blob: e1444bde02bb0278568fceafac9669e973c0fe4d [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_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800864 struct ixgbe_ring *tx_ring,
865 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800866{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000867 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000868 u32 txctrl = dca3_get_tag(tx_ring->dev, cpu);
869 u16 reg_offset;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800870
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800871 switch (hw->mac.type) {
872 case ixgbe_mac_82598EB:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000873 reg_offset = IXGBE_DCA_TXCTRL(tx_ring->reg_idx);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800874 break;
875 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800876 case ixgbe_mac_X540:
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000877 reg_offset = IXGBE_DCA_TXCTRL_82599(tx_ring->reg_idx);
878 txctrl <<= IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599;
879 break;
880 default:
881 /* for unknown hardware do not write register */
882 return;
883 }
884
885 /*
886 * We can enable relaxed ordering for reads, but not writes when
887 * DCA is enabled. This is due to a known issue in some chipsets
888 * which will cause the DCA tag to be cleared.
889 */
890 txctrl |= IXGBE_DCA_TXCTRL_DESC_RRO_EN |
891 IXGBE_DCA_TXCTRL_DATA_RRO_EN |
892 IXGBE_DCA_TXCTRL_DESC_DCA_EN;
893
894 IXGBE_WRITE_REG(hw, reg_offset, txctrl);
895}
896
897static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
898 struct ixgbe_ring *rx_ring,
899 int cpu)
900{
901 struct ixgbe_hw *hw = &adapter->hw;
902 u32 rxctrl = dca3_get_tag(rx_ring->dev, cpu);
903 u8 reg_idx = rx_ring->reg_idx;
904
905
906 switch (hw->mac.type) {
907 case ixgbe_mac_82599EB:
908 case ixgbe_mac_X540:
909 rxctrl <<= IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800910 break;
911 default:
912 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800913 }
Alexander Duyckbdda1a62012-02-08 07:50:14 +0000914
915 /*
916 * We can enable relaxed ordering for reads, but not writes when
917 * DCA is enabled. This is due to a known issue in some chipsets
918 * which will cause the DCA tag to be cleared.
919 */
920 rxctrl |= IXGBE_DCA_RXCTRL_DESC_RRO_EN |
921 IXGBE_DCA_RXCTRL_DATA_DCA_EN |
922 IXGBE_DCA_RXCTRL_DESC_DCA_EN;
923
924 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925}
926
927static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
928{
929 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000930 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932
933 if (q_vector->cpu == cpu)
934 goto out_no_update;
935
Alexander Duycka5579282012-02-08 07:50:04 +0000936 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000937 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800938
Alexander Duycka5579282012-02-08 07:50:04 +0000939 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000940 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800941
942 q_vector->cpu = cpu;
943out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800944 put_cpu();
945}
946
947static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
948{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800950 int i;
951
952 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
953 return;
954
Alexander Duycke35ec122009-05-21 13:07:12 +0000955 /* always use CB2 mode, difference is masked in the CB driver */
956 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
957
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
959 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
960 else
961 num_q_vectors = 1;
962
963 for (i = 0; i < num_q_vectors; i++) {
964 adapter->q_vector[i]->cpu = -1;
965 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800966 }
967}
968
969static int __ixgbe_notify_dca(struct device *dev, void *data)
970{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800971 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800972 unsigned long event = *(unsigned long *)data;
973
Don Skidmore2a72c312011-07-20 02:27:05 +0000974 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800975 return 0;
976
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977 switch (event) {
978 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700979 /* if we're already enabled, don't do it again */
980 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
981 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300982 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700983 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800984 ixgbe_setup_dca(adapter);
985 break;
986 }
987 /* Fall Through since DCA is disabled. */
988 case DCA_PROVIDER_REMOVE:
989 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
990 dca_remove_requester(dev);
991 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
992 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
993 }
994 break;
995 }
996
Denis V. Lunev652f0932008-03-27 14:39:17 +0300997 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800998}
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000999
Alexander Duyckbdda1a62012-02-08 07:50:14 +00001000#endif /* CONFIG_IXGBE_DCA */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001001static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
1002 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001003 struct sk_buff *skb)
1004{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001005 if (ring->netdev->features & NETIF_F_RXHASH)
1006 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001007}
1008
Auke Kok9a799d72007-09-15 14:07:45 -07001009/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001010 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1011 * @adapter: address of board private structure
1012 * @rx_desc: advanced rx descriptor
1013 *
1014 * Returns : true if it is FCoE pkt
1015 */
1016static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1017 union ixgbe_adv_rx_desc *rx_desc)
1018{
1019 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1020
1021 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1022 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1023 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1024 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1025}
1026
1027/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001028 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001029 * @ring: structure containing ring specific data
1030 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001031 * @skb: skb currently being received and modified
1032 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001033static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001034 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001035 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001036{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001037 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001038
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001039 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001040 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001041 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001042
1043 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001044 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1045 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001046 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001047 return;
1048 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001049
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001050 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001051 return;
1052
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001053 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001054 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1055
1056 /*
1057 * 82599 errata, UDP frames with a 0 checksum can be marked as
1058 * checksum errors.
1059 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001060 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1061 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001062 return;
1063
Alexander Duyck8a0da212012-01-31 02:59:49 +00001064 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001065 return;
1066 }
1067
Auke Kok9a799d72007-09-15 14:07:45 -07001068 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001069 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001070}
1071
Alexander Duyck84ea2592010-11-16 19:26:49 -08001072static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001073{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001074 rx_ring->next_to_use = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001075 /*
1076 * Force memory writes to complete before letting h/w
1077 * know there are new descriptors to fetch. (Only
1078 * applicable for weak-ordered memory model archs,
1079 * such as IA-64).
1080 */
1081 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001082 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001083}
1084
Alexander Duyckf990b792012-01-31 02:59:34 +00001085static bool ixgbe_alloc_mapped_skb(struct ixgbe_ring *rx_ring,
1086 struct ixgbe_rx_buffer *bi)
1087{
1088 struct sk_buff *skb = bi->skb;
1089 dma_addr_t dma = bi->dma;
1090
1091 if (dma)
1092 return true;
1093
1094 if (likely(!skb)) {
1095 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1096 rx_ring->rx_buf_len);
1097 bi->skb = skb;
1098 if (!skb) {
1099 rx_ring->rx_stats.alloc_rx_buff_failed++;
1100 return false;
1101 }
Alexander Duyckf990b792012-01-31 02:59:34 +00001102 }
1103
1104 dma = dma_map_single(rx_ring->dev, skb->data,
1105 rx_ring->rx_buf_len, DMA_FROM_DEVICE);
1106
1107 if (dma_mapping_error(rx_ring->dev, dma)) {
1108 rx_ring->rx_stats.alloc_rx_buff_failed++;
1109 return false;
1110 }
1111
1112 bi->dma = dma;
1113 return true;
1114}
1115
1116static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1117 struct ixgbe_rx_buffer *bi)
1118{
1119 struct page *page = bi->page;
1120 dma_addr_t page_dma = bi->page_dma;
1121 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
1122
1123 if (page_dma)
1124 return true;
1125
1126 if (!page) {
1127 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1128 bi->page = page;
1129 if (unlikely(!page)) {
1130 rx_ring->rx_stats.alloc_rx_page_failed++;
1131 return false;
1132 }
1133 }
1134
1135 page_dma = dma_map_page(rx_ring->dev, page,
1136 page_offset, PAGE_SIZE / 2,
1137 DMA_FROM_DEVICE);
1138
1139 if (dma_mapping_error(rx_ring->dev, page_dma)) {
1140 rx_ring->rx_stats.alloc_rx_page_failed++;
1141 return false;
1142 }
1143
1144 bi->page_dma = page_dma;
1145 bi->page_offset = page_offset;
1146 return true;
1147}
1148
Auke Kok9a799d72007-09-15 14:07:45 -07001149/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001150 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001151 * @rx_ring: ring to place buffers on
1152 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001153 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001154void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001155{
Auke Kok9a799d72007-09-15 14:07:45 -07001156 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001157 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001158 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001159
Alexander Duyckf990b792012-01-31 02:59:34 +00001160 /* nothing to do or no valid netdev defined */
1161 if (!cleaned_count || !rx_ring->netdev)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001162 return;
1163
Alexander Duycke4f74022012-01-31 02:59:44 +00001164 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001165 bi = &rx_ring->rx_buffer_info[i];
1166 i -= rx_ring->count;
1167
Auke Kok9a799d72007-09-15 14:07:45 -07001168 while (cleaned_count--) {
Alexander Duyckf990b792012-01-31 02:59:34 +00001169 if (!ixgbe_alloc_mapped_skb(rx_ring, bi))
1170 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001171
Alexander Duyckf990b792012-01-31 02:59:34 +00001172 /* Refresh the desc even if buffer_addrs didn't change
1173 * because each write-back erases this info. */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001174 if (ring_is_ps_enabled(rx_ring)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001175 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Alexander Duyckf990b792012-01-31 02:59:34 +00001176
1177 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1178 break;
1179
1180 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001181 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001182 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001183 }
1184
Alexander Duyckf990b792012-01-31 02:59:34 +00001185 rx_desc++;
1186 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001187 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001188 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001189 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001190 bi = rx_ring->rx_buffer_info;
1191 i -= rx_ring->count;
1192 }
1193
1194 /* clear the hdr_addr for the next_to_use descriptor */
1195 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001196 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001197
Alexander Duyckf990b792012-01-31 02:59:34 +00001198 i += rx_ring->count;
1199
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001200 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001201 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001202}
1203
Alexander Duyckc267fc12010-11-16 19:27:00 -08001204static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001205{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001206 /* HW will not DMA in data larger than the given buffer, even if it
1207 * parses the (NFS, of course) header to be larger. In that case, it
1208 * fills the header buffer and spills the rest into the page.
1209 */
1210 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1211 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1212 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1213 if (hlen > IXGBE_RX_HDR_SIZE)
1214 hlen = IXGBE_RX_HDR_SIZE;
1215 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001216}
1217
Alexander Duyckf8212f92009-04-27 22:42:37 +00001218/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001219 * ixgbe_merge_active_tail - merge active tail into lro skb
1220 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001221 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001222 * This function merges the length and data of an active tail into the
1223 * skb containing the frag_list. It resets the tail's pointer to the head,
1224 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001225 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001226static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001227{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001228 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001229
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001230 if (!head)
1231 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001232
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001233 head->len += tail->len;
1234 head->data_len += tail->len;
1235 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001236
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001237 IXGBE_CB(tail)->head = NULL;
1238
1239 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001240}
1241
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001242/**
1243 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1244 * @head: pointer to the start of the skb
1245 * @tail: pointer to active tail to add to frag_list
1246 *
1247 * This function adds an active tail to the end of the frag list. This tail
1248 * will still be receiving data so we cannot yet ad it's stats to the main
1249 * skb. That is done via ixgbe_merge_active_tail.
1250 **/
1251static inline void ixgbe_add_active_tail(struct sk_buff *head,
1252 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001253{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001254 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1255
1256 if (old_tail) {
1257 ixgbe_merge_active_tail(old_tail);
1258 old_tail->next = tail;
1259 } else {
1260 skb_shinfo(head)->frag_list = tail;
1261 }
1262
1263 IXGBE_CB(tail)->head = head;
1264 IXGBE_CB(head)->tail = tail;
1265}
1266
1267/**
1268 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1269 * @head: pointer to head of an active frag list
1270 *
1271 * This function will clear the frag_tail_tracker pointer on an active
1272 * frag_list and returns true if the pointer was actually set
1273 **/
1274static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1275{
1276 struct sk_buff *tail = IXGBE_CB(head)->tail;
1277
1278 if (!tail)
1279 return false;
1280
1281 ixgbe_merge_active_tail(tail);
1282
1283 IXGBE_CB(head)->tail = NULL;
1284
1285 return true;
1286}
1287
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001288/**
1289 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1290 * @data: pointer to the start of the headers
1291 * @max_len: total length of section to find headers in
1292 *
1293 * This function is meant to determine the length of headers that will
1294 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1295 * motivation of doing this is to only perform one pull for IPv4 TCP
1296 * packets so that we can do basic things like calculating the gso_size
1297 * based on the average data per packet.
1298 **/
1299static unsigned int ixgbe_get_headlen(unsigned char *data,
1300 unsigned int max_len)
1301{
1302 union {
1303 unsigned char *network;
1304 /* l2 headers */
1305 struct ethhdr *eth;
1306 struct vlan_hdr *vlan;
1307 /* l3 headers */
1308 struct iphdr *ipv4;
1309 } hdr;
1310 __be16 protocol;
1311 u8 nexthdr = 0; /* default to not TCP */
1312 u8 hlen;
1313
1314 /* this should never happen, but better safe than sorry */
1315 if (max_len < ETH_HLEN)
1316 return max_len;
1317
1318 /* initialize network frame pointer */
1319 hdr.network = data;
1320
1321 /* set first protocol and move network header forward */
1322 protocol = hdr.eth->h_proto;
1323 hdr.network += ETH_HLEN;
1324
1325 /* handle any vlan tag if present */
1326 if (protocol == __constant_htons(ETH_P_8021Q)) {
1327 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1328 return max_len;
1329
1330 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1331 hdr.network += VLAN_HLEN;
1332 }
1333
1334 /* handle L3 protocols */
1335 if (protocol == __constant_htons(ETH_P_IP)) {
1336 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1337 return max_len;
1338
1339 /* access ihl as a u8 to avoid unaligned access on ia64 */
1340 hlen = (hdr.network[0] & 0x0F) << 2;
1341
1342 /* verify hlen meets minimum size requirements */
1343 if (hlen < sizeof(struct iphdr))
1344 return hdr.network - data;
1345
1346 /* record next protocol */
1347 nexthdr = hdr.ipv4->protocol;
1348 hdr.network += hlen;
1349#ifdef CONFIG_FCOE
1350 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1351 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1352 return max_len;
1353 hdr.network += FCOE_HEADER_LEN;
1354#endif
1355 } else {
1356 return hdr.network - data;
1357 }
1358
1359 /* finally sort out TCP */
1360 if (nexthdr == IPPROTO_TCP) {
1361 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1362 return max_len;
1363
1364 /* access doff as a u8 to avoid unaligned access on ia64 */
1365 hlen = (hdr.network[12] & 0xF0) >> 2;
1366
1367 /* verify hlen meets minimum size requirements */
1368 if (hlen < sizeof(struct tcphdr))
1369 return hdr.network - data;
1370
1371 hdr.network += hlen;
1372 }
1373
1374 /*
1375 * If everything has gone correctly hdr.network should be the
1376 * data section of the packet and will be the end of the header.
1377 * If not then it probably represents the end of the last recognized
1378 * header.
1379 */
1380 if ((hdr.network - data) < max_len)
1381 return hdr.network - data;
1382 else
1383 return max_len;
1384}
1385
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001386static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1387 union ixgbe_adv_rx_desc *rx_desc,
1388 struct sk_buff *skb)
1389{
1390 __le32 rsc_enabled;
1391 u32 rsc_cnt;
1392
1393 if (!ring_is_rsc_enabled(rx_ring))
1394 return;
1395
1396 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1397 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1398
1399 /* If this is an RSC frame rsc_cnt should be non-zero */
1400 if (!rsc_enabled)
1401 return;
1402
1403 rsc_cnt = le32_to_cpu(rsc_enabled);
1404 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1405
1406 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001407}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001408
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001409static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1410 struct sk_buff *skb)
1411{
1412 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1413
1414 /* set gso_size to avoid messing up TCP MSS */
1415 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1416 IXGBE_CB(skb)->append_cnt);
1417}
1418
1419static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1420 struct sk_buff *skb)
1421{
1422 /* if append_cnt is 0 then frame is not RSC */
1423 if (!IXGBE_CB(skb)->append_cnt)
1424 return;
1425
1426 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1427 rx_ring->rx_stats.rsc_flush++;
1428
1429 ixgbe_set_rsc_gso_size(rx_ring, skb);
1430
1431 /* gso_size is computed using append_cnt so always clear it last */
1432 IXGBE_CB(skb)->append_cnt = 0;
1433}
1434
Alexander Duyck8a0da212012-01-31 02:59:49 +00001435/**
1436 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1437 * @rx_ring: rx descriptor ring packet is being transacted on
1438 * @rx_desc: pointer to the EOP Rx descriptor
1439 * @skb: pointer to current skb being populated
1440 *
1441 * This function checks the ring, descriptor, and packet information in
1442 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1443 * other fields within the skb.
1444 **/
1445static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1446 union ixgbe_adv_rx_desc *rx_desc,
1447 struct sk_buff *skb)
1448{
1449 ixgbe_update_rsc_stats(rx_ring, skb);
1450
1451 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1452
1453 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1454
1455 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1456 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1457 __vlan_hwaccel_put_tag(skb, vid);
1458 }
1459
1460 skb_record_rx_queue(skb, rx_ring->queue_index);
1461
1462 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1463}
1464
1465static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1466 struct sk_buff *skb)
1467{
1468 struct ixgbe_adapter *adapter = q_vector->adapter;
1469
1470 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1471 napi_gro_receive(&q_vector->napi, skb);
1472 else
1473 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001474}
1475
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001476static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001477 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001478 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001479{
Auke Kok9a799d72007-09-15 14:07:45 -07001480 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001481 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001482 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001483 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001484 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001485#ifdef IXGBE_FCOE
Alexander Duyck8a0da212012-01-31 02:59:49 +00001486 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001487 int ddp_bytes = 0;
1488#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001489 u16 i;
1490 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001491
1492 i = rx_ring->next_to_clean;
Alexander Duycke4f74022012-01-31 02:59:44 +00001493 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001494
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001495 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001496 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001497
Milton Miller3c945e52010-02-19 17:44:42 +00001498 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001499
Alexander Duyckc267fc12010-11-16 19:27:00 -08001500 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1501
Auke Kok9a799d72007-09-15 14:07:45 -07001502 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001503 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001504 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001505
David S. Miller8decf862011-09-22 03:23:13 -04001506 /* linear means we are building an skb from multiple pages */
1507 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001508 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001509 if (ring_is_ps_enabled(rx_ring)) {
1510 hlen = ixgbe_get_hlen(rx_desc);
1511 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1512 } else {
1513 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1514 }
1515
1516 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001517
1518 /*
1519 * Delay unmapping of the first packet. It carries the
1520 * header information, HW may still access the header
1521 * after writeback. Only unmap it when EOP is reached
1522 */
1523 if (!IXGBE_CB(skb)->head) {
1524 IXGBE_CB(skb)->delay_unmap = true;
1525 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1526 } else {
1527 skb = ixgbe_merge_active_tail(skb);
1528 dma_unmap_single(rx_ring->dev,
1529 rx_buffer_info->dma,
1530 rx_ring->rx_buf_len,
1531 DMA_FROM_DEVICE);
1532 }
1533 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001534 } else {
1535 /* assume packet split since header is unmapped */
1536 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001537 }
1538
1539 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001540 dma_unmap_page(rx_ring->dev,
1541 rx_buffer_info->page_dma,
1542 PAGE_SIZE / 2,
1543 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001544 rx_buffer_info->page_dma = 0;
1545 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001546 rx_buffer_info->page,
1547 rx_buffer_info->page_offset,
1548 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001549
Alexander Duyckc267fc12010-11-16 19:27:00 -08001550 if ((page_count(rx_buffer_info->page) == 1) &&
1551 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001552 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001553 else
1554 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001555
1556 skb->len += upper_len;
1557 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001558 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001559 }
1560
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001561 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1562
Auke Kok9a799d72007-09-15 14:07:45 -07001563 i++;
1564 if (i == rx_ring->count)
1565 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001566
Alexander Duycke4f74022012-01-31 02:59:44 +00001567 next_rxd = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001568 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001569 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001570
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001571 if ((!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001572 struct ixgbe_rx_buffer *next_buffer;
1573 u32 nextp;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001574
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001575 if (IXGBE_CB(skb)->append_cnt) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001576 nextp = le32_to_cpu(
1577 rx_desc->wb.upper.status_error);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001578 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1579 } else {
1580 nextp = i;
1581 }
1582
1583 next_buffer = &rx_ring->rx_buffer_info[nextp];
1584
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001585 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001586 rx_buffer_info->skb = next_buffer->skb;
1587 rx_buffer_info->dma = next_buffer->dma;
1588 next_buffer->skb = skb;
1589 next_buffer->dma = 0;
1590 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001591 struct sk_buff *next_skb = next_buffer->skb;
1592 ixgbe_add_active_tail(skb, next_skb);
1593 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001594 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001595 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001596 goto next_desc;
1597 }
1598
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001599 dma_unmap_single(rx_ring->dev,
1600 IXGBE_CB(skb)->dma,
1601 rx_ring->rx_buf_len,
1602 DMA_FROM_DEVICE);
1603 IXGBE_CB(skb)->dma = 0;
1604 IXGBE_CB(skb)->delay_unmap = false;
1605
1606 if (ixgbe_close_active_frag_list(skb) &&
1607 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001608 /* if we got here without RSC the packet is invalid */
Alexander Duyckff886df2011-06-11 01:45:13 +00001609 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001610 goto next_desc;
1611 }
1612
Auke Kok9a799d72007-09-15 14:07:45 -07001613 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001614 if (unlikely(ixgbe_test_staterr(rx_desc,
1615 IXGBE_RXDADV_ERR_FRAME_ERR_MASK))) {
Auke Kok9a799d72007-09-15 14:07:45 -07001616 dev_kfree_skb_any(skb);
1617 goto next_desc;
1618 }
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001619
1620 /* probably a little skewed due to removing CRC */
1621 total_rx_bytes += skb->len;
1622 total_rx_packets++;
1623
Alexander Duyck8a0da212012-01-31 02:59:49 +00001624 /* populate checksum, timestamp, VLAN, and protocol */
1625 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1626
Yi Zou332d4a72009-05-13 13:11:53 +00001627#ifdef IXGBE_FCOE
1628 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001629 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001630 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001631 if (!ddp_bytes) {
1632 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001633 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001634 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001635 }
Yi Zou332d4a72009-05-13 13:11:53 +00001636#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001637 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001638
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001639 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001640next_desc:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001641 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001642 break;
1643
Auke Kok9a799d72007-09-15 14:07:45 -07001644 /* return some buffers to hardware, one at a time is too slow */
1645 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001646 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001647 cleaned_count = 0;
1648 }
1649
1650 /* use prefetched values */
1651 rx_desc = next_rxd;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001652 }
1653
Auke Kok9a799d72007-09-15 14:07:45 -07001654 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001655 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001656
1657 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001658 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001659
Yi Zou3d8fd382009-06-08 14:38:44 +00001660#ifdef IXGBE_FCOE
1661 /* include DDPed FCoE data */
1662 if (ddp_bytes > 0) {
1663 unsigned int mss;
1664
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001665 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001666 sizeof(struct fc_frame_header) -
1667 sizeof(struct fcoe_crc_eof);
1668 if (mss > 512)
1669 mss &= ~511;
1670 total_rx_bytes += ddp_bytes;
1671 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1672 }
1673#endif /* IXGBE_FCOE */
1674
Alexander Duyckc267fc12010-11-16 19:27:00 -08001675 u64_stats_update_begin(&rx_ring->syncp);
1676 rx_ring->stats.packets += total_rx_packets;
1677 rx_ring->stats.bytes += total_rx_bytes;
1678 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001679 q_vector->rx.total_packets += total_rx_packets;
1680 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001681
1682 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001683}
1684
Auke Kok9a799d72007-09-15 14:07:45 -07001685/**
1686 * ixgbe_configure_msix - Configure MSI-X hardware
1687 * @adapter: board private structure
1688 *
1689 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1690 * interrupts.
1691 **/
1692static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1693{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001694 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001695 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001696 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001697
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001698 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1699
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001700 /* Populate MSIX to EITR Select */
1701 if (adapter->num_vfs > 32) {
1702 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1703 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1704 }
1705
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001706 /*
1707 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001708 * corresponding register.
1709 */
1710 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001711 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001712 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001713
Alexander Duycka5579282012-02-08 07:50:04 +00001714 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001715 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001716
Alexander Duycka5579282012-02-08 07:50:04 +00001717 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001718 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001719
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001720 if (q_vector->tx.ring && !q_vector->rx.ring) {
1721 /* tx only vector */
1722 if (adapter->tx_itr_setting == 1)
1723 q_vector->itr = IXGBE_10K_ITR;
1724 else
1725 q_vector->itr = adapter->tx_itr_setting;
1726 } else {
1727 /* rx or rx/tx vector */
1728 if (adapter->rx_itr_setting == 1)
1729 q_vector->itr = IXGBE_20K_ITR;
1730 else
1731 q_vector->itr = adapter->rx_itr_setting;
1732 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001733
Alexander Duyckfe49f042009-06-04 16:00:09 +00001734 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001735 }
1736
Alexander Duyckbd508172010-11-16 19:27:03 -08001737 switch (adapter->hw.mac.type) {
1738 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001739 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001740 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001741 break;
1742 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001743 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001744 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001745 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001746 default:
1747 break;
1748 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001749 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001750
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001751 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001752 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001753 mask &= ~(IXGBE_EIMS_OTHER |
1754 IXGBE_EIMS_MAILBOX |
1755 IXGBE_EIMS_LSC);
1756
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001757 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001758}
1759
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001760enum latency_range {
1761 lowest_latency = 0,
1762 low_latency = 1,
1763 bulk_latency = 2,
1764 latency_invalid = 255
1765};
1766
1767/**
1768 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001769 * @q_vector: structure containing interrupt and ring information
1770 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771 *
1772 * Stores a new ITR value based on packets and byte
1773 * counts during the last interrupt. The advantage of per interrupt
1774 * computation is faster updates and more accurate ITR for the current
1775 * traffic pattern. Constants in this function were computed
1776 * based on theoretical maximum wire speed and thresholds were set based
1777 * on testing data as well as attempting to minimize response time
1778 * while increasing bulk throughput.
1779 * this functionality is controlled by the InterruptThrottleRate module
1780 * parameter (see ixgbe_param.c)
1781 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001782static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1783 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001784{
Alexander Duyckbd198052011-06-11 01:45:08 +00001785 int bytes = ring_container->total_bytes;
1786 int packets = ring_container->total_packets;
1787 u32 timepassed_us;
Alexander Duyck621bd702012-02-08 07:50:20 +00001788 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001789 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001790
1791 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001792 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001793
1794 /* simple throttlerate management
Alexander Duyck621bd702012-02-08 07:50:20 +00001795 * 0-10MB/s lowest (100000 ints/s)
1796 * 10-20MB/s low (20000 ints/s)
1797 * 20-1249MB/s bulk (8000 ints/s)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001798 */
1799 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001800 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001801 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1802
1803 switch (itr_setting) {
1804 case lowest_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001805 if (bytes_perint > 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001806 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001807 break;
1808 case low_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001809 if (bytes_perint > 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001810 itr_setting = bulk_latency;
Alexander Duyck621bd702012-02-08 07:50:20 +00001811 else if (bytes_perint <= 10)
Alexander Duyckbd198052011-06-11 01:45:08 +00001812 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001813 break;
1814 case bulk_latency:
Alexander Duyck621bd702012-02-08 07:50:20 +00001815 if (bytes_perint <= 20)
Alexander Duyckbd198052011-06-11 01:45:08 +00001816 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001817 break;
1818 }
1819
Alexander Duyckbd198052011-06-11 01:45:08 +00001820 /* clear work counters since we have the values we need */
1821 ring_container->total_bytes = 0;
1822 ring_container->total_packets = 0;
1823
1824 /* write updated itr to ring container */
1825 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001826}
1827
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001828/**
1829 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001830 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001831 *
1832 * This function is made to be called by ethtool and by the driver
1833 * when it needs to update EITR registers at runtime. Hardware
1834 * specific quirks/differences are taken care of here.
1835 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001836void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001837{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001838 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001839 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001840 int v_idx = q_vector->v_idx;
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001841 u32 itr_reg = q_vector->itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001842
Alexander Duyckbd508172010-11-16 19:27:03 -08001843 switch (adapter->hw.mac.type) {
1844 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001845 /* must write high and low 16 bits to reset counter */
1846 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001847 break;
1848 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001849 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001850 /*
1851 * set the WDIS bit to not clear the timer bits and cause an
1852 * immediate assertion of the interrupt
1853 */
1854 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001855 break;
1856 default:
1857 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001858 }
1859 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1860}
1861
Alexander Duyckbd198052011-06-11 01:45:08 +00001862static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001863{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001864 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001865 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001866
Alexander Duyckbd198052011-06-11 01:45:08 +00001867 ixgbe_update_itr(q_vector, &q_vector->tx);
1868 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001869
Alexander Duyck08c88332011-06-11 01:45:03 +00001870 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001871
1872 switch (current_itr) {
1873 /* counts and packets in update_itr are dependent on these numbers */
1874 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001875 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001876 break;
1877 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001878 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001879 break;
1880 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001881 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001882 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001883 default:
1884 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001885 }
1886
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001887 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001888 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001889 new_itr = (10 * new_itr * q_vector->itr) /
1890 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001891
Alexander Duyckbd198052011-06-11 01:45:08 +00001892 /* save the algorithm value here */
Alexander Duyck5d967eb2012-02-08 07:49:43 +00001893 q_vector->itr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001894
1895 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001896 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001897}
1898
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001899/**
Alexander Duyckde88eee2012-02-08 07:49:59 +00001900 * ixgbe_check_overtemp_subtask - check for over temperature
Alexander Duyckf0f97782011-04-22 04:08:09 +00001901 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001902 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001903static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001904{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001905 struct ixgbe_hw *hw = &adapter->hw;
1906 u32 eicr = adapter->interrupt_event;
1907
Alexander Duyckf0f97782011-04-22 04:08:09 +00001908 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001909 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001910
Alexander Duyckf0f97782011-04-22 04:08:09 +00001911 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1912 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1913 return;
1914
1915 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1916
Joe Perches7ca647b2010-09-07 21:35:40 +00001917 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001918 case IXGBE_DEV_ID_82599_T3_LOM:
1919 /*
1920 * Since the warning interrupt is for both ports
1921 * we don't have to check if:
1922 * - This interrupt wasn't for our port.
1923 * - We may have missed the interrupt so always have to
1924 * check if we got a LSC
1925 */
1926 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1927 !(eicr & IXGBE_EICR_LSC))
1928 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001929
Alexander Duyckf0f97782011-04-22 04:08:09 +00001930 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1931 u32 autoneg;
1932 bool link_up = false;
1933
Joe Perches7ca647b2010-09-07 21:35:40 +00001934 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1935
Alexander Duyckf0f97782011-04-22 04:08:09 +00001936 if (link_up)
1937 return;
1938 }
1939
1940 /* Check if this is not due to overtemp */
1941 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1942 return;
1943
1944 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001945 default:
1946 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1947 return;
1948 break;
1949 }
1950 e_crit(drv,
1951 "Network adapter has been stopped because it has over heated. "
1952 "Restart the computer. If the problem persists, "
1953 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001954
1955 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001956}
1957
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001958static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1959{
1960 struct ixgbe_hw *hw = &adapter->hw;
1961
1962 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1963 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001964 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001965 /* write to clear the interrupt */
1966 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1967 }
1968}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001969
Jacob Keller4f51bf72011-08-20 04:49:45 +00001970static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1971{
1972 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1973 return;
1974
1975 switch (adapter->hw.mac.type) {
1976 case ixgbe_mac_82599EB:
1977 /*
1978 * Need to check link state so complete overtemp check
1979 * on service task
1980 */
1981 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1982 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1983 adapter->interrupt_event = eicr;
1984 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1985 ixgbe_service_event_schedule(adapter);
1986 return;
1987 }
1988 return;
1989 case ixgbe_mac_X540:
1990 if (!(eicr & IXGBE_EICR_TS))
1991 return;
1992 break;
1993 default:
1994 return;
1995 }
1996
1997 e_crit(drv,
1998 "Network adapter has been stopped because it has over heated. "
1999 "Restart the computer. If the problem persists, "
2000 "power off the system and replace the adapter\n");
2001}
2002
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002003static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
2004{
2005 struct ixgbe_hw *hw = &adapter->hw;
2006
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002007 if (eicr & IXGBE_EICR_GPI_SDP2) {
2008 /* Clear the interrupt */
2009 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002010 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2011 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2012 ixgbe_service_event_schedule(adapter);
2013 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002014 }
2015
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002016 if (eicr & IXGBE_EICR_GPI_SDP1) {
2017 /* Clear the interrupt */
2018 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002019 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2020 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2021 ixgbe_service_event_schedule(adapter);
2022 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002023 }
2024}
2025
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002026static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2027{
2028 struct ixgbe_hw *hw = &adapter->hw;
2029
2030 adapter->lsc_int++;
2031 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2032 adapter->link_check_timeout = jiffies;
2033 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2034 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002035 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002036 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002037 }
2038}
2039
Alexander Duyckfe49f042009-06-04 16:00:09 +00002040static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2041 u64 qmask)
2042{
2043 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002044 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002045
Alexander Duyckbd508172010-11-16 19:27:03 -08002046 switch (hw->mac.type) {
2047 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002048 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002049 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2050 break;
2051 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002052 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002053 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002054 if (mask)
2055 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002056 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002057 if (mask)
2058 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2059 break;
2060 default:
2061 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002062 }
2063 /* skip the flush */
2064}
2065
2066static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002067 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002068{
2069 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002070 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002071
Alexander Duyckbd508172010-11-16 19:27:03 -08002072 switch (hw->mac.type) {
2073 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002074 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002075 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2076 break;
2077 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002078 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002079 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002080 if (mask)
2081 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002082 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002083 if (mask)
2084 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2085 break;
2086 default:
2087 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002088 }
2089 /* skip the flush */
2090}
2091
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002092/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002093 * ixgbe_irq_enable - Enable default interrupt generation settings
2094 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002095 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002096static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2097 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002098{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002099 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002100
Alexander Duyck2c4af692011-07-15 07:29:55 +00002101 /* don't reenable LSC while waiting for link */
2102 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2103 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002104
Alexander Duyck2c4af692011-07-15 07:29:55 +00002105 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002106 switch (adapter->hw.mac.type) {
2107 case ixgbe_mac_82599EB:
2108 mask |= IXGBE_EIMS_GPI_SDP0;
2109 break;
2110 case ixgbe_mac_X540:
2111 mask |= IXGBE_EIMS_TS;
2112 break;
2113 default:
2114 break;
2115 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002116 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2117 mask |= IXGBE_EIMS_GPI_SDP1;
2118 switch (adapter->hw.mac.type) {
2119 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002120 mask |= IXGBE_EIMS_GPI_SDP1;
2121 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002122 case ixgbe_mac_X540:
2123 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002124 mask |= IXGBE_EIMS_MAILBOX;
2125 break;
2126 default:
2127 break;
2128 }
2129 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2130 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2131 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002132
Alexander Duyck2c4af692011-07-15 07:29:55 +00002133 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2134 if (queues)
2135 ixgbe_irq_enable_queues(adapter, ~0);
2136 if (flush)
2137 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002138}
2139
Alexander Duyck2c4af692011-07-15 07:29:55 +00002140static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002141{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002142 struct ixgbe_adapter *adapter = data;
2143 struct ixgbe_hw *hw = &adapter->hw;
2144 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002145
Alexander Duyck2c4af692011-07-15 07:29:55 +00002146 /*
2147 * Workaround for Silicon errata. Use clear-by-write instead
2148 * of clear-by-read. Reading with EICS will return the
2149 * interrupt causes without clearing, which later be done
2150 * with the write to EICR.
2151 */
2152 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2153 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002154
Alexander Duyck2c4af692011-07-15 07:29:55 +00002155 if (eicr & IXGBE_EICR_LSC)
2156 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002157
Alexander Duyck2c4af692011-07-15 07:29:55 +00002158 if (eicr & IXGBE_EICR_MAILBOX)
2159 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002160
Alexander Duyck2c4af692011-07-15 07:29:55 +00002161 switch (hw->mac.type) {
2162 case ixgbe_mac_82599EB:
2163 case ixgbe_mac_X540:
2164 if (eicr & IXGBE_EICR_ECC)
2165 e_info(link, "Received unrecoverable ECC Err, please "
2166 "reboot\n");
2167 /* Handle Flow Director Full threshold interrupt */
2168 if (eicr & IXGBE_EICR_FLOW_DIR) {
2169 int reinit_count = 0;
2170 int i;
2171 for (i = 0; i < adapter->num_tx_queues; i++) {
2172 struct ixgbe_ring *ring = adapter->tx_ring[i];
2173 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2174 &ring->state))
2175 reinit_count++;
2176 }
2177 if (reinit_count) {
2178 /* no more flow director interrupts until after init */
2179 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2180 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2181 ixgbe_service_event_schedule(adapter);
2182 }
2183 }
2184 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002185 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002186 break;
2187 default:
2188 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002189 }
2190
Alexander Duyck2c4af692011-07-15 07:29:55 +00002191 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002192
Alexander Duyck2c4af692011-07-15 07:29:55 +00002193 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002194 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002195 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002196
Alexander Duyck2c4af692011-07-15 07:29:55 +00002197 return IRQ_HANDLED;
2198}
2199
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002200static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002201{
2202 struct ixgbe_q_vector *q_vector = data;
2203
Auke Kok9a799d72007-09-15 14:07:45 -07002204 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002205
2206 if (q_vector->rx.ring || q_vector->tx.ring)
2207 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002208
2209 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002210}
2211
Auke Kok9a799d72007-09-15 14:07:45 -07002212/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002213 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2214 * @adapter: board private structure
2215 *
2216 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2217 * interrupts from the kernel.
2218 **/
2219static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2220{
2221 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002222 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2223 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002224 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002225
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002227 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002228 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002229
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002230 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002231 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002232 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002233 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002234 } else if (q_vector->rx.ring) {
2235 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2236 "%s-%s-%d", netdev->name, "rx", ri++);
2237 } else if (q_vector->tx.ring) {
2238 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2239 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002240 } else {
2241 /* skip this unused q_vector */
2242 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002243 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002244 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2245 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002247 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002248 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002249 goto free_queue_irqs;
2250 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002251 /* If Flow Director is enabled, set interrupt affinity */
2252 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2253 /* assign the mask for this irq */
2254 irq_set_affinity_hint(entry->vector,
Alexander Duyckde88eee2012-02-08 07:49:59 +00002255 &q_vector->affinity_mask);
Alexander Duyck207867f2011-07-15 03:05:37 +00002256 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257 }
2258
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002260 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261 if (err) {
Alexander Duyckde88eee2012-02-08 07:49:59 +00002262 e_err(probe, "request_irq for msix_other failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 goto free_queue_irqs;
2264 }
2265
2266 return 0;
2267
2268free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002269 while (vector) {
2270 vector--;
2271 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2272 NULL);
2273 free_irq(adapter->msix_entries[vector].vector,
2274 adapter->q_vector[vector]);
2275 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002276 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2277 pci_disable_msix(adapter->pdev);
2278 kfree(adapter->msix_entries);
2279 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002280 return err;
2281}
2282
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002283/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002285 * @irq: interrupt number
2286 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002287 **/
2288static irqreturn_t ixgbe_intr(int irq, void *data)
2289{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002290 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002291 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002292 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002293 u32 eicr;
2294
Don Skidmore54037502009-02-21 15:42:56 -08002295 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002296 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002297 * before the read of EICR.
2298 */
2299 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2300
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002302 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002303 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002304 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002305 /*
2306 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002307 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002308 * have disabled interrupts due to EIAM
2309 * finish the workaround of silicon errata on 82598. Unmask
2310 * the interrupt that we masked before the EICR read.
2311 */
2312 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2313 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002314 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002315 }
Auke Kok9a799d72007-09-15 14:07:45 -07002316
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002317 if (eicr & IXGBE_EICR_LSC)
2318 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002319
Alexander Duyckbd508172010-11-16 19:27:03 -08002320 switch (hw->mac.type) {
2321 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002322 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002323 /* Fall through */
2324 case ixgbe_mac_X540:
2325 if (eicr & IXGBE_EICR_ECC)
2326 e_info(link, "Received unrecoverable ECC err, please "
2327 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002328 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002329 break;
2330 default:
2331 break;
2332 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002333
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002334 ixgbe_check_fan_failure(adapter, eicr);
2335
Alexander Duyckb9f6ed22012-02-08 07:49:54 +00002336 /* would disable interrupts here but EIAM disabled it */
2337 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002338
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002339 /*
2340 * re-enable link(maybe) and non-queue interrupts, no flush.
2341 * ixgbe_poll will re-enable the queue interrupts
2342 */
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002343 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2344 ixgbe_irq_enable(adapter, false, false);
2345
Auke Kok9a799d72007-09-15 14:07:45 -07002346 return IRQ_HANDLED;
2347}
2348
2349/**
2350 * ixgbe_request_irq - initialize interrupts
2351 * @adapter: board private structure
2352 *
2353 * Attempts to configure interrupts using the best available
2354 * capabilities of the hardware and kernel.
2355 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002357{
2358 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002359 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002360
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002361 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002362 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002363 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002364 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002365 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002366 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002367 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002368 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002369
Alexander Duyckde88eee2012-02-08 07:49:59 +00002370 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002371 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002372
Auke Kok9a799d72007-09-15 14:07:45 -07002373 return err;
2374}
2375
2376static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2377{
Auke Kok9a799d72007-09-15 14:07:45 -07002378 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002379 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002380
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002381 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002382 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002383 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002384 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002385
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002386 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002387 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002388 if (!adapter->q_vector[i]->rx.ring &&
2389 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002390 continue;
2391
Alexander Duyck207867f2011-07-15 03:05:37 +00002392 /* clear the affinity_mask in the IRQ descriptor */
2393 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2394 NULL);
2395
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002396 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002397 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002398 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002399 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002400 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002401 }
2402}
2403
2404/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002405 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2406 * @adapter: board private structure
2407 **/
2408static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2409{
Alexander Duyckbd508172010-11-16 19:27:03 -08002410 switch (adapter->hw.mac.type) {
2411 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002412 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002413 break;
2414 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002415 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002416 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2417 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002418 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002419 break;
2420 default:
2421 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002422 }
2423 IXGBE_WRITE_FLUSH(&adapter->hw);
2424 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2425 int i;
2426 for (i = 0; i < adapter->num_msix_vectors; i++)
2427 synchronize_irq(adapter->msix_entries[i].vector);
2428 } else {
2429 synchronize_irq(adapter->pdev->irq);
2430 }
2431}
2432
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002433/**
Auke Kok9a799d72007-09-15 14:07:45 -07002434 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2435 *
2436 **/
2437static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2438{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002439 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002440
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002441 /* rx/tx vector */
2442 if (adapter->rx_itr_setting == 1)
2443 q_vector->itr = IXGBE_20K_ITR;
2444 else
2445 q_vector->itr = adapter->rx_itr_setting;
2446
2447 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002448
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002449 ixgbe_set_ivar(adapter, 0, 0, 0);
2450 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451
Emil Tantilov396e7992010-07-01 20:05:12 +00002452 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002453}
2454
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002455/**
2456 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2457 * @adapter: board private structure
2458 * @ring: structure containing ring specific data
2459 *
2460 * Configure the Tx descriptor ring after a reset.
2461 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002462void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2463 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002464{
2465 struct ixgbe_hw *hw = &adapter->hw;
2466 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002467 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002468 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002469 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002470
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002471 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002472 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002473 IXGBE_WRITE_FLUSH(hw);
2474
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002475 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002476 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002477 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2478 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2479 ring->count * sizeof(union ixgbe_adv_tx_desc));
2480 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2481 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002482 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002483
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002484 /*
2485 * set WTHRESH to encourage burst writeback, it should not be set
2486 * higher than 1 when ITR is 0 as it could cause false TX hangs
2487 *
2488 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2489 * to or less than the number of on chip descriptors, which is
2490 * currently 40.
2491 */
Alexander Duycke954b372012-02-08 07:49:38 +00002492 if (!ring->q_vector || (ring->q_vector->itr < 8))
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002493 txdctl |= (1 << 16); /* WTHRESH = 1 */
2494 else
2495 txdctl |= (8 << 16); /* WTHRESH = 8 */
2496
Alexander Duycke954b372012-02-08 07:49:38 +00002497 /*
2498 * Setting PTHRESH to 32 both improves performance
2499 * and avoids a TX hang with DFP enabled
2500 */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002501 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2502 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002503
2504 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002505 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2506 adapter->atr_sample_rate) {
2507 ring->atr_sample_rate = adapter->atr_sample_rate;
2508 ring->atr_count = 0;
2509 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2510 } else {
2511 ring->atr_sample_rate = 0;
2512 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002513
John Fastabendc84d3242010-11-16 19:27:12 -08002514 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2515
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002516 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002517 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2518
Alexander Duyckb2d96e02012-02-07 08:14:33 +00002519 netdev_tx_reset_queue(txring_txq(ring));
2520
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002521 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2522 if (hw->mac.type == ixgbe_mac_82598EB &&
2523 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2524 return;
2525
2526 /* poll to verify queue is enabled */
2527 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002528 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002529 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2530 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2531 if (!wait_loop)
2532 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002533}
2534
Alexander Duyck120ff942010-08-19 13:34:50 +00002535static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2536{
2537 struct ixgbe_hw *hw = &adapter->hw;
2538 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002539 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002540 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002541
2542 if (hw->mac.type == ixgbe_mac_82598EB)
2543 return;
2544
2545 /* disable the arbiter while setting MTQC */
2546 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2547 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2548 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2549
2550 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002551 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002552 case (IXGBE_FLAG_SRIOV_ENABLED):
2553 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2554 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2555 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002556 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002557 if (!tcs)
2558 reg = IXGBE_MTQC_64Q_1PB;
2559 else if (tcs <= 4)
2560 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2561 else
2562 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2563
2564 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2565
2566 /* Enable Security TX Buffer IFG for multiple pb */
2567 if (tcs) {
2568 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2569 reg |= IXGBE_SECTX_DCB;
2570 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2571 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002572 break;
2573 }
2574
2575 /* re-enable the arbiter */
2576 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2577 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2578}
2579
Auke Kok9a799d72007-09-15 14:07:45 -07002580/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002581 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002582 * @adapter: board private structure
2583 *
2584 * Configure the Tx unit of the MAC after a reset.
2585 **/
2586static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2587{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002588 struct ixgbe_hw *hw = &adapter->hw;
2589 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002590 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002591
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002592 ixgbe_setup_mtqc(adapter);
2593
2594 if (hw->mac.type != ixgbe_mac_82598EB) {
2595 /* DMATXCTL.EN must be before Tx queues are enabled */
2596 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2597 dmatxctl |= IXGBE_DMATXCTL_TE;
2598 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2599 }
2600
Auke Kok9a799d72007-09-15 14:07:45 -07002601 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002602 for (i = 0; i < adapter->num_tx_queues; i++)
2603 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002604}
2605
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002606#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002607
Yi Zoua6616b42009-08-06 13:05:23 +00002608static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002609 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002610{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002611 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002612 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002613
Alexander Duyckbd508172010-11-16 19:27:03 -08002614 switch (adapter->hw.mac.type) {
2615 case ixgbe_mac_82598EB: {
2616 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2617 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002618 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002619 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002620 break;
2621 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002622 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002623 default:
2624 break;
2625 }
2626
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002627 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002628
2629 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2630 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002631 if (adapter->num_vfs)
2632 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002633
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002634 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2635 IXGBE_SRRCTL_BSIZEHDR_MASK;
2636
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002637 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002638#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2639 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2640#else
2641 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2642#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002643 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002644 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002645 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2646 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002647 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002648 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002649
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002650 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002651}
2652
Alexander Duyck05abb122010-08-19 13:35:41 +00002653static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002654{
Alexander Duyck05abb122010-08-19 13:35:41 +00002655 struct ixgbe_hw *hw = &adapter->hw;
2656 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002657 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2658 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002659 u32 mrqc = 0, reta = 0;
2660 u32 rxcsum;
2661 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002662 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002663 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2664
2665 if (tcs)
2666 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002667
Alexander Duyck05abb122010-08-19 13:35:41 +00002668 /* Fill out hash function seeds */
2669 for (i = 0; i < 10; i++)
2670 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002671
Alexander Duyck05abb122010-08-19 13:35:41 +00002672 /* Fill out redirection table */
2673 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002674 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002675 j = 0;
2676 /* reta = 4-byte sliding window of
2677 * 0x00..(indices-1)(indices-1)00..etc. */
2678 reta = (reta << 8) | (j * 0x11);
2679 if ((i & 3) == 3)
2680 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2681 }
2682
2683 /* Disable indicating checksum in descriptor, enables RSS hash */
2684 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2685 rxcsum |= IXGBE_RXCSUM_PCSD;
2686 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2687
John Fastabend8b1c0b22011-05-03 02:26:48 +00002688 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2689 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002690 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002691 } else {
2692 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2693 | IXGBE_FLAG_SRIOV_ENABLED);
2694
2695 switch (mask) {
2696 case (IXGBE_FLAG_RSS_ENABLED):
2697 if (!tcs)
2698 mrqc = IXGBE_MRQC_RSSEN;
2699 else if (tcs <= 4)
2700 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2701 else
2702 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2703 break;
2704 case (IXGBE_FLAG_SRIOV_ENABLED):
2705 mrqc = IXGBE_MRQC_VMDQEN;
2706 break;
2707 default:
2708 break;
2709 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002710 }
2711
Alexander Duyck05abb122010-08-19 13:35:41 +00002712 /* Perform hash on these packet types */
2713 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2714 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2715 | IXGBE_MRQC_RSS_FIELD_IPV6
2716 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2717
2718 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002719}
2720
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002721/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002722 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2723 * @adapter: address of board private structure
2724 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002725 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002726static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002727 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002728{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002729 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002730 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002731 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002732 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002733
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002734 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002735 return;
2736
2737 rx_buf_len = ring->rx_buf_len;
2738 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002739 rscctrl |= IXGBE_RSCCTL_RSCEN;
2740 /*
2741 * we must limit the number of descriptors so that the
2742 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002743 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002744 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002745 if (ring_is_ps_enabled(ring)) {
Alexander Duyck642c6802011-11-10 09:09:17 +00002746#if (PAGE_SIZE < 8192)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002747 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002748#elif (PAGE_SIZE < 16384)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002749 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duyck642c6802011-11-10 09:09:17 +00002750#elif (PAGE_SIZE < 32768)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002751 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2752#else
2753 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2754#endif
2755 } else {
Alexander Duyck642c6802011-11-10 09:09:17 +00002756 if (rx_buf_len <= IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002757 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002758 else if (rx_buf_len <= IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002759 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2760 else
2761 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2762 }
Alexander Duyck73670962010-08-19 13:38:34 +00002763 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002764}
2765
Alexander Duyck9e10e042010-08-19 13:40:06 +00002766/**
2767 * ixgbe_set_uta - Set unicast filter table address
2768 * @adapter: board private structure
2769 *
2770 * The unicast table address is a register array of 32-bit registers.
2771 * The table is meant to be used in a way similar to how the MTA is used
2772 * however due to certain limitations in the hardware it is necessary to
2773 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2774 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2775 **/
2776static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2777{
2778 struct ixgbe_hw *hw = &adapter->hw;
2779 int i;
2780
2781 /* The UTA table only exists on 82599 hardware and newer */
2782 if (hw->mac.type < ixgbe_mac_82599EB)
2783 return;
2784
2785 /* we only need to do this if VMDq is enabled */
2786 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2787 return;
2788
2789 for (i = 0; i < 128; i++)
2790 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2791}
2792
2793#define IXGBE_MAX_RX_DESC_POLL 10
2794static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2795 struct ixgbe_ring *ring)
2796{
2797 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002798 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2799 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002800 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002801
2802 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2803 if (hw->mac.type == ixgbe_mac_82598EB &&
2804 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2805 return;
2806
2807 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002808 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002809 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2810 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2811
2812 if (!wait_loop) {
2813 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2814 "the polling period\n", reg_idx);
2815 }
2816}
2817
Yi Zou2d39d572011-01-06 14:29:56 +00002818void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2819 struct ixgbe_ring *ring)
2820{
2821 struct ixgbe_hw *hw = &adapter->hw;
2822 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2823 u32 rxdctl;
2824 u8 reg_idx = ring->reg_idx;
2825
2826 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2827 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2828
2829 /* write value back with RXDCTL.ENABLE bit cleared */
2830 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2831
2832 if (hw->mac.type == ixgbe_mac_82598EB &&
2833 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2834 return;
2835
2836 /* the hardware may take up to 100us to really disable the rx queue */
2837 do {
2838 udelay(10);
2839 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2840 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2841
2842 if (!wait_loop) {
2843 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2844 "the polling period\n", reg_idx);
2845 }
2846}
2847
Alexander Duyck84418e32010-08-19 13:40:54 +00002848void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2849 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002850{
2851 struct ixgbe_hw *hw = &adapter->hw;
2852 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002853 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002854 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002855
Alexander Duyck9e10e042010-08-19 13:40:06 +00002856 /* disable queue to avoid issues while updating state */
2857 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002858 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002859
Alexander Duyckacd37172010-08-19 13:36:05 +00002860 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2861 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2862 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2863 ring->count * sizeof(union ixgbe_adv_rx_desc));
2864 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2865 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002866 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002867
2868 ixgbe_configure_srrctl(adapter, ring);
2869 ixgbe_configure_rscctl(adapter, ring);
2870
Greg Rosee9f98072011-01-26 01:06:07 +00002871 /* If operating in IOV mode set RLPML for X540 */
2872 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2873 hw->mac.type == ixgbe_mac_X540) {
2874 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2875 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2876 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2877 }
2878
Alexander Duyck9e10e042010-08-19 13:40:06 +00002879 if (hw->mac.type == ixgbe_mac_82598EB) {
2880 /*
2881 * enable cache line friendly hardware writes:
2882 * PTHRESH=32 descriptors (half the internal cache),
2883 * this also removes ugly rx_no_buffer_count increment
2884 * HTHRESH=4 descriptors (to minimize latency on fetch)
2885 * WTHRESH=8 burst writeback up to two cache lines
2886 */
2887 rxdctl &= ~0x3FFFFF;
2888 rxdctl |= 0x080420;
2889 }
2890
2891 /* enable receive descriptor ring */
2892 rxdctl |= IXGBE_RXDCTL_ENABLE;
2893 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2894
2895 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002896 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002897}
2898
Alexander Duyck48654522010-08-19 13:36:27 +00002899static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2900{
2901 struct ixgbe_hw *hw = &adapter->hw;
2902 int p;
2903
2904 /* PSRTYPE must be initialized in non 82598 adapters */
2905 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002906 IXGBE_PSRTYPE_UDPHDR |
2907 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002908 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002909 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002910
2911 if (hw->mac.type == ixgbe_mac_82598EB)
2912 return;
2913
2914 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2915 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2916
2917 for (p = 0; p < adapter->num_rx_pools; p++)
2918 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2919 psrtype);
2920}
2921
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002922static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2923{
2924 struct ixgbe_hw *hw = &adapter->hw;
2925 u32 gcr_ext;
2926 u32 vt_reg_bits;
2927 u32 reg_offset, vf_shift;
2928 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002929 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002930
2931 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2932 return;
2933
2934 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2935 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
2936 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
2937 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
2938
2939 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00002940 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002941
2942 /* Enable only the PF's pool for Tx/Rx */
2943 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
2944 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
2945 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
2946 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
2947 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
2948
2949 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
2950 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
2951
2952 /*
2953 * Set up VF register offsets for selected VT Mode,
2954 * i.e. 32 or 64 VFs for SR-IOV
2955 */
2956 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
2957 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
2958 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
2959 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
2960
2961 /* enable Tx loopback for VF/PF communication */
2962 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00002963 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00002964 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00002965 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00002966 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00002967 /* For VFs that have spoof checking turned off */
2968 for (i = 0; i < adapter->num_vfs; i++) {
2969 if (!adapter->vfinfo[i].spoofchk_enabled)
2970 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
2971 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002972}
2973
Alexander Duyck477de6e2010-08-19 13:38:11 +00002974static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002975{
Auke Kok9a799d72007-09-15 14:07:45 -07002976 struct ixgbe_hw *hw = &adapter->hw;
2977 struct net_device *netdev = adapter->netdev;
2978 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07002979 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00002980 struct ixgbe_ring *rx_ring;
2981 int i;
2982 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00002983
Auke Kok9a799d72007-09-15 14:07:45 -07002984 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00002985 /* On by default */
2986 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
2987
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002988 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00002989 if (adapter->num_vfs)
2990 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
2991
2992 /* Disable packet split due to 82599 erratum #45 */
2993 if (hw->mac.type == ixgbe_mac_82599EB)
2994 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07002995
Alexander Duyck477de6e2010-08-19 13:38:11 +00002996#ifdef IXGBE_FCOE
2997 /* adjust max frame to be able to do baby jumbo for FCoE */
2998 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
2999 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3000 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3001
3002#endif /* IXGBE_FCOE */
3003 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3004 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3005 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3006 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3007
3008 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003009 }
3010
Alexander Duyck919e78a2011-08-26 09:52:38 +00003011 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3012 max_frame += VLAN_HLEN;
3013
3014 /* Set the RX buffer length according to the mode */
3015 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3016 rx_buf_len = IXGBE_RX_HDR_SIZE;
3017 } else {
3018 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3019 (netdev->mtu <= ETH_DATA_LEN))
3020 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3021 /*
3022 * Make best use of allocation by using all but 1K of a
3023 * power of 2 allocation that will be used for skb->head.
3024 */
3025 else if (max_frame <= IXGBE_RXBUFFER_3K)
3026 rx_buf_len = IXGBE_RXBUFFER_3K;
3027 else if (max_frame <= IXGBE_RXBUFFER_7K)
3028 rx_buf_len = IXGBE_RXBUFFER_7K;
3029 else if (max_frame <= IXGBE_RXBUFFER_15K)
3030 rx_buf_len = IXGBE_RXBUFFER_15K;
3031 else
3032 rx_buf_len = IXGBE_MAX_RXBUFFER;
3033 }
3034
Auke Kok9a799d72007-09-15 14:07:45 -07003035 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003036 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3037 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003038 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3039
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003040 /*
3041 * Setup the HW Rx Head and Tail Descriptor Pointers and
3042 * the Base and Length of the Rx Descriptor Ring
3043 */
Auke Kok9a799d72007-09-15 14:07:45 -07003044 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003045 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003046 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003047
Yi Zou6e455b892009-08-06 13:05:44 +00003048 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003049 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003050 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003051 clear_ring_ps_enabled(rx_ring);
3052
3053 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3054 set_ring_rsc_enabled(rx_ring);
3055 else
3056 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003057
Yi Zou63f39bd2009-05-17 12:34:35 +00003058#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003059 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003060 struct ixgbe_ring_feature *f;
3061 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003062 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003063 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003064 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3065 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003066 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003067 } else if (!ring_is_rsc_enabled(rx_ring) &&
3068 !ring_is_ps_enabled(rx_ring)) {
3069 rx_ring->rx_buf_len =
3070 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003071 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003072 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003073#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003074 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003075}
3076
Alexander Duyck73670962010-08-19 13:38:34 +00003077static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3078{
3079 struct ixgbe_hw *hw = &adapter->hw;
3080 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3081
3082 switch (hw->mac.type) {
3083 case ixgbe_mac_82598EB:
3084 /*
3085 * For VMDq support of different descriptor types or
3086 * buffer sizes through the use of multiple SRRCTL
3087 * registers, RDRXCTL.MVMEN must be set to 1
3088 *
3089 * also, the manual doesn't mention it clearly but DCA hints
3090 * will only use queue 0's tags unless this bit is set. Side
3091 * effects of setting this bit are only that SRRCTL must be
3092 * fully programmed [0..15]
3093 */
3094 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3095 break;
3096 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003097 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003098 /* Disable RSC for ACK packets */
3099 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3100 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3101 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3102 /* hardware requires some bits to be set by default */
3103 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3104 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3105 break;
3106 default:
3107 /* We should do nothing since we don't know this hardware */
3108 return;
3109 }
3110
3111 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3112}
3113
Alexander Duyck477de6e2010-08-19 13:38:11 +00003114/**
3115 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3116 * @adapter: board private structure
3117 *
3118 * Configure the Rx unit of the MAC after a reset.
3119 **/
3120static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3121{
3122 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003123 int i;
3124 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003125
3126 /* disable receives while setting up the descriptors */
3127 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3128 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3129
3130 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003131 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003132
Alexander Duyck9e10e042010-08-19 13:40:06 +00003133 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003134 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003135
Alexander Duyck9e10e042010-08-19 13:40:06 +00003136 ixgbe_set_uta(adapter);
3137
Alexander Duyck477de6e2010-08-19 13:38:11 +00003138 /* set_rx_buffer_len must be called before ring initialization */
3139 ixgbe_set_rx_buffer_len(adapter);
3140
3141 /*
3142 * Setup the HW Rx Head and Tail Descriptor Pointers and
3143 * the Base and Length of the Rx Descriptor Ring
3144 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145 for (i = 0; i < adapter->num_rx_queues; i++)
3146 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003147
Alexander Duyck9e10e042010-08-19 13:40:06 +00003148 /* disable drop enable for 82598 parts */
3149 if (hw->mac.type == ixgbe_mac_82598EB)
3150 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3151
3152 /* enable all receives */
3153 rxctrl |= IXGBE_RXCTRL_RXEN;
3154 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003155}
3156
Jiri Pirko8e586132011-12-08 19:52:37 -05003157static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003158{
3159 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003160 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003161 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003162
3163 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003164 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003165 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003166
3167 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003168}
3169
Jiri Pirko8e586132011-12-08 19:52:37 -05003170static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003171{
3172 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003173 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003174 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003175
Auke Kok9a799d72007-09-15 14:07:45 -07003176 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003177 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003178 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003179
3180 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003181}
3182
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003183/**
3184 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3185 * @adapter: driver data
3186 */
3187static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3188{
3189 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003190 u32 vlnctrl;
3191
3192 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3193 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3194 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3195}
3196
3197/**
3198 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3199 * @adapter: driver data
3200 */
3201static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3202{
3203 struct ixgbe_hw *hw = &adapter->hw;
3204 u32 vlnctrl;
3205
3206 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3207 vlnctrl |= IXGBE_VLNCTRL_VFE;
3208 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3209 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3210}
3211
3212/**
3213 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3214 * @adapter: driver data
3215 */
3216static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3217{
3218 struct ixgbe_hw *hw = &adapter->hw;
3219 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003220 int i, j;
3221
3222 switch (hw->mac.type) {
3223 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003224 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3225 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003226 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3227 break;
3228 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003229 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003230 for (i = 0; i < adapter->num_rx_queues; i++) {
3231 j = adapter->rx_ring[i]->reg_idx;
3232 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3233 vlnctrl &= ~IXGBE_RXDCTL_VME;
3234 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3235 }
3236 break;
3237 default:
3238 break;
3239 }
3240}
3241
3242/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003243 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003244 * @adapter: driver data
3245 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003246static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003247{
3248 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003249 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003250 int i, j;
3251
3252 switch (hw->mac.type) {
3253 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003254 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3255 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003256 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3257 break;
3258 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003259 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003260 for (i = 0; i < adapter->num_rx_queues; i++) {
3261 j = adapter->rx_ring[i]->reg_idx;
3262 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3263 vlnctrl |= IXGBE_RXDCTL_VME;
3264 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3265 }
3266 break;
3267 default:
3268 break;
3269 }
3270}
3271
Auke Kok9a799d72007-09-15 14:07:45 -07003272static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3273{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003274 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003275
Jesse Grossf62bbb52010-10-20 13:56:10 +00003276 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3277
3278 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3279 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003280}
3281
3282/**
Alexander Duyck28500622010-06-15 09:25:48 +00003283 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3284 * @netdev: network interface device structure
3285 *
3286 * Writes unicast address list to the RAR table.
3287 * Returns: -ENOMEM on failure/insufficient address space
3288 * 0 on no addresses written
3289 * X on writing X addresses to the RAR table
3290 **/
3291static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3292{
3293 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3294 struct ixgbe_hw *hw = &adapter->hw;
3295 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003296 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003297 int count = 0;
3298
3299 /* return ENOMEM indicating insufficient memory for addresses */
3300 if (netdev_uc_count(netdev) > rar_entries)
3301 return -ENOMEM;
3302
3303 if (!netdev_uc_empty(netdev) && rar_entries) {
3304 struct netdev_hw_addr *ha;
3305 /* return error if we do not support writing to RAR table */
3306 if (!hw->mac.ops.set_rar)
3307 return -ENOMEM;
3308
3309 netdev_for_each_uc_addr(ha, netdev) {
3310 if (!rar_entries)
3311 break;
3312 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3313 vfn, IXGBE_RAH_AV);
3314 count++;
3315 }
3316 }
3317 /* write the addresses in reverse order to avoid write combining */
3318 for (; rar_entries > 0 ; rar_entries--)
3319 hw->mac.ops.clear_rar(hw, rar_entries);
3320
3321 return count;
3322}
3323
3324/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003325 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003326 * @netdev: network interface device structure
3327 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003328 * The set_rx_method entry point is called whenever the unicast/multicast
3329 * address list or the network interface flags are updated. This routine is
3330 * responsible for configuring the hardware for proper unicast, multicast and
3331 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003332 **/
Greg Rose7f870472010-01-09 02:25:29 +00003333void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003334{
3335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3336 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003337 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3338 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003339
3340 /* Check for Promiscuous and All Multicast modes */
3341
3342 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3343
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003344 /* set all bits that we expect to always be set */
3345 fctrl |= IXGBE_FCTRL_BAM;
3346 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3347 fctrl |= IXGBE_FCTRL_PMCF;
3348
Alexander Duyck28500622010-06-15 09:25:48 +00003349 /* clear the bits we are changing the status of */
3350 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3351
Auke Kok9a799d72007-09-15 14:07:45 -07003352 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003353 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003354 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003355 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003356 /* don't hardware filter vlans in promisc mode */
3357 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003358 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003359 if (netdev->flags & IFF_ALLMULTI) {
3360 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003361 vmolr |= IXGBE_VMOLR_MPE;
3362 } else {
3363 /*
3364 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003365 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003366 * that we can at least receive multicast traffic
3367 */
3368 hw->mac.ops.update_mc_addr_list(hw, netdev);
3369 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003370 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003371 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003372 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003373 /*
3374 * Write addresses to available RAR registers, if there is not
3375 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003376 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003377 */
3378 count = ixgbe_write_uc_addr_list(netdev);
3379 if (count < 0) {
3380 fctrl |= IXGBE_FCTRL_UPE;
3381 vmolr |= IXGBE_VMOLR_ROPE;
3382 }
3383 }
3384
3385 if (adapter->num_vfs) {
3386 ixgbe_restore_vf_multicasts(adapter);
3387 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3388 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3389 IXGBE_VMOLR_ROPE);
3390 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003391 }
3392
3393 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003394
3395 if (netdev->features & NETIF_F_HW_VLAN_RX)
3396 ixgbe_vlan_strip_enable(adapter);
3397 else
3398 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003399}
3400
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003401static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3402{
3403 int q_idx;
3404 struct ixgbe_q_vector *q_vector;
3405 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3406
3407 /* legacy and MSI only use one vector */
3408 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3409 q_vectors = 1;
3410
3411 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003412 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003413 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003414 }
3415}
3416
3417static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3418{
3419 int q_idx;
3420 struct ixgbe_q_vector *q_vector;
3421 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3422
3423 /* legacy and MSI only use one vector */
3424 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3425 q_vectors = 1;
3426
3427 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003428 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003429 napi_disable(&q_vector->napi);
3430 }
3431}
3432
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003433#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003434/*
3435 * ixgbe_configure_dcb - Configure DCB hardware
3436 * @adapter: ixgbe adapter struct
3437 *
3438 * This is called by the driver on open to configure the DCB hardware.
3439 * This is also called by the gennetlink interface when reconfiguring
3440 * the DCB state.
3441 */
3442static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3443{
3444 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003445 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003446
Alexander Duyck67ebd792010-08-19 13:34:04 +00003447 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3448 if (hw->mac.type == ixgbe_mac_82598EB)
3449 netif_set_gso_max_size(adapter->netdev, 65536);
3450 return;
3451 }
3452
3453 if (hw->mac.type == ixgbe_mac_82598EB)
3454 netif_set_gso_max_size(adapter->netdev, 32768);
3455
Alexander Duyck2f90b862008-11-20 20:52:10 -08003456
Alexander Duyck2f90b862008-11-20 20:52:10 -08003457 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003458 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003459
Alexander Duyck2f90b862008-11-20 20:52:10 -08003460 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003461
John Fastabendb1208182011-10-15 05:00:10 +00003462#ifdef IXGBE_FCOE
3463 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3464 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3465#endif
3466
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003467 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003468 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003469 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3470 DCB_TX_CONFIG);
3471 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3472 DCB_RX_CONFIG);
3473 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003474 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3475 ixgbe_dcb_hw_ets(&adapter->hw,
3476 adapter->ixgbe_ieee_ets,
3477 max_frame);
3478 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3479 adapter->ixgbe_ieee_pfc->pfc_en,
3480 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003481 }
John Fastabend8187cd42011-02-23 05:58:08 +00003482
3483 /* Enable RSS Hash per TC */
3484 if (hw->mac.type != ixgbe_mac_82598EB) {
3485 int i;
3486 u32 reg = 0;
3487
3488 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3489 u8 msb = 0;
3490 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3491
3492 while (cnt >>= 1)
3493 msb++;
3494
3495 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3496 }
3497 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3498 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003499}
John Fastabend9da712d2011-08-23 03:14:22 +00003500#endif
3501
3502/* Additional bittime to account for IXGBE framing */
3503#define IXGBE_ETH_FRAMING 20
3504
3505/*
3506 * ixgbe_hpbthresh - calculate high water mark for flow control
3507 *
3508 * @adapter: board private structure to calculate for
3509 * @pb - packet buffer to calculate
3510 */
3511static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3512{
3513 struct ixgbe_hw *hw = &adapter->hw;
3514 struct net_device *dev = adapter->netdev;
3515 int link, tc, kb, marker;
3516 u32 dv_id, rx_pba;
3517
3518 /* Calculate max LAN frame size */
3519 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3520
3521#ifdef IXGBE_FCOE
3522 /* FCoE traffic class uses FCOE jumbo frames */
3523 if (dev->features & NETIF_F_FCOE_MTU) {
3524 int fcoe_pb = 0;
3525
3526#ifdef CONFIG_IXGBE_DCB
3527 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003528
3529#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003530 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3531 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3532 }
3533#endif
3534
3535 /* Calculate delay value for device */
3536 switch (hw->mac.type) {
3537 case ixgbe_mac_X540:
3538 dv_id = IXGBE_DV_X540(link, tc);
3539 break;
3540 default:
3541 dv_id = IXGBE_DV(link, tc);
3542 break;
3543 }
3544
3545 /* Loopback switch introduces additional latency */
3546 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3547 dv_id += IXGBE_B2BT(tc);
3548
3549 /* Delay value is calculated in bit times convert to KB */
3550 kb = IXGBE_BT2KB(dv_id);
3551 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3552
3553 marker = rx_pba - kb;
3554
3555 /* It is possible that the packet buffer is not large enough
3556 * to provide required headroom. In this case throw an error
3557 * to user and a do the best we can.
3558 */
3559 if (marker < 0) {
3560 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3561 "headroom to support flow control."
3562 "Decrease MTU or number of traffic classes\n", pb);
3563 marker = tc + 1;
3564 }
3565
3566 return marker;
3567}
3568
3569/*
3570 * ixgbe_lpbthresh - calculate low water mark for for flow control
3571 *
3572 * @adapter: board private structure to calculate for
3573 * @pb - packet buffer to calculate
3574 */
3575static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3576{
3577 struct ixgbe_hw *hw = &adapter->hw;
3578 struct net_device *dev = adapter->netdev;
3579 int tc;
3580 u32 dv_id;
3581
3582 /* Calculate max LAN frame size */
3583 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3584
3585 /* Calculate delay value for device */
3586 switch (hw->mac.type) {
3587 case ixgbe_mac_X540:
3588 dv_id = IXGBE_LOW_DV_X540(tc);
3589 break;
3590 default:
3591 dv_id = IXGBE_LOW_DV(tc);
3592 break;
3593 }
3594
3595 /* Delay value is calculated in bit times convert to KB */
3596 return IXGBE_BT2KB(dv_id);
3597}
3598
3599/*
3600 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3601 */
3602static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3603{
3604 struct ixgbe_hw *hw = &adapter->hw;
3605 int num_tc = netdev_get_num_tc(adapter->netdev);
3606 int i;
3607
3608 if (!num_tc)
3609 num_tc = 1;
3610
3611 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3612
3613 for (i = 0; i < num_tc; i++) {
3614 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3615
3616 /* Low water marks must not be larger than high water marks */
3617 if (hw->fc.low_water > hw->fc.high_water[i])
3618 hw->fc.low_water = 0;
3619 }
3620}
John Fastabend80605c652011-05-02 12:34:10 +00003621
3622static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3623{
John Fastabend80605c652011-05-02 12:34:10 +00003624 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003625 int hdrm;
3626 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003627
3628 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3629 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003630 hdrm = 32 << adapter->fdir_pballoc;
3631 else
3632 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003633
Alexander Duyckf7e10272011-07-21 00:40:35 +00003634 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003635 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003636}
3637
Alexander Duycke4911d52011-05-11 07:18:52 +00003638static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3639{
3640 struct ixgbe_hw *hw = &adapter->hw;
3641 struct hlist_node *node, *node2;
3642 struct ixgbe_fdir_filter *filter;
3643
3644 spin_lock(&adapter->fdir_perfect_lock);
3645
3646 if (!hlist_empty(&adapter->fdir_filter_list))
3647 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3648
3649 hlist_for_each_entry_safe(filter, node, node2,
3650 &adapter->fdir_filter_list, fdir_node) {
3651 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003652 &filter->filter,
3653 filter->sw_idx,
3654 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3655 IXGBE_FDIR_DROP_QUEUE :
3656 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003657 }
3658
3659 spin_unlock(&adapter->fdir_perfect_lock);
3660}
3661
Auke Kok9a799d72007-09-15 14:07:45 -07003662static void ixgbe_configure(struct ixgbe_adapter *adapter)
3663{
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003664 struct ixgbe_hw *hw = &adapter->hw;
3665
John Fastabend80605c652011-05-02 12:34:10 +00003666 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003667#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003668 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003669#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003670
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003671 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003672 ixgbe_restore_vlan(adapter);
3673
Yi Zoueacd73f2009-05-13 13:11:06 +00003674#ifdef IXGBE_FCOE
3675 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3676 ixgbe_configure_fcoe(adapter);
3677
3678#endif /* IXGBE_FCOE */
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003679
3680 switch (hw->mac.type) {
3681 case ixgbe_mac_82599EB:
3682 case ixgbe_mac_X540:
3683 hw->mac.ops.disable_rx_buff(hw);
3684 break;
3685 default:
3686 break;
3687 }
3688
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003689 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003690 ixgbe_init_fdir_signature_82599(&adapter->hw,
3691 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003692 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3693 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3694 adapter->fdir_pballoc);
3695 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003696 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003697
Atita Shirwaikard2f5e7f2012-02-18 02:58:58 +00003698 switch (hw->mac.type) {
3699 case ixgbe_mac_82599EB:
3700 case ixgbe_mac_X540:
3701 hw->mac.ops.enable_rx_buff(hw);
3702 break;
3703 default:
3704 break;
3705 }
3706
Alexander Duyck933d41f2010-09-07 21:34:29 +00003707 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003708
Auke Kok9a799d72007-09-15 14:07:45 -07003709 ixgbe_configure_tx(adapter);
3710 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003711}
3712
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003713static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3714{
3715 switch (hw->phy.type) {
3716 case ixgbe_phy_sfp_avago:
3717 case ixgbe_phy_sfp_ftl:
3718 case ixgbe_phy_sfp_intel:
3719 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003720 case ixgbe_phy_sfp_passive_tyco:
3721 case ixgbe_phy_sfp_passive_unknown:
3722 case ixgbe_phy_sfp_active_unknown:
3723 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003724 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003725 case ixgbe_phy_nl:
3726 if (hw->mac.type == ixgbe_mac_82598EB)
3727 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003728 default:
3729 return false;
3730 }
3731}
3732
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003733/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003734 * ixgbe_sfp_link_config - set up SFP+ link
3735 * @adapter: pointer to private adapter struct
3736 **/
3737static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3738{
Alexander Duyck70864002011-04-27 09:13:56 +00003739 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003740 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003741 * is that an SFP was inserted/removed after the reset
3742 * but before SFP detection was enabled. As such the best
3743 * solution is to just start searching as soon as we start
3744 */
3745 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3746 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003747
Alexander Duyck70864002011-04-27 09:13:56 +00003748 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003749}
3750
3751/**
3752 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003753 * @hw: pointer to private hardware struct
3754 *
3755 * Returns 0 on success, negative on failure
3756 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003757static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003758{
3759 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003760 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003761 u32 ret = IXGBE_ERR_LINK_SETUP;
3762
3763 if (hw->mac.ops.check_link)
3764 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3765
3766 if (ret)
3767 goto link_cfg_out;
3768
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003769 autoneg = hw->phy.autoneg_advertised;
3770 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003771 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3772 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003773 if (ret)
3774 goto link_cfg_out;
3775
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003776 if (hw->mac.ops.setup_link)
3777 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003778link_cfg_out:
3779 return ret;
3780}
3781
Alexander Duycka34bcff2010-08-19 13:39:20 +00003782static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003783{
Auke Kok9a799d72007-09-15 14:07:45 -07003784 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003785 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003786
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003787 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003788 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3789 IXGBE_GPIE_OCD;
3790 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003791 /*
3792 * use EIAM to auto-mask when MSI-X interrupt is asserted
3793 * this saves a register write for every interrupt
3794 */
3795 switch (hw->mac.type) {
3796 case ixgbe_mac_82598EB:
3797 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3798 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003799 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003800 case ixgbe_mac_X540:
3801 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003802 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3803 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3804 break;
3805 }
3806 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003807 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3808 * specifically only auto mask tx and rx interrupts */
3809 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003810 }
3811
Alexander Duycka34bcff2010-08-19 13:39:20 +00003812 /* XXX: to interrupt immediately for EICS writes, enable this */
3813 /* gpie |= IXGBE_GPIE_EIMEN; */
3814
3815 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3816 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3817 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003818 }
3819
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003820 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003821 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3822 switch (adapter->hw.mac.type) {
3823 case ixgbe_mac_82599EB:
3824 gpie |= IXGBE_SDP0_GPIEN;
3825 break;
3826 case ixgbe_mac_X540:
3827 gpie |= IXGBE_EIMS_TS;
3828 break;
3829 default:
3830 break;
3831 }
3832 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003833
Alexander Duycka34bcff2010-08-19 13:39:20 +00003834 /* Enable fan failure interrupt */
3835 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003836 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003837
Don Skidmore2698b202011-04-13 07:01:52 +00003838 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003839 gpie |= IXGBE_SDP1_GPIEN;
3840 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003841 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003842
3843 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3844}
3845
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003846static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003847{
3848 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003849 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003850 u32 ctrl_ext;
3851
3852 ixgbe_get_hw_control(adapter);
3853 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003854
Auke Kok9a799d72007-09-15 14:07:45 -07003855 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3856 ixgbe_configure_msix(adapter);
3857 else
3858 ixgbe_configure_msi_and_legacy(adapter);
3859
Don Skidmorec6ecf392010-12-03 03:31:51 +00003860 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3861 if (hw->mac.ops.enable_tx_laser &&
3862 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003863 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003864 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003865 hw->mac.ops.enable_tx_laser(hw);
3866
Auke Kok9a799d72007-09-15 14:07:45 -07003867 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003868 ixgbe_napi_enable_all(adapter);
3869
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003870 if (ixgbe_is_sfp(hw)) {
3871 ixgbe_sfp_link_config(adapter);
3872 } else {
3873 err = ixgbe_non_sfp_link_config(hw);
3874 if (err)
3875 e_err(probe, "link_config FAILED %d\n", err);
3876 }
3877
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003878 /* clear any pending interrupts, may auto mask */
3879 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003880 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003881
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003882 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003883 * If this adapter has a fan, check to see if we had a failure
3884 * before we enabled the interrupt.
3885 */
3886 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3887 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3888 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003889 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003890 }
3891
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003892 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003893 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003894
Auke Kok9a799d72007-09-15 14:07:45 -07003895 /* bring the link up in the watchdog, this could race with our first
3896 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003897 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3898 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003899 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003900
3901 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3902 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3903 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3904 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003905}
3906
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003907void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3908{
3909 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003910 /* put off any impending NetWatchDogTimeout */
3911 adapter->netdev->trans_start = jiffies;
3912
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003913 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003914 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003915 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003916 /*
3917 * If SR-IOV enabled then wait a bit before bringing the adapter
3918 * back up to give the VFs time to respond to the reset. The
3919 * two second wait is based upon the watchdog timer cycle in
3920 * the VF driver.
3921 */
3922 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3923 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003924 ixgbe_up(adapter);
3925 clear_bit(__IXGBE_RESETTING, &adapter->state);
3926}
3927
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003928void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003929{
3930 /* hardware has been reset, we need to reload some things */
3931 ixgbe_configure(adapter);
3932
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003933 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003934}
3935
3936void ixgbe_reset(struct ixgbe_adapter *adapter)
3937{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003938 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003939 int err;
3940
Alexander Duyck70864002011-04-27 09:13:56 +00003941 /* lock SFP init bit to prevent race conditions with the watchdog */
3942 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3943 usleep_range(1000, 2000);
3944
3945 /* clear all SFP and link config related flags while holding SFP_INIT */
3946 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3947 IXGBE_FLAG2_SFP_NEEDS_RESET);
3948 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3949
Don Skidmore8ca783a2009-05-26 20:40:47 -07003950 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003951 switch (err) {
3952 case 0:
3953 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003954 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003955 break;
3956 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003957 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003958 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003959 case IXGBE_ERR_EEPROM_VERSION:
3960 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003961 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003962 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00003963 "your hardware. If you are experiencing problems "
3964 "please contact your Intel or hardware "
3965 "representative who provided you with this "
3966 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003967 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003968 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003969 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003970 }
Auke Kok9a799d72007-09-15 14:07:45 -07003971
Alexander Duyck70864002011-04-27 09:13:56 +00003972 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3973
Auke Kok9a799d72007-09-15 14:07:45 -07003974 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003975 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3976 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003977}
3978
Auke Kok9a799d72007-09-15 14:07:45 -07003979/**
3980 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003981 * @rx_ring: ring to free buffers from
3982 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003983static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003984{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003985 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003986 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003987 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003988
Alexander Duyck84418e32010-08-19 13:40:54 +00003989 /* ring already cleared, nothing to do */
3990 if (!rx_ring->rx_buffer_info)
3991 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003992
Alexander Duyck84418e32010-08-19 13:40:54 +00003993 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003994 for (i = 0; i < rx_ring->count; i++) {
3995 struct ixgbe_rx_buffer *rx_buffer_info;
3996
3997 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3998 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003999 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004000 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004001 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004002 rx_buffer_info->dma = 0;
4003 }
4004 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004005 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004006 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004007 /* We need to clean up RSC frag lists */
4008 skb = ixgbe_merge_active_tail(skb);
4009 ixgbe_close_active_frag_list(skb);
4010 if (IXGBE_CB(skb)->delay_unmap) {
4011 dma_unmap_single(dev,
4012 IXGBE_CB(skb)->dma,
4013 rx_ring->rx_buf_len,
4014 DMA_FROM_DEVICE);
4015 IXGBE_CB(skb)->dma = 0;
4016 IXGBE_CB(skb)->delay_unmap = false;
4017 }
4018 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004019 }
4020 if (!rx_buffer_info->page)
4021 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004022 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004023 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004024 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004025 rx_buffer_info->page_dma = 0;
4026 }
Auke Kok9a799d72007-09-15 14:07:45 -07004027 put_page(rx_buffer_info->page);
4028 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004029 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004030 }
4031
4032 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4033 memset(rx_ring->rx_buffer_info, 0, size);
4034
4035 /* Zero out the descriptor ring */
4036 memset(rx_ring->desc, 0, rx_ring->size);
4037
4038 rx_ring->next_to_clean = 0;
4039 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004040}
4041
4042/**
4043 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004044 * @tx_ring: ring to be cleaned
4045 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004046static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004047{
4048 struct ixgbe_tx_buffer *tx_buffer_info;
4049 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004050 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004051
Alexander Duyck84418e32010-08-19 13:40:54 +00004052 /* ring already cleared, nothing to do */
4053 if (!tx_ring->tx_buffer_info)
4054 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004055
Alexander Duyck84418e32010-08-19 13:40:54 +00004056 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004057 for (i = 0; i < tx_ring->count; i++) {
4058 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004059 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004060 }
4061
4062 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4063 memset(tx_ring->tx_buffer_info, 0, size);
4064
4065 /* Zero out the descriptor ring */
4066 memset(tx_ring->desc, 0, tx_ring->size);
4067
4068 tx_ring->next_to_use = 0;
4069 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004070}
4071
4072/**
Auke Kok9a799d72007-09-15 14:07:45 -07004073 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4074 * @adapter: board private structure
4075 **/
4076static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4077{
4078 int i;
4079
4080 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004081 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004082}
4083
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004084/**
4085 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4086 * @adapter: board private structure
4087 **/
4088static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4089{
4090 int i;
4091
4092 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004093 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004094}
4095
Alexander Duycke4911d52011-05-11 07:18:52 +00004096static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4097{
4098 struct hlist_node *node, *node2;
4099 struct ixgbe_fdir_filter *filter;
4100
4101 spin_lock(&adapter->fdir_perfect_lock);
4102
4103 hlist_for_each_entry_safe(filter, node, node2,
4104 &adapter->fdir_filter_list, fdir_node) {
4105 hlist_del(&filter->fdir_node);
4106 kfree(filter);
4107 }
4108 adapter->fdir_filter_count = 0;
4109
4110 spin_unlock(&adapter->fdir_perfect_lock);
4111}
4112
Auke Kok9a799d72007-09-15 14:07:45 -07004113void ixgbe_down(struct ixgbe_adapter *adapter)
4114{
4115 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004116 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004117 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004118 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004119
4120 /* signal that we are down to the interrupt handler */
4121 set_bit(__IXGBE_DOWN, &adapter->state);
4122
4123 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004124 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4125 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004126
Yi Zou2d39d572011-01-06 14:29:56 +00004127 /* disable all enabled rx queues */
4128 for (i = 0; i < adapter->num_rx_queues; i++)
4129 /* this call also flushes the previous write */
4130 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4131
Don Skidmore032b4322011-03-18 09:32:53 +00004132 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004133
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004134 netif_tx_stop_all_queues(netdev);
4135
Alexander Duyck70864002011-04-27 09:13:56 +00004136 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004137 netif_carrier_off(netdev);
4138 netif_tx_disable(netdev);
4139
4140 ixgbe_irq_disable(adapter);
4141
4142 ixgbe_napi_disable_all(adapter);
4143
Alexander Duyckd034acf2011-04-27 09:25:34 +00004144 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4145 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004146 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4147
4148 del_timer_sync(&adapter->service_timer);
4149
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004150 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004151 /* Clear EITR Select mapping */
4152 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4153
4154 /* Mark all the VFs as inactive */
4155 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004156 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004157
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004158 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004159 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004160
Auke Kok9a799d72007-09-15 14:07:45 -07004161 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004162 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004163 }
4164
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004165 /* disable transmits in the hardware now that interrupts are off */
4166 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004167 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004168 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004169 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004170
4171 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004172 switch (hw->mac.type) {
4173 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004174 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004175 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004176 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4177 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004178 break;
4179 default:
4180 break;
4181 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004182
Paul Larson6f4a0e42008-06-24 17:00:56 -07004183 if (!pci_channel_offline(adapter->pdev))
4184 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004185
4186 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4187 if (hw->mac.ops.disable_tx_laser &&
4188 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004189 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004190 (hw->mac.type == ixgbe_mac_82599EB))))
4191 hw->mac.ops.disable_tx_laser(hw);
4192
Auke Kok9a799d72007-09-15 14:07:45 -07004193 ixgbe_clean_all_tx_rings(adapter);
4194 ixgbe_clean_all_rx_rings(adapter);
4195
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004196#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004197 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004198 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004199#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004200}
4201
Auke Kok9a799d72007-09-15 14:07:45 -07004202/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004203 * ixgbe_poll - NAPI Rx polling callback
4204 * @napi: structure for representing this polling device
4205 * @budget: how many packets driver is allowed to clean
4206 *
4207 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004208 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004209static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004210{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004211 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004212 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004213 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004214 struct ixgbe_ring *ring;
4215 int per_ring_budget;
4216 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004217
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004218#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004219 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4220 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004221#endif
4222
Alexander Duycka5579282012-02-08 07:50:04 +00004223 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004224 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004225
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004226 /* attempt to distribute budget to each queue fairly, but don't allow
4227 * the budget to go below 1 because we'll exit polling */
4228 if (q_vector->rx.count > 1)
4229 per_ring_budget = max(budget/q_vector->rx.count, 1);
4230 else
4231 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004232
Alexander Duycka5579282012-02-08 07:50:04 +00004233 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004234 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4235 per_ring_budget);
4236
4237 /* If all work not completed, return budget and keep polling */
4238 if (!clean_complete)
4239 return budget;
4240
4241 /* all work done, exit the polling mode */
4242 napi_complete(napi);
4243 if (adapter->rx_itr_setting & 1)
4244 ixgbe_set_itr(q_vector);
4245 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4246 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4247
4248 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004249}
4250
4251/**
4252 * ixgbe_tx_timeout - Respond to a Tx Hang
4253 * @netdev: network interface device structure
4254 **/
4255static void ixgbe_tx_timeout(struct net_device *netdev)
4256{
4257 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4258
4259 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004260 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004261}
4262
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004263/**
4264 * ixgbe_set_rss_queues: Allocate queues for RSS
4265 * @adapter: board private structure to initialize
4266 *
4267 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4268 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4269 *
4270 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004271static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4272{
4273 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004274 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004275
4276 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004277 f->mask = 0xF;
4278 adapter->num_rx_queues = f->indices;
4279 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004280 ret = true;
4281 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004282 ret = false;
4283 }
4284
4285 return ret;
4286}
4287
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004288/**
4289 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4290 * @adapter: board private structure to initialize
4291 *
4292 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4293 * to the original CPU that initiated the Tx session. This runs in addition
4294 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4295 * Rx load across CPUs using RSS.
4296 *
4297 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004298static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004299{
4300 bool ret = false;
4301 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4302
4303 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4304 f_fdir->mask = 0;
4305
Alexander Duyck24ddd962012-02-10 02:08:32 +00004306 /*
4307 * Use RSS in addition to Flow Director to ensure the best
4308 * distribution of flows across cores, even when an FDIR flow
4309 * isn't matched.
4310 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004311 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4312 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004313 adapter->num_tx_queues = f_fdir->indices;
4314 adapter->num_rx_queues = f_fdir->indices;
4315 ret = true;
4316 } else {
4317 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004318 }
4319 return ret;
4320}
4321
Yi Zou0331a832009-05-17 12:33:52 +00004322#ifdef IXGBE_FCOE
4323/**
4324 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4325 * @adapter: board private structure to initialize
4326 *
4327 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4328 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4329 * rx queues out of the max number of rx queues, instead, it is used as the
4330 * index of the first rx queue used by FCoE.
4331 *
4332 **/
4333static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4334{
Yi Zou0331a832009-05-17 12:33:52 +00004335 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4336
John Fastabende5b64632011-03-08 03:44:52 +00004337 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4338 return false;
4339
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004340 f->indices = min_t(int, num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004341
John Fastabende901acd2011-04-26 07:26:08 +00004342 adapter->num_rx_queues = 1;
4343 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004344
John Fastabende901acd2011-04-26 07:26:08 +00004345 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4346 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004347 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004348 ixgbe_set_fdir_queues(adapter);
4349 else
4350 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004351 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004352
John Fastabende901acd2011-04-26 07:26:08 +00004353 /* adding FCoE rx rings to the end */
4354 f->mask = adapter->num_rx_queues;
4355 adapter->num_rx_queues += f->indices;
4356 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004357
John Fastabende5b64632011-03-08 03:44:52 +00004358 return true;
4359}
4360#endif /* IXGBE_FCOE */
4361
John Fastabende901acd2011-04-26 07:26:08 +00004362/* Artificial max queue cap per traffic class in DCB mode */
4363#define DCB_QUEUE_CAP 8
4364
John Fastabende5b64632011-03-08 03:44:52 +00004365#ifdef CONFIG_IXGBE_DCB
4366static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4367{
John Fastabende901acd2011-04-26 07:26:08 +00004368 int per_tc_q, q, i, offset = 0;
4369 struct net_device *dev = adapter->netdev;
4370 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004371
John Fastabende901acd2011-04-26 07:26:08 +00004372 if (!tcs)
4373 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004374
John Fastabende901acd2011-04-26 07:26:08 +00004375 /* Map queue offset and counts onto allocated tx queues */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00004376 per_tc_q = min_t(unsigned int, dev->num_tx_queues / tcs, DCB_QUEUE_CAP);
4377 q = min_t(int, num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004378
John Fastabend8b1c0b22011-05-03 02:26:48 +00004379 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004380 netdev_set_tc_queue(dev, i, q, offset);
4381 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004382 }
4383
John Fastabende901acd2011-04-26 07:26:08 +00004384 adapter->num_tx_queues = q * tcs;
4385 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004386
4387#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004388 /* FCoE enabled queues require special configuration indexed
4389 * by feature specific indices and mask. Here we map FCoE
4390 * indices onto the DCB queue pairs allowing FCoE to own
4391 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004392 */
John Fastabende901acd2011-04-26 07:26:08 +00004393 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4394 int tc;
4395 struct ixgbe_ring_feature *f =
4396 &adapter->ring_feature[RING_F_FCOE];
4397
4398 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4399 f->indices = dev->tc_to_txq[tc].count;
4400 f->mask = dev->tc_to_txq[tc].offset;
4401 }
John Fastabende5b64632011-03-08 03:44:52 +00004402#endif
4403
John Fastabende901acd2011-04-26 07:26:08 +00004404 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004405}
John Fastabende5b64632011-03-08 03:44:52 +00004406#endif
Yi Zou0331a832009-05-17 12:33:52 +00004407
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004408/**
4409 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4410 * @adapter: board private structure to initialize
4411 *
4412 * IOV doesn't actually use anything, so just NAK the
4413 * request for now and let the other queue routines
4414 * figure out what to do.
4415 */
4416static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4417{
4418 return false;
4419}
4420
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004421/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004422 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004423 * @adapter: board private structure to initialize
4424 *
4425 * This is the top level queue allocation routine. The order here is very
4426 * important, starting with the "most" number of features turned on at once,
4427 * and ending with the smallest set of features. This way large combinations
4428 * can be allocated if they're turned on, and smaller combinations are the
4429 * fallthrough conditions.
4430 *
4431 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004432static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004433{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004434 /* Start with base case */
4435 adapter->num_rx_queues = 1;
4436 adapter->num_tx_queues = 1;
4437 adapter->num_rx_pools = adapter->num_rx_queues;
4438 adapter->num_rx_queues_per_pool = 1;
4439
4440 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004441 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004442
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004443#ifdef CONFIG_IXGBE_DCB
4444 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004445 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004446
4447#endif
John Fastabende5b64632011-03-08 03:44:52 +00004448#ifdef IXGBE_FCOE
4449 if (ixgbe_set_fcoe_queues(adapter))
4450 goto done;
4451
4452#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004453 if (ixgbe_set_fdir_queues(adapter))
4454 goto done;
4455
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004456 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004457 goto done;
4458
4459 /* fallback to base case */
4460 adapter->num_rx_queues = 1;
4461 adapter->num_tx_queues = 1;
4462
4463done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004464 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4465 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4466 return 0;
4467
Ben Hutchings847f53f2010-09-27 08:28:56 +00004468 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004469 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004470 return netif_set_real_num_rx_queues(adapter->netdev,
4471 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004472}
4473
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004474static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004475 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004476{
4477 int err, vector_threshold;
4478
Alexander Duyck8f154862012-02-10 02:08:37 +00004479 /* We'll want at least 2 (vector_threshold):
4480 * 1) TxQ[0] + RxQ[0] handler
4481 * 2) Other (Link Status Change, etc.)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004482 */
4483 vector_threshold = MIN_MSIX_COUNT;
4484
Alexander Duyck24ddd962012-02-10 02:08:32 +00004485 /*
4486 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004487 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4488 * Right now, we simply care about how many we'll get; we'll
4489 * set them up later while requesting irq's.
4490 */
4491 while (vectors >= vector_threshold) {
4492 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004493 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004494 if (!err) /* Success in acquiring all requested vectors. */
4495 break;
4496 else if (err < 0)
4497 vectors = 0; /* Nasty failure, quit now */
4498 else /* err == number of vectors we should try again with */
4499 vectors = err;
4500 }
4501
4502 if (vectors < vector_threshold) {
4503 /* Can't allocate enough MSI-X interrupts? Oh well.
4504 * This just means we'll go with either a single MSI
4505 * vector or fall back to legacy interrupts.
4506 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004507 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4508 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004509 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4510 kfree(adapter->msix_entries);
4511 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004512 } else {
4513 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004514 /*
4515 * Adjust for only the vectors we'll use, which is minimum
4516 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4517 * vectors we were allocated.
4518 */
4519 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004520 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004521 }
4522}
4523
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004524/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004525 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004526 * @adapter: board private structure to initialize
4527 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004528 * Cache the descriptor ring offsets for RSS to the assigned rings.
4529 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004530 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004531static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004532{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004533 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004534
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004535 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4536 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004537
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004538 for (i = 0; i < adapter->num_rx_queues; i++)
4539 adapter->rx_ring[i]->reg_idx = i;
4540 for (i = 0; i < adapter->num_tx_queues; i++)
4541 adapter->tx_ring[i]->reg_idx = i;
4542
4543 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004544}
4545
4546#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004547
4548/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004549static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4550 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004551{
4552 struct net_device *dev = adapter->netdev;
4553 struct ixgbe_hw *hw = &adapter->hw;
4554 u8 num_tcs = netdev_get_num_tc(dev);
4555
4556 *tx = 0;
4557 *rx = 0;
4558
4559 switch (hw->mac.type) {
4560 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004561 *tx = tc << 2;
4562 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004563 break;
4564 case ixgbe_mac_82599EB:
4565 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004566 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004567 if (tc < 3) {
4568 *tx = tc << 5;
4569 *rx = tc << 4;
4570 } else if (tc < 5) {
4571 *tx = ((tc + 2) << 4);
4572 *rx = tc << 4;
4573 } else if (tc < num_tcs) {
4574 *tx = ((tc + 8) << 3);
4575 *rx = tc << 4;
4576 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004577 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004578 *rx = tc << 5;
4579 switch (tc) {
4580 case 0:
4581 *tx = 0;
4582 break;
4583 case 1:
4584 *tx = 64;
4585 break;
4586 case 2:
4587 *tx = 96;
4588 break;
4589 case 3:
4590 *tx = 112;
4591 break;
4592 default:
4593 break;
4594 }
4595 }
4596 break;
4597 default:
4598 break;
4599 }
4600}
4601
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004602/**
4603 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4604 * @adapter: board private structure to initialize
4605 *
4606 * Cache the descriptor ring offsets for DCB to the assigned rings.
4607 *
4608 **/
4609static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4610{
John Fastabende5b64632011-03-08 03:44:52 +00004611 struct net_device *dev = adapter->netdev;
4612 int i, j, k;
4613 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004614
John Fastabend8b1c0b22011-05-03 02:26:48 +00004615 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004616 return false;
4617
John Fastabende5b64632011-03-08 03:44:52 +00004618 for (i = 0, k = 0; i < num_tcs; i++) {
4619 unsigned int tx_s, rx_s;
4620 u16 count = dev->tc_to_txq[i].count;
4621
4622 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4623 for (j = 0; j < count; j++, k++) {
4624 adapter->tx_ring[k]->reg_idx = tx_s + j;
4625 adapter->rx_ring[k]->reg_idx = rx_s + j;
4626 adapter->tx_ring[k]->dcb_tc = i;
4627 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004628 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004629 }
John Fastabende5b64632011-03-08 03:44:52 +00004630
4631 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004632}
4633#endif
4634
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004635/**
4636 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4637 * @adapter: board private structure to initialize
4638 *
4639 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4640 *
4641 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004642static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004643{
4644 int i;
4645 bool ret = false;
4646
Alexander Duyck03ecf912011-05-20 07:36:17 +00004647 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4648 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004649 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004650 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004651 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004652 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004653 ret = true;
4654 }
4655
4656 return ret;
4657}
4658
Yi Zou0331a832009-05-17 12:33:52 +00004659#ifdef IXGBE_FCOE
4660/**
4661 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4662 * @adapter: board private structure to initialize
4663 *
4664 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4665 *
4666 */
4667static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4668{
Yi Zou0331a832009-05-17 12:33:52 +00004669 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004670 int i;
4671 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004672
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004673 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4674 return false;
4675
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004676 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004677 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004678 ixgbe_cache_ring_fdir(adapter);
4679 else
4680 ixgbe_cache_ring_rss(adapter);
4681
4682 fcoe_rx_i = f->mask;
4683 fcoe_tx_i = f->mask;
4684 }
4685 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4686 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4687 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4688 }
4689 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004690}
4691
4692#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004693/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004694 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4695 * @adapter: board private structure to initialize
4696 *
4697 * SR-IOV doesn't use any descriptor rings but changes the default if
4698 * no other mapping is used.
4699 *
4700 */
4701static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4702{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004703 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4704 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004705 if (adapter->num_vfs)
4706 return true;
4707 else
4708 return false;
4709}
4710
4711/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004712 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4713 * @adapter: board private structure to initialize
4714 *
4715 * Once we know the feature-set enabled for the device, we'll cache
4716 * the register offset the descriptor ring is assigned to.
4717 *
4718 * Note, the order the various feature calls is important. It must start with
4719 * the "most" features enabled at the same time, then trickle down to the
4720 * least amount of features turned on at once.
4721 **/
4722static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4723{
4724 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004725 adapter->rx_ring[0]->reg_idx = 0;
4726 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004727
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004728 if (ixgbe_cache_ring_sriov(adapter))
4729 return;
4730
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004731#ifdef CONFIG_IXGBE_DCB
4732 if (ixgbe_cache_ring_dcb(adapter))
4733 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004734#endif
John Fastabende5b64632011-03-08 03:44:52 +00004735
4736#ifdef IXGBE_FCOE
4737 if (ixgbe_cache_ring_fcoe(adapter))
4738 return;
4739#endif /* IXGBE_FCOE */
4740
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004741 if (ixgbe_cache_ring_fdir(adapter))
4742 return;
4743
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004744 if (ixgbe_cache_ring_rss(adapter))
4745 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004746}
4747
Auke Kok9a799d72007-09-15 14:07:45 -07004748/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004749 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4750 * @adapter: board private structure to initialize
4751 *
4752 * Attempt to configure the interrupts using the best available
4753 * capabilities of the hardware and the kernel.
4754 **/
Al Virofeea6a52008-11-27 15:34:07 -08004755static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004756{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004757 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004758 int err = 0;
4759 int vector, v_budget;
4760
4761 /*
4762 * It's easy to be greedy for MSI-X vectors, but it really
4763 * doesn't do us much good if we have a lot more vectors
4764 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004765 * (roughly) the same number of vectors as there are CPU's.
Alexander Duyck8f154862012-02-10 02:08:37 +00004766 * The default is to use pairs of vectors.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004767 */
Alexander Duyck8f154862012-02-10 02:08:37 +00004768 v_budget = max(adapter->num_rx_queues, adapter->num_tx_queues);
4769 v_budget = min_t(int, v_budget, num_online_cpus());
4770 v_budget += NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004771
4772 /*
4773 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004774 * hw.mac->max_msix_vectors vectors. With features
4775 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4776 * descriptor queues supported by our device. Thus, we cap it off in
4777 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004778 */
Alexander Duyckde88eee2012-02-08 07:49:59 +00004779 v_budget = min_t(int, v_budget, hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004780
4781 /* A failure in MSI-X entry allocation isn't fatal, but it does
4782 * mean we disable MSI-X capabilities of the adapter. */
4783 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004784 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004785 if (adapter->msix_entries) {
4786 for (vector = 0; vector < v_budget; vector++)
4787 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004788
Alexander Duyck7a921c92009-05-06 10:43:28 +00004789 ixgbe_acquire_msix_vectors(adapter, v_budget);
4790
4791 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4792 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004793 }
David S. Miller26d27842010-05-03 15:18:22 -07004794
Alexander Duyck7a921c92009-05-06 10:43:28 +00004795 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4796 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004797 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004798 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004799 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004800 "queues are disabled. Disabling Flow Director\n");
4801 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004802 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004803 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004804 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4805 ixgbe_disable_sriov(adapter);
4806
Ben Hutchings847f53f2010-09-27 08:28:56 +00004807 err = ixgbe_set_num_queues(adapter);
4808 if (err)
4809 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004810
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004811 err = pci_enable_msi(adapter->pdev);
4812 if (!err) {
4813 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4814 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004815 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4816 "Unable to allocate MSI interrupt, "
4817 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004818 /* reset err */
4819 err = 0;
4820 }
4821
4822out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004823 return err;
4824}
4825
Alexander Duyckde88eee2012-02-08 07:49:59 +00004826static void ixgbe_add_ring(struct ixgbe_ring *ring,
4827 struct ixgbe_ring_container *head)
4828{
4829 ring->next = head->ring;
4830 head->ring = ring;
4831 head->count++;
4832}
4833
4834/**
4835 * ixgbe_alloc_q_vector - Allocate memory for a single interrupt vector
4836 * @adapter: board private structure to initialize
4837 * @v_idx: index of vector in adapter struct
4838 *
4839 * We allocate one q_vector. If allocation fails we return -ENOMEM.
4840 **/
4841static int ixgbe_alloc_q_vector(struct ixgbe_adapter *adapter, int v_idx,
4842 int txr_count, int txr_idx,
4843 int rxr_count, int rxr_idx)
4844{
4845 struct ixgbe_q_vector *q_vector;
4846 struct ixgbe_ring *ring;
4847 int node = -1;
4848 int cpu = -1;
4849 int ring_count, size;
4850
4851 ring_count = txr_count + rxr_count;
4852 size = sizeof(struct ixgbe_q_vector) +
4853 (sizeof(struct ixgbe_ring) * ring_count);
4854
4855 /* customize cpu for Flow Director mapping */
4856 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
4857 if (cpu_online(v_idx)) {
4858 cpu = v_idx;
4859 node = cpu_to_node(cpu);
4860 }
4861 }
4862
4863 /* allocate q_vector and rings */
4864 q_vector = kzalloc_node(size, GFP_KERNEL, node);
4865 if (!q_vector)
4866 q_vector = kzalloc(size, GFP_KERNEL);
4867 if (!q_vector)
4868 return -ENOMEM;
4869
4870 /* setup affinity mask and node */
4871 if (cpu != -1)
4872 cpumask_set_cpu(cpu, &q_vector->affinity_mask);
4873 else
4874 cpumask_copy(&q_vector->affinity_mask, cpu_online_mask);
4875 q_vector->numa_node = node;
4876
4877 /* initialize NAPI */
4878 netif_napi_add(adapter->netdev, &q_vector->napi,
4879 ixgbe_poll, 64);
4880
4881 /* tie q_vector and adapter together */
4882 adapter->q_vector[v_idx] = q_vector;
4883 q_vector->adapter = adapter;
4884 q_vector->v_idx = v_idx;
4885
4886 /* initialize work limits */
4887 q_vector->tx.work_limit = adapter->tx_work_limit;
4888
4889 /* initialize pointer to rings */
4890 ring = q_vector->ring;
4891
4892 while (txr_count) {
4893 /* assign generic ring traits */
4894 ring->dev = &adapter->pdev->dev;
4895 ring->netdev = adapter->netdev;
4896
4897 /* configure backlink on ring */
4898 ring->q_vector = q_vector;
4899
4900 /* update q_vector Tx values */
4901 ixgbe_add_ring(ring, &q_vector->tx);
4902
4903 /* apply Tx specific ring traits */
4904 ring->count = adapter->tx_ring_count;
4905 ring->queue_index = txr_idx;
4906
4907 /* assign ring to adapter */
4908 adapter->tx_ring[txr_idx] = ring;
4909
4910 /* update count and index */
4911 txr_count--;
4912 txr_idx++;
4913
4914 /* push pointer to next ring */
4915 ring++;
4916 }
4917
4918 while (rxr_count) {
4919 /* assign generic ring traits */
4920 ring->dev = &adapter->pdev->dev;
4921 ring->netdev = adapter->netdev;
4922
4923 /* configure backlink on ring */
4924 ring->q_vector = q_vector;
4925
4926 /* update q_vector Rx values */
4927 ixgbe_add_ring(ring, &q_vector->rx);
4928
4929 /*
4930 * 82599 errata, UDP frames with a 0 checksum
4931 * can be marked as checksum errors.
4932 */
4933 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4934 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4935
4936 /* apply Rx specific ring traits */
4937 ring->count = adapter->rx_ring_count;
4938 ring->queue_index = rxr_idx;
4939
4940 /* assign ring to adapter */
4941 adapter->rx_ring[rxr_idx] = ring;
4942
4943 /* update count and index */
4944 rxr_count--;
4945 rxr_idx++;
4946
4947 /* push pointer to next ring */
4948 ring++;
4949 }
4950
4951 return 0;
4952}
4953
4954/**
4955 * ixgbe_free_q_vector - Free memory allocated for specific interrupt vector
4956 * @adapter: board private structure to initialize
4957 * @v_idx: Index of vector to be freed
4958 *
4959 * This function frees the memory allocated to the q_vector. In addition if
4960 * NAPI is enabled it will delete any references to the NAPI struct prior
4961 * to freeing the q_vector.
4962 **/
4963static void ixgbe_free_q_vector(struct ixgbe_adapter *adapter, int v_idx)
4964{
4965 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4966 struct ixgbe_ring *ring;
4967
Alexander Duycka5579282012-02-08 07:50:04 +00004968 ixgbe_for_each_ring(ring, q_vector->tx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004969 adapter->tx_ring[ring->queue_index] = NULL;
4970
Alexander Duycka5579282012-02-08 07:50:04 +00004971 ixgbe_for_each_ring(ring, q_vector->rx)
Alexander Duyckde88eee2012-02-08 07:49:59 +00004972 adapter->rx_ring[ring->queue_index] = NULL;
4973
4974 adapter->q_vector[v_idx] = NULL;
4975 netif_napi_del(&q_vector->napi);
4976
4977 /*
4978 * ixgbe_get_stats64() might access the rings on this vector,
4979 * we must wait a grace period before freeing it.
4980 */
4981 kfree_rcu(q_vector, rcu);
4982}
4983
Alexander Duyck7a921c92009-05-06 10:43:28 +00004984/**
4985 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4986 * @adapter: board private structure to initialize
4987 *
4988 * We allocate one q_vector per queue interrupt. If allocation fails we
4989 * return -ENOMEM.
4990 **/
4991static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4992{
Alexander Duyckde88eee2012-02-08 07:49:59 +00004993 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
4994 int rxr_remaining = adapter->num_rx_queues;
4995 int txr_remaining = adapter->num_tx_queues;
4996 int rxr_idx = 0, txr_idx = 0, v_idx = 0;
4997 int err;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004998
Alexander Duyckde88eee2012-02-08 07:49:59 +00004999 /* only one q_vector if MSI-X is disabled. */
5000 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
5001 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005002
Alexander Duyckde88eee2012-02-08 07:49:59 +00005003 if (q_vectors >= (rxr_remaining + txr_remaining)) {
5004 for (; rxr_remaining; v_idx++, q_vectors--) {
5005 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5006 err = ixgbe_alloc_q_vector(adapter, v_idx,
5007 0, 0, rqpv, rxr_idx);
5008
5009 if (err)
5010 goto err_out;
5011
5012 /* update counts and index */
5013 rxr_remaining -= rqpv;
5014 rxr_idx += rqpv;
5015 }
5016 }
5017
5018 for (; q_vectors; v_idx++, q_vectors--) {
5019 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors);
5020 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors);
5021 err = ixgbe_alloc_q_vector(adapter, v_idx,
5022 tqpv, txr_idx,
5023 rqpv, rxr_idx);
5024
5025 if (err)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005026 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005027
Alexander Duyckde88eee2012-02-08 07:49:59 +00005028 /* update counts and index */
5029 rxr_remaining -= rqpv;
5030 rxr_idx += rqpv;
5031 txr_remaining -= tqpv;
5032 txr_idx += tqpv;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005033 }
5034
5035 return 0;
5036
5037err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005038 while (v_idx) {
5039 v_idx--;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005040 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041 }
Alexander Duyckde88eee2012-02-08 07:49:59 +00005042
Alexander Duyck7a921c92009-05-06 10:43:28 +00005043 return -ENOMEM;
5044}
5045
5046/**
5047 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5048 * @adapter: board private structure to initialize
5049 *
5050 * This function frees the memory allocated to the q_vectors. In addition if
5051 * NAPI is enabled it will delete any references to the NAPI struct prior
5052 * to freeing the q_vector.
5053 **/
5054static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5055{
Alexander Duyckde88eee2012-02-08 07:49:59 +00005056 int v_idx, q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057
Alexander Duyck91281fd2009-06-04 16:00:27 +00005058 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyckde88eee2012-02-08 07:49:59 +00005059 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005060 else
Alexander Duyckde88eee2012-02-08 07:49:59 +00005061 q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005062
Alexander Duyckde88eee2012-02-08 07:49:59 +00005063 for (v_idx = 0; v_idx < q_vectors; v_idx++)
5064 ixgbe_free_q_vector(adapter, v_idx);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005065}
5066
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005067static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005068{
5069 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5070 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5071 pci_disable_msix(adapter->pdev);
5072 kfree(adapter->msix_entries);
5073 adapter->msix_entries = NULL;
5074 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5075 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5076 pci_disable_msi(adapter->pdev);
5077 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005078}
5079
5080/**
5081 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5082 * @adapter: board private structure to initialize
5083 *
5084 * We determine which interrupt scheme to use based on...
5085 * - Kernel support (MSI, MSI-X)
5086 * - which can be user-defined (via MODULE_PARAM)
5087 * - Hardware queue count (num_*_queues)
5088 * - defined by miscellaneous hardware support/features (RSS, etc.)
5089 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005090int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005091{
5092 int err;
5093
5094 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005095 err = ixgbe_set_num_queues(adapter);
5096 if (err)
5097 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005098
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005099 err = ixgbe_set_interrupt_capability(adapter);
5100 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005101 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005102 goto err_set_interrupt;
5103 }
5104
Alexander Duyck7a921c92009-05-06 10:43:28 +00005105 err = ixgbe_alloc_q_vectors(adapter);
5106 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005107 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005108 goto err_alloc_q_vectors;
5109 }
5110
Alexander Duyckde88eee2012-02-08 07:49:59 +00005111 ixgbe_cache_ring_register(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005112
Emil Tantilov849c4542010-06-03 16:53:41 +00005113 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005114 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5115 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005116
5117 set_bit(__IXGBE_DOWN, &adapter->state);
5118
5119 return 0;
5120
Alexander Duyck7a921c92009-05-06 10:43:28 +00005121err_alloc_q_vectors:
5122 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005123err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005124 return err;
5125}
5126
5127/**
5128 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5129 * @adapter: board private structure to clear interrupt scheme on
5130 *
5131 * We go through and clear interrupt specific resources and reset the structure
5132 * to pre-load conditions
5133 **/
5134void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5135{
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005136 adapter->num_tx_queues = 0;
5137 adapter->num_rx_queues = 0;
5138
Alexander Duyck7a921c92009-05-06 10:43:28 +00005139 ixgbe_free_q_vectors(adapter);
5140 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005141}
5142
5143/**
5144 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5145 * @adapter: board private structure to initialize
5146 *
5147 * ixgbe_sw_init initializes the Adapter private data structure.
5148 * Fields are initialized based on PCI device information and
5149 * OS network device settings (MTU size).
5150 **/
5151static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5152{
5153 struct ixgbe_hw *hw = &adapter->hw;
5154 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005155 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005156#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005157 int j;
5158 struct tc_configuration *tc;
5159#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005160
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005161 /* PCI config space info */
5162
5163 hw->vendor_id = pdev->vendor;
5164 hw->device_id = pdev->device;
5165 hw->revision_id = pdev->revision;
5166 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5167 hw->subsystem_device_id = pdev->subsystem_device;
5168
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005169 /* Set capability flags */
Jesse Brandeburg3ed69d72012-02-10 10:20:02 +00005170 rss = min_t(int, IXGBE_MAX_RSS_INDICES, num_online_cpus());
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005171 adapter->ring_feature[RING_F_RSS].indices = rss;
5172 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005173 switch (hw->mac.type) {
5174 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005175 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5176 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005177 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005178 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005179 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005180 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5181 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005182 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005183 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5184 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005185 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5186 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005187 /* Flow Director hash filters enabled */
5188 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5189 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005190 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005191 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005192 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005193#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005194 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5195 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5196 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005197#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005198 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005199 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005200#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005201#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005202 break;
5203 default:
5204 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005205 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005206
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005207 /* n-tuple support exists, always init our spinlock */
5208 spin_lock_init(&adapter->fdir_perfect_lock);
5209
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005210#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005211 switch (hw->mac.type) {
5212 case ixgbe_mac_X540:
5213 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5214 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5215 break;
5216 default:
5217 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5218 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5219 break;
5220 }
5221
Alexander Duyck2f90b862008-11-20 20:52:10 -08005222 /* Configure DCB traffic classes */
5223 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5224 tc = &adapter->dcb_cfg.tc_config[j];
5225 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5226 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5227 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5228 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5229 tc->dcb_pfc = pfc_disabled;
5230 }
John Fastabend4de2a022011-09-27 03:52:01 +00005231
5232 /* Initialize default user to priority mapping, UPx->TC0 */
5233 tc = &adapter->dcb_cfg.tc_config[0];
5234 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5235 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5236
Alexander Duyck2f90b862008-11-20 20:52:10 -08005237 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5238 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005239 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005240 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005241 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005242 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005243 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005244
5245#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005246
5247 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005248 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005249 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005250#ifdef CONFIG_DCB
5251 adapter->last_lfc_mode = hw->fc.current_mode;
5252#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005253 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005254 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5255 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005256 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005257
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005258 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005259 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005260 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005261
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005262 /* set default ring sizes */
5263 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5264 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5265
Alexander Duyckbd198052011-06-11 01:45:08 +00005266 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005267 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005268
Auke Kok9a799d72007-09-15 14:07:45 -07005269 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005270 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005271 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005272 return -EIO;
5273 }
5274
Auke Kok9a799d72007-09-15 14:07:45 -07005275 set_bit(__IXGBE_DOWN, &adapter->state);
5276
5277 return 0;
5278}
5279
5280/**
5281 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005282 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005283 *
5284 * Return 0 on success, negative on failure
5285 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005286int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005287{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005288 struct device *dev = tx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005289 int orig_node = dev_to_node(dev);
5290 int numa_node = -1;
Auke Kok9a799d72007-09-15 14:07:45 -07005291 int size;
5292
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005293 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005294
5295 if (tx_ring->q_vector)
5296 numa_node = tx_ring->q_vector->numa_node;
5297
5298 tx_ring->tx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005299 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005300 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005301 if (!tx_ring->tx_buffer_info)
5302 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005303
5304 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005305 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005306 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005307
Alexander Duyckde88eee2012-02-08 07:49:59 +00005308 set_dev_node(dev, numa_node);
5309 tx_ring->desc = dma_alloc_coherent(dev,
5310 tx_ring->size,
5311 &tx_ring->dma,
5312 GFP_KERNEL);
5313 set_dev_node(dev, orig_node);
5314 if (!tx_ring->desc)
5315 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
5316 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005317 if (!tx_ring->desc)
5318 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005319
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005320 tx_ring->next_to_use = 0;
5321 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005322 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005323
5324err:
5325 vfree(tx_ring->tx_buffer_info);
5326 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005327 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005328 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005329}
5330
5331/**
Alexander Duyck69888672008-09-11 20:05:39 -07005332 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5333 * @adapter: board private structure
5334 *
5335 * If this function returns with an error, then it's possible one or
5336 * more of the rings is populated (while the rest are not). It is the
5337 * callers duty to clean those orphaned rings.
5338 *
5339 * Return 0 on success, negative on failure
5340 **/
5341static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5342{
5343 int i, err = 0;
5344
5345 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005346 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005347 if (!err)
5348 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005349 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005350 break;
5351 }
5352
5353 return err;
5354}
5355
5356/**
Auke Kok9a799d72007-09-15 14:07:45 -07005357 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005358 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005359 *
5360 * Returns 0 on success, negative on failure
5361 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005362int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005363{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005364 struct device *dev = rx_ring->dev;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005365 int orig_node = dev_to_node(dev);
5366 int numa_node = -1;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005367 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005368
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005369 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Alexander Duyckde88eee2012-02-08 07:49:59 +00005370
5371 if (rx_ring->q_vector)
5372 numa_node = rx_ring->q_vector->numa_node;
5373
5374 rx_ring->rx_buffer_info = vzalloc_node(size, numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005375 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005376 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005377 if (!rx_ring->rx_buffer_info)
5378 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005379
Auke Kok9a799d72007-09-15 14:07:45 -07005380 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005381 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5382 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005383
Alexander Duyckde88eee2012-02-08 07:49:59 +00005384 set_dev_node(dev, numa_node);
5385 rx_ring->desc = dma_alloc_coherent(dev,
5386 rx_ring->size,
5387 &rx_ring->dma,
5388 GFP_KERNEL);
5389 set_dev_node(dev, orig_node);
5390 if (!rx_ring->desc)
5391 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
5392 &rx_ring->dma, GFP_KERNEL);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393 if (!rx_ring->desc)
5394 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005395
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005396 rx_ring->next_to_clean = 0;
5397 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005398
5399 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005400err:
5401 vfree(rx_ring->rx_buffer_info);
5402 rx_ring->rx_buffer_info = NULL;
5403 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005404 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005405}
5406
5407/**
Alexander Duyck69888672008-09-11 20:05:39 -07005408 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5409 * @adapter: board private structure
5410 *
5411 * If this function returns with an error, then it's possible one or
5412 * more of the rings is populated (while the rest are not). It is the
5413 * callers duty to clean those orphaned rings.
5414 *
5415 * Return 0 on success, negative on failure
5416 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005417static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5418{
5419 int i, err = 0;
5420
5421 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005422 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005423 if (!err)
5424 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005425 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005426 break;
5427 }
5428
5429 return err;
5430}
5431
5432/**
Auke Kok9a799d72007-09-15 14:07:45 -07005433 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005434 * @tx_ring: Tx descriptor ring for a specific queue
5435 *
5436 * Free all transmit software resources
5437 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005438void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005439{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005440 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005441
5442 vfree(tx_ring->tx_buffer_info);
5443 tx_ring->tx_buffer_info = NULL;
5444
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005445 /* if not set, then don't free */
5446 if (!tx_ring->desc)
5447 return;
5448
5449 dma_free_coherent(tx_ring->dev, tx_ring->size,
5450 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005451
5452 tx_ring->desc = NULL;
5453}
5454
5455/**
5456 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5457 * @adapter: board private structure
5458 *
5459 * Free all transmit software resources
5460 **/
5461static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5462{
5463 int i;
5464
5465 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005466 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005467 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005468}
5469
5470/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005471 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005472 * @rx_ring: ring to clean the resources from
5473 *
5474 * Free all receive software resources
5475 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005476void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005477{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005478 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005479
5480 vfree(rx_ring->rx_buffer_info);
5481 rx_ring->rx_buffer_info = NULL;
5482
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005483 /* if not set, then don't free */
5484 if (!rx_ring->desc)
5485 return;
5486
5487 dma_free_coherent(rx_ring->dev, rx_ring->size,
5488 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005489
5490 rx_ring->desc = NULL;
5491}
5492
5493/**
5494 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5495 * @adapter: board private structure
5496 *
5497 * Free all receive software resources
5498 **/
5499static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5500{
5501 int i;
5502
5503 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005504 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005505 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005506}
5507
5508/**
Auke Kok9a799d72007-09-15 14:07:45 -07005509 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5510 * @netdev: network interface device structure
5511 * @new_mtu: new value for maximum frame size
5512 *
5513 * Returns 0 on success, negative on failure
5514 **/
5515static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5516{
5517 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005518 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005519 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5520
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005521 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005522 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5523 hw->mac.type != ixgbe_mac_X540) {
5524 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5525 return -EINVAL;
5526 } else {
5527 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5528 return -EINVAL;
5529 }
Auke Kok9a799d72007-09-15 14:07:45 -07005530
Emil Tantilov396e7992010-07-01 20:05:12 +00005531 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005532 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005533 netdev->mtu = new_mtu;
5534
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005535 if (netif_running(netdev))
5536 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005537
5538 return 0;
5539}
5540
5541/**
5542 * ixgbe_open - Called when a network interface is made active
5543 * @netdev: network interface device structure
5544 *
5545 * Returns 0 on success, negative value on failure
5546 *
5547 * The open entry point is called when a network interface is made
5548 * active by the system (IFF_UP). At this point all resources needed
5549 * for transmit and receive operations are allocated, the interrupt
5550 * handler is registered with the OS, the watchdog timer is started,
5551 * and the stack is notified that the interface is ready.
5552 **/
5553static int ixgbe_open(struct net_device *netdev)
5554{
5555 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5556 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005557
Auke Kok4bebfaa2008-02-11 09:26:01 -08005558 /* disallow open during test */
5559 if (test_bit(__IXGBE_TESTING, &adapter->state))
5560 return -EBUSY;
5561
Jesse Brandeburg54386462009-04-17 20:44:27 +00005562 netif_carrier_off(netdev);
5563
Auke Kok9a799d72007-09-15 14:07:45 -07005564 /* allocate transmit descriptors */
5565 err = ixgbe_setup_all_tx_resources(adapter);
5566 if (err)
5567 goto err_setup_tx;
5568
Auke Kok9a799d72007-09-15 14:07:45 -07005569 /* allocate receive descriptors */
5570 err = ixgbe_setup_all_rx_resources(adapter);
5571 if (err)
5572 goto err_setup_rx;
5573
5574 ixgbe_configure(adapter);
5575
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005576 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005577 if (err)
5578 goto err_req_irq;
5579
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005580 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005581
5582 return 0;
5583
Auke Kok9a799d72007-09-15 14:07:45 -07005584err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005585err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005586 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005587err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005588 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005589 ixgbe_reset(adapter);
5590
5591 return err;
5592}
5593
5594/**
5595 * ixgbe_close - Disables a network interface
5596 * @netdev: network interface device structure
5597 *
5598 * Returns 0, this is not allowed to fail
5599 *
5600 * The close entry point is called when an interface is de-activated
5601 * by the OS. The hardware is still under the drivers control, but
5602 * needs to be disabled. A global MAC reset is issued to stop the
5603 * hardware, and all transmit and receive resources are freed.
5604 **/
5605static int ixgbe_close(struct net_device *netdev)
5606{
5607 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005608
5609 ixgbe_down(adapter);
5610 ixgbe_free_irq(adapter);
5611
Alexander Duycke4911d52011-05-11 07:18:52 +00005612 ixgbe_fdir_filter_exit(adapter);
5613
Auke Kok9a799d72007-09-15 14:07:45 -07005614 ixgbe_free_all_tx_resources(adapter);
5615 ixgbe_free_all_rx_resources(adapter);
5616
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005617 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005618
5619 return 0;
5620}
5621
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005622#ifdef CONFIG_PM
5623static int ixgbe_resume(struct pci_dev *pdev)
5624{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005625 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5626 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005627 u32 err;
5628
5629 pci_set_power_state(pdev, PCI_D0);
5630 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005631 /*
5632 * pci_restore_state clears dev->state_saved so call
5633 * pci_save_state to restore it.
5634 */
5635 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005636
5637 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005638 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005639 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005640 return err;
5641 }
5642 pci_set_master(pdev);
5643
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005644 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005645
5646 err = ixgbe_init_interrupt_scheme(adapter);
5647 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005648 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005649 return err;
5650 }
5651
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005652 ixgbe_reset(adapter);
5653
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005654 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5655
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005656 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005657 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005658 if (err)
5659 return err;
5660 }
5661
5662 netif_device_attach(netdev);
5663
5664 return 0;
5665}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005666#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005667
5668static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005669{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005670 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5671 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005672 struct ixgbe_hw *hw = &adapter->hw;
5673 u32 ctrl, fctrl;
5674 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005675#ifdef CONFIG_PM
5676 int retval = 0;
5677#endif
5678
5679 netif_device_detach(netdev);
5680
5681 if (netif_running(netdev)) {
5682 ixgbe_down(adapter);
5683 ixgbe_free_irq(adapter);
5684 ixgbe_free_all_tx_resources(adapter);
5685 ixgbe_free_all_rx_resources(adapter);
5686 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005687
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005688 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005689#ifdef CONFIG_DCB
5690 kfree(adapter->ixgbe_ieee_pfc);
5691 kfree(adapter->ixgbe_ieee_ets);
5692#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005693
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005694#ifdef CONFIG_PM
5695 retval = pci_save_state(pdev);
5696 if (retval)
5697 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005698
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005699#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005700 if (wufc) {
5701 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005702
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005703 /* turn on all-multi mode if wake on multicast is enabled */
5704 if (wufc & IXGBE_WUFC_MC) {
5705 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5706 fctrl |= IXGBE_FCTRL_MPE;
5707 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5708 }
5709
5710 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5711 ctrl |= IXGBE_CTRL_GIO_DIS;
5712 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5713
5714 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5715 } else {
5716 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5717 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5718 }
5719
Alexander Duyckbd508172010-11-16 19:27:03 -08005720 switch (hw->mac.type) {
5721 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005722 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005723 break;
5724 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005725 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005726 pci_wake_from_d3(pdev, !!wufc);
5727 break;
5728 default:
5729 break;
5730 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005731
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005732 *enable_wake = !!wufc;
5733
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005734 ixgbe_release_hw_control(adapter);
5735
5736 pci_disable_device(pdev);
5737
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005738 return 0;
5739}
5740
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005741#ifdef CONFIG_PM
5742static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5743{
5744 int retval;
5745 bool wake;
5746
5747 retval = __ixgbe_shutdown(pdev, &wake);
5748 if (retval)
5749 return retval;
5750
5751 if (wake) {
5752 pci_prepare_to_sleep(pdev);
5753 } else {
5754 pci_wake_from_d3(pdev, false);
5755 pci_set_power_state(pdev, PCI_D3hot);
5756 }
5757
5758 return 0;
5759}
5760#endif /* CONFIG_PM */
5761
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005762static void ixgbe_shutdown(struct pci_dev *pdev)
5763{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005764 bool wake;
5765
5766 __ixgbe_shutdown(pdev, &wake);
5767
5768 if (system_state == SYSTEM_POWER_OFF) {
5769 pci_wake_from_d3(pdev, wake);
5770 pci_set_power_state(pdev, PCI_D3hot);
5771 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005772}
5773
5774/**
Auke Kok9a799d72007-09-15 14:07:45 -07005775 * ixgbe_update_stats - Update the board statistics counters.
5776 * @adapter: board private structure
5777 **/
5778void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5779{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005780 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005781 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005782 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005783 u64 total_mpc = 0;
5784 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005785 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5786 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005787 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005788#ifdef IXGBE_FCOE
5789 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5790 unsigned int cpu;
5791 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5792#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005793
Don Skidmored08935c2010-06-11 13:20:29 +00005794 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5795 test_bit(__IXGBE_RESETTING, &adapter->state))
5796 return;
5797
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005798 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005799 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005800 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005801 for (i = 0; i < 16; i++)
5802 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005803 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005804 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005805 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5806 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005807 }
5808 adapter->rsc_total_count = rsc_count;
5809 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005810 }
5811
Alexander Duyck5b7da512010-11-16 19:26:50 -08005812 for (i = 0; i < adapter->num_rx_queues; i++) {
5813 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5814 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5815 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5816 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005817 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005818 bytes += rx_ring->stats.bytes;
5819 packets += rx_ring->stats.packets;
5820 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005821 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005822 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5823 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005824 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005825 netdev->stats.rx_bytes = bytes;
5826 netdev->stats.rx_packets = packets;
5827
5828 bytes = 0;
5829 packets = 0;
5830 /* gather some stats to the adapter struct that are per queue */
5831 for (i = 0; i < adapter->num_tx_queues; i++) {
5832 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5833 restart_queue += tx_ring->tx_stats.restart_queue;
5834 tx_busy += tx_ring->tx_stats.tx_busy;
5835 bytes += tx_ring->stats.bytes;
5836 packets += tx_ring->stats.packets;
5837 }
5838 adapter->restart_queue = restart_queue;
5839 adapter->tx_busy = tx_busy;
5840 netdev->stats.tx_bytes = bytes;
5841 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005842
Joe Perches7ca647b2010-09-07 21:35:40 +00005843 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005844
5845 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005846 for (i = 0; i < 8; i++) {
5847 /* for packet buffers not used, the register should read 0 */
5848 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5849 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005850 hwstats->mpc[i] += mpc;
5851 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005852 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5853 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005854 switch (hw->mac.type) {
5855 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005856 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5857 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5858 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005859 hwstats->pxonrxc[i] +=
5860 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005861 break;
5862 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005863 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005864 hwstats->pxonrxc[i] +=
5865 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005866 break;
5867 default:
5868 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005869 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005870 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005871
5872 /*16 register reads */
5873 for (i = 0; i < 16; i++) {
5874 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5875 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5876 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5877 (hw->mac.type == ixgbe_mac_X540)) {
5878 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5879 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5880 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5881 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5882 }
5883 }
5884
Joe Perches7ca647b2010-09-07 21:35:40 +00005885 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005886 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005887 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005888
John Fastabendc84d3242010-11-16 19:27:12 -08005889 ixgbe_update_xoff_received(adapter);
5890
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005891 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005892 switch (hw->mac.type) {
5893 case ixgbe_mac_82598EB:
5894 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005895 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5896 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5897 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5898 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005899 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005900 /* OS2BMC stats are X540 only*/
5901 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5902 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5903 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5904 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5905 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005906 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005907 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005908 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005909 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005910 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005911 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005912 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005913 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5914 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005915#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005916 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5917 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5918 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5919 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5920 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5921 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005922 /* Add up per cpu counters for total ddp aloc fail */
5923 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5924 for_each_possible_cpu(cpu) {
5925 fcoe_noddp_counts_sum +=
5926 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5927 fcoe_noddp_ext_buff_counts_sum +=
5928 *per_cpu_ptr(fcoe->
5929 pcpu_noddp_ext_buff, cpu);
5930 }
5931 }
5932 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5933 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005934#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005935 break;
5936 default:
5937 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005938 }
Auke Kok9a799d72007-09-15 14:07:45 -07005939 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005940 hwstats->bprc += bprc;
5941 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005942 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005943 hwstats->mprc -= bprc;
5944 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5945 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5946 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5947 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5948 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5949 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5950 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5951 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005952 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005953 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005954 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005955 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005956 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5957 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005958 /*
5959 * 82598 errata - tx of flow control packets is included in tx counters
5960 */
5961 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005962 hwstats->gptc -= xon_off_tot;
5963 hwstats->mptc -= xon_off_tot;
5964 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5965 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5966 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5967 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5968 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5969 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5970 hwstats->ptc64 -= xon_off_tot;
5971 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5972 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5973 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5974 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5975 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5976 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005977
5978 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005979 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005980
5981 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005982 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005983 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005984 netdev->stats.rx_length_errors = hwstats->rlec;
5985 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005986 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005987}
5988
5989/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005990 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5991 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005992 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005993static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005994{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005995 struct ixgbe_hw *hw = &adapter->hw;
5996 int i;
5997
Alexander Duyckd034acf2011-04-27 09:25:34 +00005998 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5999 return;
6000
6001 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
6002
6003 /* if interface is down do nothing */
6004 if (test_bit(__IXGBE_DOWN, &adapter->state))
6005 return;
6006
6007 /* do nothing if we are not using signature filters */
6008 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
6009 return;
6010
6011 adapter->fdir_overflow++;
6012
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006013 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6014 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006015 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006016 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006017 /* re-enable flow director interrupts */
6018 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006019 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006020 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006021 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006022 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006023}
6024
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006025/**
6026 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6027 * @adapter - pointer to the device adapter structure
6028 *
6029 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006030 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006031 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006032 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006033 */
6034static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6035{
Auke Kok9a799d72007-09-15 14:07:45 -07006036 struct ixgbe_hw *hw = &adapter->hw;
6037 u64 eics = 0;
6038 int i;
6039
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006040 /* If we're down or resetting, just bail */
6041 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6042 test_bit(__IXGBE_RESETTING, &adapter->state))
6043 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006044
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006045 /* Force detection of hung controller */
6046 if (netif_carrier_ok(adapter->netdev)) {
6047 for (i = 0; i < adapter->num_tx_queues; i++)
6048 set_check_for_tx_hang(adapter->tx_ring[i]);
6049 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006050
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006051 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006052 /*
6053 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006054 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006055 * would set *both* EIMS and EICS for any bit in EIAM
6056 */
6057 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6058 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006059 } else {
6060 /* get one bit for every active tx/rx interrupt vector */
6061 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6062 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006063 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006064 eics |= ((u64)1 << i);
6065 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006066 }
6067
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006068 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006069 ixgbe_irq_rearm_queues(adapter, eics);
6070
Alexander Duyckfe49f042009-06-04 16:00:09 +00006071}
6072
6073/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006074 * ixgbe_watchdog_update_link - update the link status
6075 * @adapter - pointer to the device adapter structure
6076 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006077 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006078static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006079{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006080 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006081 u32 link_speed = adapter->link_speed;
6082 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006083 int i;
6084
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006085 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6086 return;
6087
6088 if (hw->mac.ops.check_link) {
6089 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006090 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006091 /* always assume link is up, if no check link function */
6092 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6093 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006094 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006095 if (link_up) {
6096 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6097 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6098 hw->mac.ops.fc_enable(hw, i);
6099 } else {
6100 hw->mac.ops.fc_enable(hw, 0);
6101 }
6102 }
6103
6104 if (link_up ||
6105 time_after(jiffies, (adapter->link_check_timeout +
6106 IXGBE_TRY_LINK_TIMEOUT))) {
6107 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6108 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6109 IXGBE_WRITE_FLUSH(hw);
6110 }
6111
6112 adapter->link_up = link_up;
6113 adapter->link_speed = link_speed;
6114}
6115
6116/**
6117 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6118 * print link up message
6119 * @adapter - pointer to the device adapter structure
6120 **/
6121static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6122{
6123 struct net_device *netdev = adapter->netdev;
6124 struct ixgbe_hw *hw = &adapter->hw;
6125 u32 link_speed = adapter->link_speed;
6126 bool flow_rx, flow_tx;
6127
6128 /* only continue if link was previously down */
6129 if (netif_carrier_ok(netdev))
6130 return;
6131
6132 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6133
6134 switch (hw->mac.type) {
6135 case ixgbe_mac_82598EB: {
6136 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6137 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6138 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6139 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6140 }
6141 break;
6142 case ixgbe_mac_X540:
6143 case ixgbe_mac_82599EB: {
6144 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6145 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6146 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6147 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6148 }
6149 break;
6150 default:
6151 flow_tx = false;
6152 flow_rx = false;
6153 break;
6154 }
6155 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6156 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6157 "10 Gbps" :
6158 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6159 "1 Gbps" :
6160 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6161 "100 Mbps" :
6162 "unknown speed"))),
6163 ((flow_rx && flow_tx) ? "RX/TX" :
6164 (flow_rx ? "RX" :
6165 (flow_tx ? "TX" : "None"))));
6166
6167 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006168 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006169}
6170
6171/**
6172 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6173 * print link down message
6174 * @adapter - pointer to the adapter structure
6175 **/
6176static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6177{
6178 struct net_device *netdev = adapter->netdev;
6179 struct ixgbe_hw *hw = &adapter->hw;
6180
6181 adapter->link_up = false;
6182 adapter->link_speed = 0;
6183
6184 /* only continue if link was up previously */
6185 if (!netif_carrier_ok(netdev))
6186 return;
6187
6188 /* poll for SFP+ cable when link is down */
6189 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6190 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6191
6192 e_info(drv, "NIC Link is Down\n");
6193 netif_carrier_off(netdev);
6194}
6195
6196/**
6197 * ixgbe_watchdog_flush_tx - flush queues on link down
6198 * @adapter - pointer to the device adapter structure
6199 **/
6200static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6201{
6202 int i;
6203 int some_tx_pending = 0;
6204
6205 if (!netif_carrier_ok(adapter->netdev)) {
6206 for (i = 0; i < adapter->num_tx_queues; i++) {
6207 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6208 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6209 some_tx_pending = 1;
6210 break;
6211 }
6212 }
6213
6214 if (some_tx_pending) {
6215 /* We've lost link, so the controller stops DMA,
6216 * but we've got queued Tx work that's never going
6217 * to get done, so reset controller to flush Tx.
6218 * (Do the reset outside of interrupt context).
6219 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006220 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006221 }
6222 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006223}
6224
Greg Rosea985b6c32010-11-18 03:02:52 +00006225static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6226{
6227 u32 ssvpc;
6228
6229 /* Do not perform spoof check for 82598 */
6230 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6231 return;
6232
6233 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6234
6235 /*
6236 * ssvpc register is cleared on read, if zero then no
6237 * spoofed packets in the last interval.
6238 */
6239 if (!ssvpc)
6240 return;
6241
6242 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6243}
6244
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006245/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006246 * ixgbe_watchdog_subtask - check and bring link up
6247 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006248 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006249static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006250{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006251 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006252 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6253 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006254 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006255
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006256 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006257
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006258 if (adapter->link_up)
6259 ixgbe_watchdog_link_is_up(adapter);
6260 else
6261 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006262
Greg Rosea985b6c32010-11-18 03:02:52 +00006263 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006264 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006265
6266 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006267}
6268
Alexander Duyck70864002011-04-27 09:13:56 +00006269/**
6270 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6271 * @adapter - the ixgbe adapter structure
6272 **/
6273static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6274{
6275 struct ixgbe_hw *hw = &adapter->hw;
6276 s32 err;
6277
6278 /* not searching for SFP so there is nothing to do here */
6279 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6280 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6281 return;
6282
6283 /* someone else is in init, wait until next service event */
6284 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6285 return;
6286
6287 err = hw->phy.ops.identify_sfp(hw);
6288 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6289 goto sfp_out;
6290
6291 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6292 /* If no cable is present, then we need to reset
6293 * the next time we find a good cable. */
6294 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6295 }
6296
6297 /* exit on error */
6298 if (err)
6299 goto sfp_out;
6300
6301 /* exit if reset not needed */
6302 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6303 goto sfp_out;
6304
6305 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6306
6307 /*
6308 * A module may be identified correctly, but the EEPROM may not have
6309 * support for that module. setup_sfp() will fail in that case, so
6310 * we should not allow that module to load.
6311 */
6312 if (hw->mac.type == ixgbe_mac_82598EB)
6313 err = hw->phy.ops.reset(hw);
6314 else
6315 err = hw->mac.ops.setup_sfp(hw);
6316
6317 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6318 goto sfp_out;
6319
6320 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6321 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6322
6323sfp_out:
6324 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6325
6326 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6327 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6328 e_dev_err("failed to initialize because an unsupported "
6329 "SFP+ module type was detected.\n");
6330 e_dev_err("Reload the driver after installing a "
6331 "supported module.\n");
6332 unregister_netdev(adapter->netdev);
6333 }
6334}
6335
6336/**
6337 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6338 * @adapter - the ixgbe adapter structure
6339 **/
6340static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6341{
6342 struct ixgbe_hw *hw = &adapter->hw;
6343 u32 autoneg;
6344 bool negotiation;
6345
6346 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6347 return;
6348
6349 /* someone else is in init, wait until next service event */
6350 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6351 return;
6352
6353 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6354
6355 autoneg = hw->phy.autoneg_advertised;
6356 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6357 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006358 if (hw->mac.ops.setup_link)
6359 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6360
6361 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6362 adapter->link_check_timeout = jiffies;
6363 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6364}
6365
Greg Rose83c61fa2011-09-07 05:59:35 +00006366#ifdef CONFIG_PCI_IOV
6367static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6368{
6369 int vf;
6370 struct ixgbe_hw *hw = &adapter->hw;
6371 struct net_device *netdev = adapter->netdev;
6372 u32 gpc;
6373 u32 ciaa, ciad;
6374
6375 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6376 if (gpc) /* If incrementing then no need for the check below */
6377 return;
6378 /*
6379 * Check to see if a bad DMA write target from an errant or
6380 * malicious VF has caused a PCIe error. If so then we can
6381 * issue a VFLR to the offending VF(s) and then resume without
6382 * requesting a full slot reset.
6383 */
6384
6385 for (vf = 0; vf < adapter->num_vfs; vf++) {
6386 ciaa = (vf << 16) | 0x80000000;
6387 /* 32 bit read so align, we really want status at offset 6 */
6388 ciaa |= PCI_COMMAND;
6389 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6390 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6391 ciaa &= 0x7FFFFFFF;
6392 /* disable debug mode asap after reading data */
6393 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6394 /* Get the upper 16 bits which will be the PCI status reg */
6395 ciad >>= 16;
6396 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6397 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6398 /* Issue VFLR */
6399 ciaa = (vf << 16) | 0x80000000;
6400 ciaa |= 0xA8;
6401 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6402 ciad = 0x00008000; /* VFLR */
6403 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6404 ciaa &= 0x7FFFFFFF;
6405 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6406 }
6407 }
6408}
6409
6410#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006411/**
6412 * ixgbe_service_timer - Timer Call-back
6413 * @data: pointer to adapter cast into an unsigned long
6414 **/
6415static void ixgbe_service_timer(unsigned long data)
6416{
6417 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6418 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006419 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006420
Greg Rose83c61fa2011-09-07 05:59:35 +00006421#ifdef CONFIG_PCI_IOV
6422 ready = false;
6423
6424 /*
6425 * don't bother with SR-IOV VF DMA hang check if there are
6426 * no VFs or the link is down
6427 */
6428 if (!adapter->num_vfs ||
6429 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6430 ready = true;
6431 goto normal_timer_service;
6432 }
6433
6434 /* If we have VFs allocated then we must check for DMA hangs */
6435 ixgbe_check_for_bad_vf(adapter);
6436 next_event_offset = HZ / 50;
6437 adapter->timer_event_accumulator++;
6438
6439 if (adapter->timer_event_accumulator >= 100) {
6440 ready = true;
6441 adapter->timer_event_accumulator = 0;
6442 }
6443
6444 goto schedule_event;
6445
6446normal_timer_service:
6447#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006448 /* poll faster when waiting for link */
6449 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6450 next_event_offset = HZ / 10;
6451 else
6452 next_event_offset = HZ * 2;
6453
Greg Rose83c61fa2011-09-07 05:59:35 +00006454#ifdef CONFIG_PCI_IOV
6455schedule_event:
6456#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006457 /* Reset the timer */
6458 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6459
Greg Rose83c61fa2011-09-07 05:59:35 +00006460 if (ready)
6461 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006462}
6463
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006464static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6465{
6466 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6467 return;
6468
6469 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6470
6471 /* If we're already down or resetting, just bail */
6472 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6473 test_bit(__IXGBE_RESETTING, &adapter->state))
6474 return;
6475
6476 ixgbe_dump(adapter);
6477 netdev_err(adapter->netdev, "Reset adapter\n");
6478 adapter->tx_timeout_count++;
6479
6480 ixgbe_reinit_locked(adapter);
6481}
6482
Alexander Duyck70864002011-04-27 09:13:56 +00006483/**
6484 * ixgbe_service_task - manages and runs subtasks
6485 * @work: pointer to work_struct containing our data
6486 **/
6487static void ixgbe_service_task(struct work_struct *work)
6488{
6489 struct ixgbe_adapter *adapter = container_of(work,
6490 struct ixgbe_adapter,
6491 service_task);
6492
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006493 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006494 ixgbe_sfp_detection_subtask(adapter);
6495 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006496 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006497 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006498 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006499 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006500
6501 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006502}
6503
Alexander Duyck897ab152011-05-27 05:31:47 +00006504void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6505 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006506{
6507 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006508 u16 i = tx_ring->next_to_use;
6509
Alexander Duycke4f74022012-01-31 02:59:44 +00006510 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006511
6512 i++;
6513 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6514
6515 /* set bits to identify this as an advanced context descriptor */
6516 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6517
6518 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6519 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6520 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6521 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6522}
6523
6524static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6525 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6526{
Auke Kok9a799d72007-09-15 14:07:45 -07006527 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006528 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006529 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006530
Alexander Duyck897ab152011-05-27 05:31:47 +00006531 if (!skb_is_gso(skb))
6532 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006533
Alexander Duyck897ab152011-05-27 05:31:47 +00006534 if (skb_header_cloned(skb)) {
6535 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6536 if (err)
6537 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006538 }
6539
Alexander Duyck897ab152011-05-27 05:31:47 +00006540 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6541 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6542
6543 if (protocol == __constant_htons(ETH_P_IP)) {
6544 struct iphdr *iph = ip_hdr(skb);
6545 iph->tot_len = 0;
6546 iph->check = 0;
6547 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6548 iph->daddr, 0,
6549 IPPROTO_TCP,
6550 0);
6551 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6552 } else if (skb_is_gso_v6(skb)) {
6553 ipv6_hdr(skb)->payload_len = 0;
6554 tcp_hdr(skb)->check =
6555 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6556 &ipv6_hdr(skb)->daddr,
6557 0, IPPROTO_TCP, 0);
6558 }
6559
6560 l4len = tcp_hdrlen(skb);
6561 *hdr_len = skb_transport_offset(skb) + l4len;
6562
6563 /* mss_l4len_id: use 1 as index for TSO */
6564 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6565 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6566 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6567
6568 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6569 vlan_macip_lens = skb_network_header_len(skb);
6570 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6571 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6572
6573 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6574 mss_l4len_idx);
6575
6576 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006577}
6578
Alexander Duyck897ab152011-05-27 05:31:47 +00006579static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006580 struct sk_buff *skb, u32 tx_flags,
6581 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006582{
Alexander Duyck897ab152011-05-27 05:31:47 +00006583 u32 vlan_macip_lens = 0;
6584 u32 mss_l4len_idx = 0;
6585 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006586
Alexander Duyck897ab152011-05-27 05:31:47 +00006587 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006588 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6589 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006590 return false;
6591 } else {
6592 u8 l4_hdr = 0;
6593 switch (protocol) {
6594 case __constant_htons(ETH_P_IP):
6595 vlan_macip_lens |= skb_network_header_len(skb);
6596 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6597 l4_hdr = ip_hdr(skb)->protocol;
6598 break;
6599 case __constant_htons(ETH_P_IPV6):
6600 vlan_macip_lens |= skb_network_header_len(skb);
6601 l4_hdr = ipv6_hdr(skb)->nexthdr;
6602 break;
6603 default:
6604 if (unlikely(net_ratelimit())) {
6605 dev_warn(tx_ring->dev,
6606 "partial checksum but proto=%x!\n",
6607 skb->protocol);
6608 }
6609 break;
6610 }
Auke Kok9a799d72007-09-15 14:07:45 -07006611
Alexander Duyck897ab152011-05-27 05:31:47 +00006612 switch (l4_hdr) {
6613 case IPPROTO_TCP:
6614 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6615 mss_l4len_idx = tcp_hdrlen(skb) <<
6616 IXGBE_ADVTXD_L4LEN_SHIFT;
6617 break;
6618 case IPPROTO_SCTP:
6619 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6620 mss_l4len_idx = sizeof(struct sctphdr) <<
6621 IXGBE_ADVTXD_L4LEN_SHIFT;
6622 break;
6623 case IPPROTO_UDP:
6624 mss_l4len_idx = sizeof(struct udphdr) <<
6625 IXGBE_ADVTXD_L4LEN_SHIFT;
6626 break;
6627 default:
6628 if (unlikely(net_ratelimit())) {
6629 dev_warn(tx_ring->dev,
6630 "partial checksum but l4 proto=%x!\n",
6631 skb->protocol);
6632 }
6633 break;
6634 }
Auke Kok9a799d72007-09-15 14:07:45 -07006635 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006636
Alexander Duyck897ab152011-05-27 05:31:47 +00006637 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6638 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6639
6640 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6641 type_tucmd, mss_l4len_idx);
6642
6643 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006644}
6645
Alexander Duyckd3d00232011-07-15 02:31:25 +00006646static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6647{
6648 /* set type for advanced descriptor with frame checksum insertion */
6649 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6650 IXGBE_ADVTXD_DCMD_IFCS |
6651 IXGBE_ADVTXD_DCMD_DEXT);
6652
6653 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006654 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006655 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6656
6657 /* set segmentation enable bits for TSO/FSO */
6658#ifdef IXGBE_FCOE
6659 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6660#else
6661 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6662#endif
6663 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6664
6665 return cmd_type;
6666}
6667
6668static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6669{
6670 __le32 olinfo_status =
6671 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6672
6673 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6674 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6675 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6676 /* enble IPv4 checksum for TSO */
6677 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6678 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6679 }
6680
6681 /* enable L4 checksum for TSO and TX checksum offload */
6682 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6683 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6684
6685#ifdef IXGBE_FCOE
6686 /* use index 1 context for FCOE/FSO */
6687 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6688 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6689 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6690
6691#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006692 /*
6693 * Check Context must be set if Tx switch is enabled, which it
6694 * always is for case where virtual functions are running
6695 */
6696 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6697 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6698
Alexander Duyckd3d00232011-07-15 02:31:25 +00006699 return olinfo_status;
6700}
6701
6702#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6703 IXGBE_TXD_CMD_RS)
6704
6705static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6706 struct sk_buff *skb,
6707 struct ixgbe_tx_buffer *first,
6708 u32 tx_flags,
6709 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006710{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006711 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006712 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006713 union ixgbe_adv_tx_desc *tx_desc;
6714 dma_addr_t dma;
6715 __le32 cmd_type, olinfo_status;
6716 struct skb_frag_struct *frag;
6717 unsigned int f = 0;
6718 unsigned int data_len = skb->data_len;
6719 unsigned int size = skb_headlen(skb);
6720 u32 offset = 0;
6721 u32 paylen = skb->len - hdr_len;
6722 u16 i = tx_ring->next_to_use;
6723 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006724
Alexander Duyckd3d00232011-07-15 02:31:25 +00006725#ifdef IXGBE_FCOE
6726 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6727 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6728 data_len -= sizeof(struct fcoe_crc_eof);
6729 } else {
6730 size -= sizeof(struct fcoe_crc_eof) - data_len;
6731 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006732 }
Auke Kok9a799d72007-09-15 14:07:45 -07006733 }
6734
Alexander Duyckd3d00232011-07-15 02:31:25 +00006735#endif
6736 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6737 if (dma_mapping_error(dev, dma))
6738 goto dma_error;
6739
6740 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6741 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6742
Alexander Duycke4f74022012-01-31 02:59:44 +00006743 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006744
6745 for (;;) {
6746 while (size > IXGBE_MAX_DATA_PER_TXD) {
6747 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6748 tx_desc->read.cmd_type_len =
6749 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6750 tx_desc->read.olinfo_status = olinfo_status;
6751
6752 offset += IXGBE_MAX_DATA_PER_TXD;
6753 size -= IXGBE_MAX_DATA_PER_TXD;
6754
6755 tx_desc++;
6756 i++;
6757 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006758 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006759 i = 0;
6760 }
6761 }
6762
6763 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6764 tx_buffer_info->length = offset + size;
6765 tx_buffer_info->tx_flags = tx_flags;
6766 tx_buffer_info->dma = dma;
6767
6768 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6769 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6770 tx_desc->read.olinfo_status = olinfo_status;
6771
6772 if (!data_len)
6773 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006774
6775 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006776#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006777 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006778#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006779 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006780#endif
6781 data_len -= size;
6782 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006783
Alexander Duyckd3d00232011-07-15 02:31:25 +00006784 offset = 0;
6785 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006786
Ian Campbell877749b2011-08-29 23:18:26 +00006787 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006788 if (dma_mapping_error(dev, dma))
6789 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006790
Alexander Duyckd3d00232011-07-15 02:31:25 +00006791 tx_desc++;
6792 i++;
6793 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006794 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006795 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006796 }
6797 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006798
Alexander Duyckd3d00232011-07-15 02:31:25 +00006799 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6800
6801 i++;
6802 if (i == tx_ring->count)
6803 i = 0;
6804
6805 tx_ring->next_to_use = i;
6806
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006807 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6808 gso_segs = skb_shinfo(skb)->gso_segs;
6809#ifdef IXGBE_FCOE
6810 /* adjust for FCoE Sequence Offload */
6811 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6812 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6813 skb_shinfo(skb)->gso_size);
6814#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006815 else
6816 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006817
6818 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006819 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6820 tx_buffer_info->gso_segs = gso_segs;
6821 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006822
Alexander Duyckb2d96e02012-02-07 08:14:33 +00006823 netdev_tx_sent_queue(txring_txq(tx_ring), tx_buffer_info->bytecount);
6824
Alexander Duyckd3d00232011-07-15 02:31:25 +00006825 /* set the timestamp */
6826 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006827
6828 /*
6829 * Force memory writes to complete before letting h/w
6830 * know there are new descriptors to fetch. (Only
6831 * applicable for weak-ordered memory model archs,
6832 * such as IA-64).
6833 */
6834 wmb();
6835
Alexander Duyckd3d00232011-07-15 02:31:25 +00006836 /* set next_to_watch value indicating a packet is present */
6837 first->next_to_watch = tx_desc;
6838
6839 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006840 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006841
6842 return;
6843dma_error:
6844 dev_err(dev, "TX DMA map failed\n");
6845
6846 /* clear dma mappings for failed tx_buffer_info map */
6847 for (;;) {
6848 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6849 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6850 if (tx_buffer_info == first)
6851 break;
6852 if (i == 0)
6853 i = tx_ring->count;
6854 i--;
6855 }
6856
6857 dev_kfree_skb_any(skb);
6858
6859 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006860}
6861
Alexander Duyck69830522011-01-06 14:29:58 +00006862static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6863 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006864{
Alexander Duyck69830522011-01-06 14:29:58 +00006865 struct ixgbe_q_vector *q_vector = ring->q_vector;
6866 union ixgbe_atr_hash_dword input = { .dword = 0 };
6867 union ixgbe_atr_hash_dword common = { .dword = 0 };
6868 union {
6869 unsigned char *network;
6870 struct iphdr *ipv4;
6871 struct ipv6hdr *ipv6;
6872 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006873 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006874 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006875
Alexander Duyck69830522011-01-06 14:29:58 +00006876 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6877 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006878 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006879
Alexander Duyck69830522011-01-06 14:29:58 +00006880 /* do nothing if sampling is disabled */
6881 if (!ring->atr_sample_rate)
6882 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006883
Alexander Duyck69830522011-01-06 14:29:58 +00006884 ring->atr_count++;
6885
6886 /* snag network header to get L4 type and address */
6887 hdr.network = skb_network_header(skb);
6888
6889 /* Currently only IPv4/IPv6 with TCP is supported */
6890 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6891 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6892 (protocol != __constant_htons(ETH_P_IP) ||
6893 hdr.ipv4->protocol != IPPROTO_TCP))
6894 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006895
6896 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006897
Alexander Duyck66f32a82011-06-29 05:43:22 +00006898 /* skip this packet since it is invalid or the socket is closing */
6899 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006900 return;
6901
6902 /* sample on all syn packets or once every atr sample count */
6903 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6904 return;
6905
6906 /* reset sample count */
6907 ring->atr_count = 0;
6908
6909 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6910
6911 /*
6912 * src and dst are inverted, think how the receiver sees them
6913 *
6914 * The input is broken into two sections, a non-compressed section
6915 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6916 * is XORed together and stored in the compressed dword.
6917 */
6918 input.formatted.vlan_id = vlan_id;
6919
6920 /*
6921 * since src port and flex bytes occupy the same word XOR them together
6922 * and write the value to source port portion of compressed dword
6923 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006924 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006925 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6926 else
6927 common.port.src ^= th->dest ^ protocol;
6928 common.port.dst ^= th->source;
6929
6930 if (protocol == __constant_htons(ETH_P_IP)) {
6931 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6932 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6933 } else {
6934 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6935 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6936 hdr.ipv6->saddr.s6_addr32[1] ^
6937 hdr.ipv6->saddr.s6_addr32[2] ^
6938 hdr.ipv6->saddr.s6_addr32[3] ^
6939 hdr.ipv6->daddr.s6_addr32[0] ^
6940 hdr.ipv6->daddr.s6_addr32[1] ^
6941 hdr.ipv6->daddr.s6_addr32[2] ^
6942 hdr.ipv6->daddr.s6_addr32[3];
6943 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006944
6945 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006946 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6947 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006948}
6949
Alexander Duyck63544e92011-05-27 05:31:42 +00006950static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006951{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006952 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006953 /* Herbert's original patch had:
6954 * smp_mb__after_netif_stop_queue();
6955 * but since that doesn't exist yet, just open code it. */
6956 smp_mb();
6957
6958 /* We need to check again in a case another CPU has just
6959 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006960 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006961 return -EBUSY;
6962
6963 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006964 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006965 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006966 return 0;
6967}
6968
Alexander Duyck82d4e462011-06-11 01:44:58 +00006969static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006970{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006971 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006972 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006973 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006974}
6975
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006976static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6977{
6978 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006979 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6980 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006981#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006982 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006983
John Fastabende5b64632011-03-08 03:44:52 +00006984 if (((protocol == htons(ETH_P_FCOE)) ||
6985 (protocol == htons(ETH_P_FIP))) &&
6986 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6987 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6988 txq += adapter->ring_feature[RING_F_FCOE].mask;
6989 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006990 }
6991#endif
6992
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006993 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6994 while (unlikely(txq >= dev->real_num_tx_queues))
6995 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006996 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006997 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006998
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006999 return skb_tx_hash(dev, skb);
7000}
7001
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007002netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00007003 struct ixgbe_adapter *adapter,
7004 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07007005{
Alexander Duyckd3d00232011-07-15 02:31:25 +00007006 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00007007 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00007008 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00007009#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7010 unsigned short f;
7011#endif
Alexander Duycka535c302011-05-27 05:31:52 +00007012 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00007013 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007014 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007015
Alexander Duycka535c302011-05-27 05:31:52 +00007016 /*
7017 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007018 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007019 * + 2 desc gap to keep tail from touching head,
7020 * + 1 desc for context descriptor,
7021 * otherwise try next time
7022 */
7023#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7024 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7025 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7026#else
7027 count += skb_shinfo(skb)->nr_frags;
7028#endif
7029 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7030 tx_ring->tx_stats.tx_busy++;
7031 return NETDEV_TX_BUSY;
7032 }
7033
Alexander Duyck66f32a82011-06-29 05:43:22 +00007034 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007035 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007036 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7037 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7038 /* else if it is a SW VLAN check the next protocol and store the tag */
7039 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7040 struct vlan_hdr *vhdr, _vhdr;
7041 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7042 if (!vhdr)
7043 goto out_drop;
7044
7045 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007046 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7047 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007048 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007049 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007050
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007051#ifdef CONFIG_PCI_IOV
7052 /*
7053 * Use the l2switch_enable flag - would be false if the DMA
7054 * Tx switch had been disabled.
7055 */
7056 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7057 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7058
7059#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007060 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007061 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007062 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7063 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007064 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007065 tx_flags |= (skb->priority & 0x7) <<
7066 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007067 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7068 struct vlan_ethhdr *vhdr;
7069 if (skb_header_cloned(skb) &&
7070 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7071 goto out_drop;
7072 vhdr = (struct vlan_ethhdr *)skb->data;
7073 vhdr->h_vlan_TCI = htons(tx_flags >>
7074 IXGBE_TX_FLAGS_VLAN_SHIFT);
7075 } else {
7076 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7077 }
7078 }
Alexander Duycka535c302011-05-27 05:31:52 +00007079
Alexander Duycka535c302011-05-27 05:31:52 +00007080 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007081 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007082
Yi Zoueacd73f2009-05-13 13:11:06 +00007083#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007084 /* setup tx offload for FCoE */
7085 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7086 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007087 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7088 if (tso < 0)
7089 goto out_drop;
7090 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007091 tx_flags |= IXGBE_TX_FLAGS_FSO |
7092 IXGBE_TX_FLAGS_FCOE;
7093 else
7094 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007095
Alexander Duyck66f32a82011-06-29 05:43:22 +00007096 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007097 }
Auke Kok9a799d72007-09-15 14:07:45 -07007098
Auke Kok9a799d72007-09-15 14:07:45 -07007099#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007100 /* setup IPv4/IPv6 offloads */
7101 if (protocol == __constant_htons(ETH_P_IP))
7102 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007103
Alexander Duyck66f32a82011-06-29 05:43:22 +00007104 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7105 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007106 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007107 else if (tso)
7108 tx_flags |= IXGBE_TX_FLAGS_TSO;
7109 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7110 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7111
7112 /* add the ATR filter if ATR is on */
7113 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7114 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7115
7116#ifdef IXGBE_FCOE
7117xmit_fcoe:
7118#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007119 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7120
7121 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007122
7123 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007124
7125out_drop:
7126 dev_kfree_skb_any(skb);
7127 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007128}
7129
7130static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7131{
7132 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7133 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007134
Auke Kok9a799d72007-09-15 14:07:45 -07007135 tx_ring = adapter->tx_ring[skb->queue_mapping];
7136 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7137}
7138
7139/**
7140 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007141 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007142 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007143 *
Auke Kok9a799d72007-09-15 14:07:45 -07007144 * Returns 0 on success, negative on failure
7145 **/
7146static int ixgbe_set_mac(struct net_device *netdev, void *p)
7147{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007148 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7149 struct ixgbe_hw *hw = &adapter->hw;
7150 struct sockaddr *addr = p;
7151
7152 if (!is_valid_ether_addr(addr->sa_data))
7153 return -EADDRNOTAVAIL;
7154
7155 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7156 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7157
7158 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7159 IXGBE_RAH_AV);
7160
7161 return 0;
7162}
7163
7164static int
7165ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7166{
7167 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7168 struct ixgbe_hw *hw = &adapter->hw;
7169 u16 value;
7170 int rc;
7171
7172 if (prtad != hw->phy.mdio.prtad)
7173 return -EINVAL;
7174 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7175 if (!rc)
7176 rc = value;
7177 return rc;
7178}
7179
7180static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7181 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007182{
7183 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007184 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007185
7186 if (prtad != hw->phy.mdio.prtad)
7187 return -EINVAL;
7188 return hw->phy.ops.write_reg(hw, addr, devad, value);
7189}
7190
7191static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7192{
7193 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7194
7195 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7196}
7197
7198/**
7199 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7200 * netdev->dev_addrs
7201 * @netdev: network interface device structure
7202 *
7203 * Returns non-zero on failure
7204 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007205static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007206{
7207 int err = 0;
7208 struct ixgbe_adapter *adapter = netdev_priv(dev);
7209 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7210
7211 if (is_valid_ether_addr(mac->san_addr)) {
7212 rtnl_lock();
7213 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7214 rtnl_unlock();
7215 }
7216 return err;
7217}
7218
7219/**
7220 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7221 * netdev->dev_addrs
7222 * @netdev: network interface device structure
7223 *
Auke Kok9a799d72007-09-15 14:07:45 -07007224 * Returns non-zero on failure
7225 **/
7226static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7227{
7228 int err = 0;
7229 struct ixgbe_adapter *adapter = netdev_priv(dev);
7230 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7231
7232 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007233 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007234 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007235 rtnl_unlock();
7236 }
7237 return err;
7238}
Auke Kok9a799d72007-09-15 14:07:45 -07007239
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007240#ifdef CONFIG_NET_POLL_CONTROLLER
7241/*
7242 * Polling 'interrupt' - used by things like netconsole to send skbs
7243 * without having to re-enable interrupts. It's not called while
7244 * the interrupt routine is executing.
7245 */
7246static void ixgbe_netpoll(struct net_device *netdev)
7247{
7248 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007249 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007250
7251 /* if interface is down do nothing */
7252 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007253 return;
7254
7255 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007256 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007257 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007258 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007259 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007260 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007261 }
7262 } else {
7263 ixgbe_intr(adapter->pdev->irq, netdev);
7264 }
7265 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7266}
7267#endif
7268
Eric Dumazetde1036b2010-10-20 23:00:04 +00007269static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7270 struct rtnl_link_stats64 *stats)
7271{
7272 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7273 int i;
7274
Eric Dumazet1a515022010-11-16 19:26:42 -08007275 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007276 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007277 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007278 u64 bytes, packets;
7279 unsigned int start;
7280
Eric Dumazet1a515022010-11-16 19:26:42 -08007281 if (ring) {
7282 do {
7283 start = u64_stats_fetch_begin_bh(&ring->syncp);
7284 packets = ring->stats.packets;
7285 bytes = ring->stats.bytes;
7286 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7287 stats->rx_packets += packets;
7288 stats->rx_bytes += bytes;
7289 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007290 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007291
7292 for (i = 0; i < adapter->num_tx_queues; i++) {
7293 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7294 u64 bytes, packets;
7295 unsigned int start;
7296
7297 if (ring) {
7298 do {
7299 start = u64_stats_fetch_begin_bh(&ring->syncp);
7300 packets = ring->stats.packets;
7301 bytes = ring->stats.bytes;
7302 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7303 stats->tx_packets += packets;
7304 stats->tx_bytes += bytes;
7305 }
7306 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007307 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007308 /* following stats updated by ixgbe_watchdog_task() */
7309 stats->multicast = netdev->stats.multicast;
7310 stats->rx_errors = netdev->stats.rx_errors;
7311 stats->rx_length_errors = netdev->stats.rx_length_errors;
7312 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7313 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7314 return stats;
7315}
7316
John Fastabend8b1c0b22011-05-03 02:26:48 +00007317/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7318 * #adapter: pointer to ixgbe_adapter
7319 * @tc: number of traffic classes currently enabled
7320 *
7321 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7322 * 802.1Q priority maps to a packet buffer that exists.
7323 */
7324static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7325{
7326 struct ixgbe_hw *hw = &adapter->hw;
7327 u32 reg, rsave;
7328 int i;
7329
7330 /* 82598 have a static priority to TC mapping that can not
7331 * be changed so no validation is needed.
7332 */
7333 if (hw->mac.type == ixgbe_mac_82598EB)
7334 return;
7335
7336 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7337 rsave = reg;
7338
7339 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7340 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7341
7342 /* If up2tc is out of bounds default to zero */
7343 if (up2tc > tc)
7344 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7345 }
7346
7347 if (reg != rsave)
7348 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7349
7350 return;
7351}
7352
7353
7354/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7355 * classes.
7356 *
7357 * @netdev: net device to configure
7358 * @tc: number of traffic classes to enable
7359 */
7360int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7361{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007362 struct ixgbe_adapter *adapter = netdev_priv(dev);
7363 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007364
John Fastabende7589ea2011-07-18 22:38:36 +00007365 /* Multiple traffic classes requires multiple queues */
7366 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7367 e_err(drv, "Enable failed, needs MSI-X\n");
7368 return -EINVAL;
7369 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007370
7371 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007372 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007373 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7374 return -EINVAL;
7375
7376 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007377 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007378 * hardware is not flexible enough to do this dynamically.
7379 */
7380 if (netif_running(dev))
7381 ixgbe_close(dev);
7382 ixgbe_clear_interrupt_scheme(adapter);
7383
John Fastabende7589ea2011-07-18 22:38:36 +00007384 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007385 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007386 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7387
7388 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7389 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7390
7391 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7392 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7393 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007394 netdev_reset_tc(dev);
7395
John Fastabende7589ea2011-07-18 22:38:36 +00007396 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7397
7398 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7399 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7400
7401 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7402 adapter->dcb_cfg.pfc_mode_enable = false;
7403 }
7404
John Fastabend8b1c0b22011-05-03 02:26:48 +00007405 ixgbe_init_interrupt_scheme(adapter);
7406 ixgbe_validate_rtr(adapter, tc);
7407 if (netif_running(dev))
7408 ixgbe_open(dev);
7409
7410 return 0;
7411}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007412
Don Skidmore082757a2011-07-21 05:55:00 +00007413void ixgbe_do_reset(struct net_device *netdev)
7414{
7415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7416
7417 if (netif_running(netdev))
7418 ixgbe_reinit_locked(adapter);
7419 else
7420 ixgbe_reset(adapter);
7421}
7422
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007423static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7424 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007425{
7426 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7427
7428#ifdef CONFIG_DCB
7429 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7430 data &= ~NETIF_F_HW_VLAN_RX;
7431#endif
7432
7433 /* return error if RXHASH is being enabled when RSS is not supported */
7434 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7435 data &= ~NETIF_F_RXHASH;
7436
7437 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7438 if (!(data & NETIF_F_RXCSUM))
7439 data &= ~NETIF_F_LRO;
7440
7441 /* Turn off LRO if not RSC capable or invalid ITR settings */
7442 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7443 data &= ~NETIF_F_LRO;
7444 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7445 (adapter->rx_itr_setting != 1 &&
7446 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7447 data &= ~NETIF_F_LRO;
7448 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7449 }
7450
7451 return data;
7452}
7453
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007454static int ixgbe_set_features(struct net_device *netdev,
7455 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007456{
7457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7458 bool need_reset = false;
7459
Don Skidmore082757a2011-07-21 05:55:00 +00007460 /* Make sure RSC matches LRO, reset if change */
7461 if (!!(data & NETIF_F_LRO) !=
7462 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7463 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7464 switch (adapter->hw.mac.type) {
7465 case ixgbe_mac_X540:
7466 case ixgbe_mac_82599EB:
7467 need_reset = true;
7468 break;
7469 default:
7470 break;
7471 }
7472 }
7473
7474 /*
7475 * Check if Flow Director n-tuple support was enabled or disabled. If
7476 * the state changed, we need to reset.
7477 */
7478 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7479 /* turn off ATR, enable perfect filters and reset */
7480 if (data & NETIF_F_NTUPLE) {
7481 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7482 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7483 need_reset = true;
7484 }
7485 } else if (!(data & NETIF_F_NTUPLE)) {
7486 /* turn off Flow Director, set ATR and reset */
7487 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7488 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7489 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7490 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7491 need_reset = true;
7492 }
7493
7494 if (need_reset)
7495 ixgbe_do_reset(netdev);
7496
7497 return 0;
7498
7499}
7500
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007501static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007502 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007503 .ndo_stop = ixgbe_close,
7504 .ndo_start_xmit = ixgbe_xmit_frame,
7505 .ndo_select_queue = ixgbe_select_queue,
7506 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007507 .ndo_validate_addr = eth_validate_addr,
7508 .ndo_set_mac_address = ixgbe_set_mac,
7509 .ndo_change_mtu = ixgbe_change_mtu,
7510 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007511 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7512 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007513 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007514 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7515 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7516 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007517 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007518 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007519 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007520 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007521#ifdef CONFIG_NET_POLL_CONTROLLER
7522 .ndo_poll_controller = ixgbe_netpoll,
7523#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007524#ifdef IXGBE_FCOE
7525 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007526 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007527 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007528 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7529 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007530 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007531 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007532#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007533 .ndo_set_features = ixgbe_set_features,
7534 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007535};
7536
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007537static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7538 const struct ixgbe_info *ii)
7539{
7540#ifdef CONFIG_PCI_IOV
7541 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007542
Greg Rosec6bda302011-08-24 02:37:55 +00007543 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007544 return;
7545
7546 /* The 82599 supports up to 64 VFs per physical function
7547 * but this implementation limits allocation to 63 so that
7548 * basic networking resources are still available to the
7549 * physical function
7550 */
7551 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007552 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007553#endif /* CONFIG_PCI_IOV */
7554}
7555
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007556/**
Auke Kok9a799d72007-09-15 14:07:45 -07007557 * ixgbe_probe - Device Initialization Routine
7558 * @pdev: PCI device information struct
7559 * @ent: entry in ixgbe_pci_tbl
7560 *
7561 * Returns 0 on success, negative on failure
7562 *
7563 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7564 * The OS initialization, configuring of the adapter private structure,
7565 * and a hardware reset occur.
7566 **/
7567static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007568 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007569{
7570 struct net_device *netdev;
7571 struct ixgbe_adapter *adapter = NULL;
7572 struct ixgbe_hw *hw;
7573 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007574 static int cards_found;
7575 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007576 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007577 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007578#ifdef IXGBE_FCOE
7579 u16 device_caps;
7580#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007581 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007582 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007583
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007584 /* Catch broken hardware that put the wrong VF device ID in
7585 * the PCIe SR-IOV capability.
7586 */
7587 if (pdev->is_virtfn) {
7588 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7589 pci_name(pdev), pdev->vendor, pdev->device);
7590 return -EINVAL;
7591 }
7592
gouji-new9ce77662009-05-06 10:44:45 +00007593 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007594 if (err)
7595 return err;
7596
Nick Nunley1b507732010-04-27 13:10:27 +00007597 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7598 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007599 pci_using_dac = 1;
7600 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007601 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007602 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007603 err = dma_set_coherent_mask(&pdev->dev,
7604 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007605 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007606 dev_err(&pdev->dev,
7607 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007608 goto err_dma;
7609 }
7610 }
7611 pci_using_dac = 0;
7612 }
7613
gouji-new9ce77662009-05-06 10:44:45 +00007614 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007615 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007616 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007617 dev_err(&pdev->dev,
7618 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007619 goto err_pci_reg;
7620 }
7621
Frans Pop19d5afd2009-10-02 10:04:12 -07007622 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007623
Auke Kok9a799d72007-09-15 14:07:45 -07007624 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007625 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007626
John Fastabende901acd2011-04-26 07:26:08 +00007627#ifdef CONFIG_IXGBE_DCB
7628 indices *= MAX_TRAFFIC_CLASS;
7629#endif
7630
John Fastabendc85a2612010-02-25 23:15:21 +00007631 if (ii->mac == ixgbe_mac_82598EB)
7632 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7633 else
7634 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7635
John Fastabende901acd2011-04-26 07:26:08 +00007636#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007637 indices += min_t(unsigned int, num_possible_cpus(),
7638 IXGBE_MAX_FCOE_INDICES);
7639#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007640 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007641 if (!netdev) {
7642 err = -ENOMEM;
7643 goto err_alloc_etherdev;
7644 }
7645
Auke Kok9a799d72007-09-15 14:07:45 -07007646 SET_NETDEV_DEV(netdev, &pdev->dev);
7647
Auke Kok9a799d72007-09-15 14:07:45 -07007648 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007649 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007650
7651 adapter->netdev = netdev;
7652 adapter->pdev = pdev;
7653 hw = &adapter->hw;
7654 hw->back = adapter;
7655 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7656
Jeff Kirsher05857982008-09-11 19:57:00 -07007657 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007658 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007659 if (!hw->hw_addr) {
7660 err = -EIO;
7661 goto err_ioremap;
7662 }
7663
7664 for (i = 1; i <= 5; i++) {
7665 if (pci_resource_len(pdev, i) == 0)
7666 continue;
7667 }
7668
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007669 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007670 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007671 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007672 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007673
Auke Kok9a799d72007-09-15 14:07:45 -07007674 adapter->bd_number = cards_found;
7675
Auke Kok9a799d72007-09-15 14:07:45 -07007676 /* Setup hw api */
7677 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007678 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007679
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007680 /* EEPROM */
7681 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7682 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7683 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7684 if (!(eec & (1 << 8)))
7685 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7686
7687 /* PHY */
7688 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007689 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007690 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7691 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7692 hw->phy.mdio.mmds = 0;
7693 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7694 hw->phy.mdio.dev = netdev;
7695 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7696 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007697
Don Skidmore8ca783a2009-05-26 20:40:47 -07007698 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007699
7700 /* setup the private structure */
7701 err = ixgbe_sw_init(adapter);
7702 if (err)
7703 goto err_sw_init;
7704
Don Skidmoree86bff02010-02-11 04:14:08 +00007705 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007706 switch (adapter->hw.mac.type) {
7707 case ixgbe_mac_82599EB:
7708 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007709 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007710 break;
7711 default:
7712 break;
7713 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007714
Don Skidmorebf069c92009-05-07 10:39:54 +00007715 /*
7716 * If there is a fan on this device and it has failed log the
7717 * failure.
7718 */
7719 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7720 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7721 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007722 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007723 }
7724
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007725 if (allow_unsupported_sfp)
7726 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7727
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007728 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007729 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007730 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007731 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007732 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7733 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007734 err = 0;
7735 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007736 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007737 "module type was detected.\n");
7738 e_dev_err("Reload the driver after installing a supported "
7739 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007740 goto err_sw_init;
7741 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007742 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007743 goto err_sw_init;
7744 }
7745
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007746 ixgbe_probe_vf(adapter, ii);
7747
Emil Tantilov396e7992010-07-01 20:05:12 +00007748 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007749 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007750 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007751 NETIF_F_HW_VLAN_TX |
7752 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007753 NETIF_F_HW_VLAN_FILTER |
7754 NETIF_F_TSO |
7755 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007756 NETIF_F_RXHASH |
7757 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007758
Don Skidmore082757a2011-07-21 05:55:00 +00007759 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007760
Don Skidmore58be7662011-04-12 09:42:11 +00007761 switch (adapter->hw.mac.type) {
7762 case ixgbe_mac_82599EB:
7763 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007764 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007765 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7766 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007767 break;
7768 default:
7769 break;
7770 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007771
Jeff Kirsherad31c402008-06-05 04:05:30 -07007772 netdev->vlan_features |= NETIF_F_TSO;
7773 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007774 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007775 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007776 netdev->vlan_features |= NETIF_F_SG;
7777
Jiri Pirko01789342011-08-16 06:29:00 +00007778 netdev->priv_flags |= IFF_UNICAST_FLT;
7779
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007780 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7781 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7782 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007783
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007784#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007785 netdev->dcbnl_ops = &dcbnl_ops;
7786#endif
7787
Yi Zoueacd73f2009-05-13 13:11:06 +00007788#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007789 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007790 if (hw->mac.ops.get_device_caps) {
7791 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007792 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7793 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007794 }
7795 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007796 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7797 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7798 netdev->vlan_features |= NETIF_F_FSO;
7799 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7800 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007801#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007802 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007803 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007804 netdev->vlan_features |= NETIF_F_HIGHDMA;
7805 }
Auke Kok9a799d72007-09-15 14:07:45 -07007806
Don Skidmore082757a2011-07-21 05:55:00 +00007807 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7808 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007809 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007810 netdev->features |= NETIF_F_LRO;
7811
Auke Kok9a799d72007-09-15 14:07:45 -07007812 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007813 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007814 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007815 err = -EIO;
7816 goto err_eeprom;
7817 }
7818
7819 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7820 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7821
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007822 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007823 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007824 err = -EIO;
7825 goto err_eeprom;
7826 }
7827
Alexander Duyck70864002011-04-27 09:13:56 +00007828 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7829 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007830
Alexander Duyck70864002011-04-27 09:13:56 +00007831 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7832 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007833
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007834 err = ixgbe_init_interrupt_scheme(adapter);
7835 if (err)
7836 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007837
Don Skidmore082757a2011-07-21 05:55:00 +00007838 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7839 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007840 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007841 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007842
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007843 /* WOL not supported for all but the following */
7844 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007845 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007846 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007847 /* Only these subdevice supports WOL */
7848 switch (pdev->subsystem_device) {
7849 case IXGBE_SUBDEV_ID_82599_560FLR:
7850 /* only support first port */
7851 if (hw->bus.func != 0)
7852 break;
7853 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007854 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007855 break;
7856 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007857 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007858 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7859 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007860 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007861 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007862 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007863 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007864 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007865 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007866 case IXGBE_DEV_ID_X540T:
7867 /* Check eeprom to see if it is enabled */
7868 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7869 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7870
7871 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7872 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7873 (hw->bus.func == 0)))
7874 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007875 break;
7876 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007877 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7878
Emil Tantilov15e52092011-09-29 05:01:29 +00007879 /* save off EEPROM version number */
7880 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7881 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7882
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007883 /* pick up the PCI bus settings for reporting later */
7884 hw->mac.ops.get_bus_info(hw);
7885
Auke Kok9a799d72007-09-15 14:07:45 -07007886 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007887 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007888 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7889 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007890 "Unknown"),
7891 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7892 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7893 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7894 "Unknown"),
7895 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007896
7897 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7898 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007899 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007900 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007901 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007902 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007903 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007904 else
Don Skidmore289700db2010-12-03 03:32:58 +00007905 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7906 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007907
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007908 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007909 e_dev_warn("PCI-Express bandwidth available for this card is "
7910 "not sufficient for optimal performance.\n");
7911 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7912 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007913 }
7914
Auke Kok9a799d72007-09-15 14:07:45 -07007915 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007916 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007917
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007918 if (err == IXGBE_ERR_EEPROM_VERSION) {
7919 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007920 e_dev_warn("This device is a pre-production adapter/LOM. "
7921 "Please be aware there may be issues associated "
7922 "with your hardware. If you are experiencing "
7923 "problems please contact your Intel or hardware "
7924 "representative who provided you with this "
7925 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007926 }
Auke Kok9a799d72007-09-15 14:07:45 -07007927 strcpy(netdev->name, "eth%d");
7928 err = register_netdev(netdev);
7929 if (err)
7930 goto err_register;
7931
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007932 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7933 if (hw->mac.ops.disable_tx_laser &&
7934 ((hw->phy.multispeed_fiber) ||
7935 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7936 (hw->mac.type == ixgbe_mac_82599EB))))
7937 hw->mac.ops.disable_tx_laser(hw);
7938
Jesse Brandeburg54386462009-04-17 20:44:27 +00007939 /* carrier off reporting is important to ethtool even BEFORE open */
7940 netif_carrier_off(netdev);
7941
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007942#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007943 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007944 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007945 ixgbe_setup_dca(adapter);
7946 }
7947#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007948 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007949 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007950 for (i = 0; i < adapter->num_vfs; i++)
7951 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7952 }
7953
Jacob Keller2466dd92011-09-08 03:50:54 +00007954 /* firmware requires driver version to be 0xFFFFFFFF
7955 * since os does not support feature
7956 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007957 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007958 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7959 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007960
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007961 /* add san mac addr to netdev */
7962 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007963
Neerav Parikhea818752012-01-04 20:23:40 +00007964 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007965 cards_found++;
7966 return 0;
7967
7968err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007969 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007970 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007971err_sw_init:
7972err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007973 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7974 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007975 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007976 iounmap(hw->hw_addr);
7977err_ioremap:
7978 free_netdev(netdev);
7979err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007980 pci_release_selected_regions(pdev,
7981 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007982err_pci_reg:
7983err_dma:
7984 pci_disable_device(pdev);
7985 return err;
7986}
7987
7988/**
7989 * ixgbe_remove - Device Removal Routine
7990 * @pdev: PCI device information struct
7991 *
7992 * ixgbe_remove is called by the PCI subsystem to alert the driver
7993 * that it should release a PCI device. The could be caused by a
7994 * Hot-Plug event, or because the driver is going to be removed from
7995 * memory.
7996 **/
7997static void __devexit ixgbe_remove(struct pci_dev *pdev)
7998{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007999 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8000 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008001
8002 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00008003 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07008004
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008005#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008006 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
8007 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
8008 dca_remove_requester(&pdev->dev);
8009 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
8010 }
8011
8012#endif
Yi Zou332d4a72009-05-13 13:11:53 +00008013#ifdef IXGBE_FCOE
8014 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8015 ixgbe_cleanup_fcoe(adapter);
8016
8017#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008018
8019 /* remove the added san mac */
8020 ixgbe_del_sanmac_netdev(netdev);
8021
Donald Skidmorec4900be2008-11-20 21:11:42 -08008022 if (netdev->reg_state == NETREG_REGISTERED)
8023 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008024
Greg Rosec6bda302011-08-24 02:37:55 +00008025 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8026 if (!(ixgbe_check_vf_assignment(adapter)))
8027 ixgbe_disable_sriov(adapter);
8028 else
8029 e_dev_warn("Unloading driver while VFs are assigned "
8030 "- VFs will not be deallocated\n");
8031 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008032
Alexander Duyck7a921c92009-05-06 10:43:28 +00008033 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008034
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008035 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008036
8037 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008038 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008039 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008040
Emil Tantilov849c4542010-06-03 16:53:41 +00008041 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008042
Auke Kok9a799d72007-09-15 14:07:45 -07008043 free_netdev(netdev);
8044
Frans Pop19d5afd2009-10-02 10:04:12 -07008045 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008046
Auke Kok9a799d72007-09-15 14:07:45 -07008047 pci_disable_device(pdev);
8048}
8049
8050/**
8051 * ixgbe_io_error_detected - called when PCI error is detected
8052 * @pdev: Pointer to PCI device
8053 * @state: The current pci connection state
8054 *
8055 * This function is called after a PCI bus error affecting
8056 * this device has been detected.
8057 */
8058static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008059 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008060{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008061 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8062 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008063
Greg Rose83c61fa2011-09-07 05:59:35 +00008064#ifdef CONFIG_PCI_IOV
8065 struct pci_dev *bdev, *vfdev;
8066 u32 dw0, dw1, dw2, dw3;
8067 int vf, pos;
8068 u16 req_id, pf_func;
8069
8070 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8071 adapter->num_vfs == 0)
8072 goto skip_bad_vf_detection;
8073
8074 bdev = pdev->bus->self;
8075 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8076 bdev = bdev->bus->self;
8077
8078 if (!bdev)
8079 goto skip_bad_vf_detection;
8080
8081 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8082 if (!pos)
8083 goto skip_bad_vf_detection;
8084
8085 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8086 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8087 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8088 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8089
8090 req_id = dw1 >> 16;
8091 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8092 if (!(req_id & 0x0080))
8093 goto skip_bad_vf_detection;
8094
8095 pf_func = req_id & 0x01;
8096 if ((pf_func & 1) == (pdev->devfn & 1)) {
8097 unsigned int device_id;
8098
8099 vf = (req_id & 0x7F) >> 1;
8100 e_dev_err("VF %d has caused a PCIe error\n", vf);
8101 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8102 "%8.8x\tdw3: %8.8x\n",
8103 dw0, dw1, dw2, dw3);
8104 switch (adapter->hw.mac.type) {
8105 case ixgbe_mac_82599EB:
8106 device_id = IXGBE_82599_VF_DEVICE_ID;
8107 break;
8108 case ixgbe_mac_X540:
8109 device_id = IXGBE_X540_VF_DEVICE_ID;
8110 break;
8111 default:
8112 device_id = 0;
8113 break;
8114 }
8115
8116 /* Find the pci device of the offending VF */
8117 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8118 while (vfdev) {
8119 if (vfdev->devfn == (req_id & 0xFF))
8120 break;
8121 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8122 device_id, vfdev);
8123 }
8124 /*
8125 * There's a slim chance the VF could have been hot plugged,
8126 * so if it is no longer present we don't need to issue the
8127 * VFLR. Just clean up the AER in that case.
8128 */
8129 if (vfdev) {
8130 e_dev_err("Issuing VFLR to VF %d\n", vf);
8131 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8132 }
8133
8134 pci_cleanup_aer_uncorrect_error_status(pdev);
8135 }
8136
8137 /*
8138 * Even though the error may have occurred on the other port
8139 * we still need to increment the vf error reference count for
8140 * both ports because the I/O resume function will be called
8141 * for both of them.
8142 */
8143 adapter->vferr_refcount++;
8144
8145 return PCI_ERS_RESULT_RECOVERED;
8146
8147skip_bad_vf_detection:
8148#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008149 netif_device_detach(netdev);
8150
Breno Leitao3044b8d2009-05-06 10:44:26 +00008151 if (state == pci_channel_io_perm_failure)
8152 return PCI_ERS_RESULT_DISCONNECT;
8153
Auke Kok9a799d72007-09-15 14:07:45 -07008154 if (netif_running(netdev))
8155 ixgbe_down(adapter);
8156 pci_disable_device(pdev);
8157
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008158 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008159 return PCI_ERS_RESULT_NEED_RESET;
8160}
8161
8162/**
8163 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8164 * @pdev: Pointer to PCI device
8165 *
8166 * Restart the card from scratch, as if from a cold-boot.
8167 */
8168static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8169{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008170 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008171 pci_ers_result_t result;
8172 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008173
gouji-new9ce77662009-05-06 10:44:45 +00008174 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008175 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008176 result = PCI_ERS_RESULT_DISCONNECT;
8177 } else {
8178 pci_set_master(pdev);
8179 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008180 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008181
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008182 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008183
8184 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008185 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008186 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008187 }
Auke Kok9a799d72007-09-15 14:07:45 -07008188
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008189 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8190 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008191 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8192 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008193 /* non-fatal, continue */
8194 }
Auke Kok9a799d72007-09-15 14:07:45 -07008195
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008196 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008197}
8198
8199/**
8200 * ixgbe_io_resume - called when traffic can start flowing again.
8201 * @pdev: Pointer to PCI device
8202 *
8203 * This callback is called when the error recovery driver tells us that
8204 * its OK to resume normal operation.
8205 */
8206static void ixgbe_io_resume(struct pci_dev *pdev)
8207{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008208 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8209 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008210
Greg Rose83c61fa2011-09-07 05:59:35 +00008211#ifdef CONFIG_PCI_IOV
8212 if (adapter->vferr_refcount) {
8213 e_info(drv, "Resuming after VF err\n");
8214 adapter->vferr_refcount--;
8215 return;
8216 }
8217
8218#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008219 if (netif_running(netdev))
8220 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008221
8222 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008223}
8224
8225static struct pci_error_handlers ixgbe_err_handler = {
8226 .error_detected = ixgbe_io_error_detected,
8227 .slot_reset = ixgbe_io_slot_reset,
8228 .resume = ixgbe_io_resume,
8229};
8230
8231static struct pci_driver ixgbe_driver = {
8232 .name = ixgbe_driver_name,
8233 .id_table = ixgbe_pci_tbl,
8234 .probe = ixgbe_probe,
8235 .remove = __devexit_p(ixgbe_remove),
8236#ifdef CONFIG_PM
8237 .suspend = ixgbe_suspend,
8238 .resume = ixgbe_resume,
8239#endif
8240 .shutdown = ixgbe_shutdown,
8241 .err_handler = &ixgbe_err_handler
8242};
8243
8244/**
8245 * ixgbe_init_module - Driver Registration Routine
8246 *
8247 * ixgbe_init_module is the first routine called when the driver is
8248 * loaded. All it does is register with the PCI subsystem.
8249 **/
8250static int __init ixgbe_init_module(void)
8251{
8252 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008253 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008254 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008255
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008256#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008257 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008258#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008259
Auke Kok9a799d72007-09-15 14:07:45 -07008260 ret = pci_register_driver(&ixgbe_driver);
8261 return ret;
8262}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008263
Auke Kok9a799d72007-09-15 14:07:45 -07008264module_init(ixgbe_init_module);
8265
8266/**
8267 * ixgbe_exit_module - Driver Exit Cleanup Routine
8268 *
8269 * ixgbe_exit_module is called just before the driver is removed
8270 * from memory.
8271 **/
8272static void __exit ixgbe_exit_module(void)
8273{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008274#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008275 dca_unregister_notify(&dca_notifier);
8276#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008277 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008278 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008279}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008280
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008281#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008282static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008283 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008284{
8285 int ret_val;
8286
8287 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008288 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008289
8290 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8291}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008292
Alexander Duyckb4533682009-03-31 21:32:42 +00008293#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008294
Auke Kok9a799d72007-09-15 14:07:45 -07008295module_exit(ixgbe_exit_module);
8296
8297/* ixgbe_main.c */