blob: 762f33777a7f08c34bfab7ec13dda69609bc1559 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000369 tx_desc = IXGBE_TX_DESC_ADV(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 Duyck31f05a22010-08-19 13:40:31 +0000450 rx_desc = IXGBE_RX_DESC_ADV(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];
757 tx_desc = IXGBE_TX_DESC_ADV(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
766 /* if DD is not set pending work has not been completed */
767 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
768 break;
769
770 /* count the packet as being completed */
771 tx_ring->tx_stats.completed++;
772
773 /* clear next_to_watch to prevent false hangs */
774 tx_buffer->next_to_watch = NULL;
775
776 /* prevent any other reads prior to eop_desc being verified */
777 rmb();
778
779 do {
780 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800781 tx_desc->wb.status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000782 if (likely(tx_desc == eop_desc)) {
783 eop_desc = NULL;
784 dev_kfree_skb_any(tx_buffer->skb);
785 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800786
Alexander Duyckd3d00232011-07-15 02:31:25 +0000787 total_bytes += tx_buffer->bytecount;
788 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800789 }
790
Alexander Duyckd3d00232011-07-15 02:31:25 +0000791 tx_buffer++;
792 tx_desc++;
793 i++;
794 if (unlikely(i == tx_ring->count)) {
795 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700796
Alexander Duyckd3d00232011-07-15 02:31:25 +0000797 tx_buffer = tx_ring->tx_buffer_info;
798 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
799 }
800
801 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800802 }
803
Auke Kok9a799d72007-09-15 14:07:45 -0700804 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000805 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800806 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000807 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000808 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000809 q_vector->tx.total_bytes += total_bytes;
810 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800811
John Fastabendc84d3242010-11-16 19:27:12 -0800812 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800813 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800814 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000815 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800816 e_err(drv, "Detected Tx Unit Hang\n"
817 " Tx Queue <%d>\n"
818 " TDH, TDT <%x>, <%x>\n"
819 " next_to_use <%x>\n"
820 " next_to_clean <%x>\n"
821 "tx_buffer_info[next_to_clean]\n"
822 " time_stamp <%lx>\n"
823 " jiffies <%lx>\n",
824 tx_ring->queue_index,
825 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
826 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000827 tx_ring->next_to_use, i,
828 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800829
830 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
831
832 e_info(probe,
833 "tx hang %d detected on queue %d, resetting adapter\n",
834 adapter->tx_timeout_count + 1, tx_ring->queue_index);
835
836 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000837 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800838
839 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000840 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800841 }
Auke Kok9a799d72007-09-15 14:07:45 -0700842
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800843#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000844 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000845 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800846 /* Make sure that anybody stopping the queue after this
847 * sees the new next_to_clean.
848 */
849 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800850 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800851 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800852 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800853 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800854 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800855 }
Auke Kok9a799d72007-09-15 14:07:45 -0700856
Alexander Duyck59224552011-08-31 00:01:06 +0000857 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700858}
859
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400860#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800861static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800862 struct ixgbe_ring *rx_ring,
863 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800864{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800865 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800866 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800867 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800868
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800869 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
870 switch (hw->mac.type) {
871 case ixgbe_mac_82598EB:
872 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000873 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
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 Duyck33cf09c2010-11-16 19:26:55 -0800877 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000878 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800879 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
880 break;
881 default:
882 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800883 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800884 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
885 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
886 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800887 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800888}
889
890static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800891 struct ixgbe_ring *tx_ring,
892 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800893{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000894 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800895 u32 txctrl;
896 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800897
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800898 switch (hw->mac.type) {
899 case ixgbe_mac_82598EB:
900 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
901 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000902 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800903 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800904 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
905 break;
906 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800907 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800908 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
909 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000910 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800911 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
912 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800913 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
914 break;
915 default:
916 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800917 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800918}
919
920static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
921{
922 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000923 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800924 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925
926 if (q_vector->cpu == cpu)
927 goto out_no_update;
928
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000929 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
930 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000932 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
933 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800934
935 q_vector->cpu = cpu;
936out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800937 put_cpu();
938}
939
940static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
941{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800942 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800943 int i;
944
945 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
946 return;
947
Alexander Duycke35ec122009-05-21 13:07:12 +0000948 /* always use CB2 mode, difference is masked in the CB driver */
949 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
950
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800951 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
952 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
953 else
954 num_q_vectors = 1;
955
956 for (i = 0; i < num_q_vectors; i++) {
957 adapter->q_vector[i]->cpu = -1;
958 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800959 }
960}
961
962static int __ixgbe_notify_dca(struct device *dev, void *data)
963{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800964 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800965 unsigned long event = *(unsigned long *)data;
966
Don Skidmore2a72c312011-07-20 02:27:05 +0000967 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 return 0;
969
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800970 switch (event) {
971 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700972 /* if we're already enabled, don't do it again */
973 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
974 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300975 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700976 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977 ixgbe_setup_dca(adapter);
978 break;
979 }
980 /* Fall Through since DCA is disabled. */
981 case DCA_PROVIDER_REMOVE:
982 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
983 dca_remove_requester(dev);
984 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
985 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
986 }
987 break;
988 }
989
Denis V. Lunev652f0932008-03-27 14:39:17 +0300990 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800991}
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400992#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000993
994static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
995 struct sk_buff *skb)
996{
997 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
998}
999
Auke Kok9a799d72007-09-15 14:07:45 -07001000/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001001 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1002 * @adapter: address of board private structure
1003 * @rx_desc: advanced rx descriptor
1004 *
1005 * Returns : true if it is FCoE pkt
1006 */
1007static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1008 union ixgbe_adv_rx_desc *rx_desc)
1009{
1010 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1011
1012 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1013 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1014 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1015 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1016}
1017
1018/**
Auke Kok9a799d72007-09-15 14:07:45 -07001019 * ixgbe_receive_skb - Send a completed packet up the stack
1020 * @adapter: board private structure
1021 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001022 * @status: hardware indication of status of receive
1023 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1024 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001025 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001026static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001027 struct sk_buff *skb, u8 status,
1028 struct ixgbe_ring *ring,
1029 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001030{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001031 struct ixgbe_adapter *adapter = q_vector->adapter;
1032 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001033 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1034 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001035
Jesse Grossf62bbb52010-10-20 13:56:10 +00001036 if (is_vlan && (tag & VLAN_VID_MASK))
1037 __vlan_hwaccel_put_tag(skb, tag);
1038
1039 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1040 napi_gro_receive(napi, skb);
1041 else
1042 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001043}
1044
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001045/**
1046 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1047 * @adapter: address of board private structure
1048 * @status_err: hardware indication of status of receive
1049 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001050 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001051 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001052static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001053 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001054 struct sk_buff *skb,
1055 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001056{
Alexander Duyckff886df2011-06-11 01:45:13 +00001057 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001058
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001059 /* Rx csum disabled */
1060 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001061 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001062
1063 /* if IP and error */
1064 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1065 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001066 adapter->hw_csum_rx_error++;
1067 return;
1068 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001069
1070 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1071 return;
1072
1073 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001074 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1075
1076 /*
1077 * 82599 errata, UDP frames with a 0 checksum can be marked as
1078 * checksum errors.
1079 */
1080 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1081 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1082 return;
1083
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001084 adapter->hw_csum_rx_error++;
1085 return;
1086 }
1087
Auke Kok9a799d72007-09-15 14:07:45 -07001088 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001089 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001090}
1091
Alexander Duyck84ea2592010-11-16 19:26:49 -08001092static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001093{
1094 /*
1095 * Force memory writes to complete before letting h/w
1096 * know there are new descriptors to fetch. (Only
1097 * applicable for weak-ordered memory model archs,
1098 * such as IA-64).
1099 */
1100 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001101 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001102}
1103
Auke Kok9a799d72007-09-15 14:07:45 -07001104/**
1105 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001106 * @rx_ring: ring to place buffers on
1107 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001108 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001109void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001110{
Auke Kok9a799d72007-09-15 14:07:45 -07001111 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001112 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001113 struct sk_buff *skb;
1114 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001115
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001116 /* do nothing if no valid netdev defined */
1117 if (!rx_ring->netdev)
1118 return;
1119
Auke Kok9a799d72007-09-15 14:07:45 -07001120 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001121 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001122 bi = &rx_ring->rx_buffer_info[i];
1123 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001124
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001125 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001126 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001127 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001128 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001129 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001130 goto no_buffers;
1131 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001132 /* initialize queue mapping */
1133 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001134 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001135 }
Auke Kok9a799d72007-09-15 14:07:45 -07001136
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001137 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001138 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001139 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001140 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001141 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001142 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001143 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001144 bi->dma = 0;
1145 goto no_buffers;
1146 }
Auke Kok9a799d72007-09-15 14:07:45 -07001147 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001148
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001149 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001150 if (!bi->page) {
Eric Dumazet1f2149c2011-11-22 10:57:41 +00001151 bi->page = alloc_page(GFP_ATOMIC | __GFP_COLD);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001152 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001153 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001154 goto no_buffers;
1155 }
1156 }
1157
1158 if (!bi->page_dma) {
1159 /* use a half page if we're re-using */
1160 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001161 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001162 bi->page,
1163 bi->page_offset,
1164 PAGE_SIZE / 2,
1165 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001166 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001167 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001168 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001169 bi->page_dma = 0;
1170 goto no_buffers;
1171 }
1172 }
1173
1174 /* Refresh the desc even if buffer_addrs didn't change
1175 * because each write-back erases this info. */
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001176 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1177 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001178 } else {
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07001179 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001180 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001181 }
1182
1183 i++;
1184 if (i == rx_ring->count)
1185 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001186 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001187
Auke Kok9a799d72007-09-15 14:07:45 -07001188no_buffers:
1189 if (rx_ring->next_to_use != i) {
1190 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001191 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001192 }
1193}
1194
Alexander Duyckc267fc12010-11-16 19:27:00 -08001195static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001196{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001197 /* HW will not DMA in data larger than the given buffer, even if it
1198 * parses the (NFS, of course) header to be larger. In that case, it
1199 * fills the header buffer and spills the rest into the page.
1200 */
1201 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1202 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1203 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1204 if (hlen > IXGBE_RX_HDR_SIZE)
1205 hlen = IXGBE_RX_HDR_SIZE;
1206 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001207}
1208
Alexander Duyckf8212f92009-04-27 22:42:37 +00001209/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001210 * ixgbe_merge_active_tail - merge active tail into lro skb
1211 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001212 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001213 * This function merges the length and data of an active tail into the
1214 * skb containing the frag_list. It resets the tail's pointer to the head,
1215 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001216 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001217static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001218{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001219 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001220
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001221 if (!head)
1222 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001223
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001224 head->len += tail->len;
1225 head->data_len += tail->len;
1226 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001227
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001228 IXGBE_CB(tail)->head = NULL;
1229
1230 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001231}
1232
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001233/**
1234 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1235 * @head: pointer to the start of the skb
1236 * @tail: pointer to active tail to add to frag_list
1237 *
1238 * This function adds an active tail to the end of the frag list. This tail
1239 * will still be receiving data so we cannot yet ad it's stats to the main
1240 * skb. That is done via ixgbe_merge_active_tail.
1241 **/
1242static inline void ixgbe_add_active_tail(struct sk_buff *head,
1243 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001244{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001245 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1246
1247 if (old_tail) {
1248 ixgbe_merge_active_tail(old_tail);
1249 old_tail->next = tail;
1250 } else {
1251 skb_shinfo(head)->frag_list = tail;
1252 }
1253
1254 IXGBE_CB(tail)->head = head;
1255 IXGBE_CB(head)->tail = tail;
1256}
1257
1258/**
1259 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1260 * @head: pointer to head of an active frag list
1261 *
1262 * This function will clear the frag_tail_tracker pointer on an active
1263 * frag_list and returns true if the pointer was actually set
1264 **/
1265static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1266{
1267 struct sk_buff *tail = IXGBE_CB(head)->tail;
1268
1269 if (!tail)
1270 return false;
1271
1272 ixgbe_merge_active_tail(tail);
1273
1274 IXGBE_CB(head)->tail = NULL;
1275
1276 return true;
1277}
1278
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001279/**
1280 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1281 * @data: pointer to the start of the headers
1282 * @max_len: total length of section to find headers in
1283 *
1284 * This function is meant to determine the length of headers that will
1285 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1286 * motivation of doing this is to only perform one pull for IPv4 TCP
1287 * packets so that we can do basic things like calculating the gso_size
1288 * based on the average data per packet.
1289 **/
1290static unsigned int ixgbe_get_headlen(unsigned char *data,
1291 unsigned int max_len)
1292{
1293 union {
1294 unsigned char *network;
1295 /* l2 headers */
1296 struct ethhdr *eth;
1297 struct vlan_hdr *vlan;
1298 /* l3 headers */
1299 struct iphdr *ipv4;
1300 } hdr;
1301 __be16 protocol;
1302 u8 nexthdr = 0; /* default to not TCP */
1303 u8 hlen;
1304
1305 /* this should never happen, but better safe than sorry */
1306 if (max_len < ETH_HLEN)
1307 return max_len;
1308
1309 /* initialize network frame pointer */
1310 hdr.network = data;
1311
1312 /* set first protocol and move network header forward */
1313 protocol = hdr.eth->h_proto;
1314 hdr.network += ETH_HLEN;
1315
1316 /* handle any vlan tag if present */
1317 if (protocol == __constant_htons(ETH_P_8021Q)) {
1318 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1319 return max_len;
1320
1321 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1322 hdr.network += VLAN_HLEN;
1323 }
1324
1325 /* handle L3 protocols */
1326 if (protocol == __constant_htons(ETH_P_IP)) {
1327 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1328 return max_len;
1329
1330 /* access ihl as a u8 to avoid unaligned access on ia64 */
1331 hlen = (hdr.network[0] & 0x0F) << 2;
1332
1333 /* verify hlen meets minimum size requirements */
1334 if (hlen < sizeof(struct iphdr))
1335 return hdr.network - data;
1336
1337 /* record next protocol */
1338 nexthdr = hdr.ipv4->protocol;
1339 hdr.network += hlen;
1340#ifdef CONFIG_FCOE
1341 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1342 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1343 return max_len;
1344 hdr.network += FCOE_HEADER_LEN;
1345#endif
1346 } else {
1347 return hdr.network - data;
1348 }
1349
1350 /* finally sort out TCP */
1351 if (nexthdr == IPPROTO_TCP) {
1352 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1353 return max_len;
1354
1355 /* access doff as a u8 to avoid unaligned access on ia64 */
1356 hlen = (hdr.network[12] & 0xF0) >> 2;
1357
1358 /* verify hlen meets minimum size requirements */
1359 if (hlen < sizeof(struct tcphdr))
1360 return hdr.network - data;
1361
1362 hdr.network += hlen;
1363 }
1364
1365 /*
1366 * If everything has gone correctly hdr.network should be the
1367 * data section of the packet and will be the end of the header.
1368 * If not then it probably represents the end of the last recognized
1369 * header.
1370 */
1371 if ((hdr.network - data) < max_len)
1372 return hdr.network - data;
1373 else
1374 return max_len;
1375}
1376
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001377static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1378 union ixgbe_adv_rx_desc *rx_desc,
1379 struct sk_buff *skb)
1380{
1381 __le32 rsc_enabled;
1382 u32 rsc_cnt;
1383
1384 if (!ring_is_rsc_enabled(rx_ring))
1385 return;
1386
1387 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1388 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1389
1390 /* If this is an RSC frame rsc_cnt should be non-zero */
1391 if (!rsc_enabled)
1392 return;
1393
1394 rsc_cnt = le32_to_cpu(rsc_enabled);
1395 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1396
1397 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001398}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001399
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001400static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1401 struct sk_buff *skb)
1402{
1403 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1404
1405 /* set gso_size to avoid messing up TCP MSS */
1406 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1407 IXGBE_CB(skb)->append_cnt);
1408}
1409
1410static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1411 struct sk_buff *skb)
1412{
1413 /* if append_cnt is 0 then frame is not RSC */
1414 if (!IXGBE_CB(skb)->append_cnt)
1415 return;
1416
1417 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1418 rx_ring->rx_stats.rsc_flush++;
1419
1420 ixgbe_set_rsc_gso_size(rx_ring, skb);
1421
1422 /* gso_size is computed using append_cnt so always clear it last */
1423 IXGBE_CB(skb)->append_cnt = 0;
1424}
1425
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001426static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001427 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001428 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001429{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001430 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001431 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001432 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001433 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001434 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001435 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001436#ifdef IXGBE_FCOE
1437 int ddp_bytes = 0;
1438#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001439 u32 staterr;
1440 u16 i;
1441 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001442
1443 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001444 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001445 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001446
1447 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001448 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001449
Milton Miller3c945e52010-02-19 17:44:42 +00001450 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001451
Alexander Duyckc267fc12010-11-16 19:27:00 -08001452 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1453
Auke Kok9a799d72007-09-15 14:07:45 -07001454 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001455 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001456 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001457
David S. Miller8decf862011-09-22 03:23:13 -04001458 /* linear means we are building an skb from multiple pages */
1459 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001460 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001461 if (ring_is_ps_enabled(rx_ring)) {
1462 hlen = ixgbe_get_hlen(rx_desc);
1463 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1464 } else {
1465 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1466 }
1467
1468 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001469
1470 /*
1471 * Delay unmapping of the first packet. It carries the
1472 * header information, HW may still access the header
1473 * after writeback. Only unmap it when EOP is reached
1474 */
1475 if (!IXGBE_CB(skb)->head) {
1476 IXGBE_CB(skb)->delay_unmap = true;
1477 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1478 } else {
1479 skb = ixgbe_merge_active_tail(skb);
1480 dma_unmap_single(rx_ring->dev,
1481 rx_buffer_info->dma,
1482 rx_ring->rx_buf_len,
1483 DMA_FROM_DEVICE);
1484 }
1485 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001486 } else {
1487 /* assume packet split since header is unmapped */
1488 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001489 }
1490
1491 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001492 dma_unmap_page(rx_ring->dev,
1493 rx_buffer_info->page_dma,
1494 PAGE_SIZE / 2,
1495 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001496 rx_buffer_info->page_dma = 0;
1497 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001498 rx_buffer_info->page,
1499 rx_buffer_info->page_offset,
1500 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001501
Alexander Duyckc267fc12010-11-16 19:27:00 -08001502 if ((page_count(rx_buffer_info->page) == 1) &&
1503 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001504 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001505 else
1506 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001507
1508 skb->len += upper_len;
1509 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001510 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001511 }
1512
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001513 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1514
Auke Kok9a799d72007-09-15 14:07:45 -07001515 i++;
1516 if (i == rx_ring->count)
1517 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001518
Alexander Duyck31f05a22010-08-19 13:40:31 +00001519 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001520 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001521 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001522
Alexander Duyckc267fc12010-11-16 19:27:00 -08001523 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001524 struct ixgbe_rx_buffer *next_buffer;
1525 u32 nextp;
1526
1527 if (IXGBE_CB(skb)->append_cnt) {
1528 nextp = staterr & IXGBE_RXDADV_NEXTP_MASK;
1529 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1530 } else {
1531 nextp = i;
1532 }
1533
1534 next_buffer = &rx_ring->rx_buffer_info[nextp];
1535
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001536 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001537 rx_buffer_info->skb = next_buffer->skb;
1538 rx_buffer_info->dma = next_buffer->dma;
1539 next_buffer->skb = skb;
1540 next_buffer->dma = 0;
1541 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001542 struct sk_buff *next_skb = next_buffer->skb;
1543 ixgbe_add_active_tail(skb, next_skb);
1544 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001545 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001546 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001547 goto next_desc;
1548 }
1549
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001550 dma_unmap_single(rx_ring->dev,
1551 IXGBE_CB(skb)->dma,
1552 rx_ring->rx_buf_len,
1553 DMA_FROM_DEVICE);
1554 IXGBE_CB(skb)->dma = 0;
1555 IXGBE_CB(skb)->delay_unmap = false;
1556
1557 if (ixgbe_close_active_frag_list(skb) &&
1558 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001559 /* if we got here without RSC the packet is invalid */
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001560 dev_kfree_skb_any(skb);
1561 goto next_desc;
Alexander Duyckaa801752010-11-16 19:27:02 -08001562 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001563
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001564 ixgbe_update_rsc_stats(rx_ring, skb);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001565
1566 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001567 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1568 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001569 goto next_desc;
1570 }
1571
Alexander Duyckff886df2011-06-11 01:45:13 +00001572 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001573 if (adapter->netdev->features & NETIF_F_RXHASH)
1574 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001575
1576 /* probably a little skewed due to removing CRC */
1577 total_rx_bytes += skb->len;
1578 total_rx_packets++;
1579
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001580 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001581#ifdef IXGBE_FCOE
1582 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001583 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1584 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1585 staterr);
David S. Miller823dcd22011-08-20 10:39:12 -07001586 if (!ddp_bytes) {
1587 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001588 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001589 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001590 }
Yi Zou332d4a72009-05-13 13:11:53 +00001591#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001592 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001593
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001594 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001595next_desc:
1596 rx_desc->wb.upper.status_error = 0;
1597
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001598 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001599 break;
1600
Auke Kok9a799d72007-09-15 14:07:45 -07001601 /* return some buffers to hardware, one at a time is too slow */
1602 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001603 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001604 cleaned_count = 0;
1605 }
1606
1607 /* use prefetched values */
1608 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001609 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001610 }
1611
Auke Kok9a799d72007-09-15 14:07:45 -07001612 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001613 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001614
1615 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001616 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001617
Yi Zou3d8fd382009-06-08 14:38:44 +00001618#ifdef IXGBE_FCOE
1619 /* include DDPed FCoE data */
1620 if (ddp_bytes > 0) {
1621 unsigned int mss;
1622
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001623 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001624 sizeof(struct fc_frame_header) -
1625 sizeof(struct fcoe_crc_eof);
1626 if (mss > 512)
1627 mss &= ~511;
1628 total_rx_bytes += ddp_bytes;
1629 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1630 }
1631#endif /* IXGBE_FCOE */
1632
Alexander Duyckc267fc12010-11-16 19:27:00 -08001633 u64_stats_update_begin(&rx_ring->syncp);
1634 rx_ring->stats.packets += total_rx_packets;
1635 rx_ring->stats.bytes += total_rx_bytes;
1636 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001637 q_vector->rx.total_packets += total_rx_packets;
1638 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001639
1640 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001641}
1642
Auke Kok9a799d72007-09-15 14:07:45 -07001643/**
1644 * ixgbe_configure_msix - Configure MSI-X hardware
1645 * @adapter: board private structure
1646 *
1647 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1648 * interrupts.
1649 **/
1650static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1651{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001652 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001653 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001654 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001655
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001656 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1657
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001658 /* Populate MSIX to EITR Select */
1659 if (adapter->num_vfs > 32) {
1660 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1661 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1662 }
1663
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001664 /*
1665 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001666 * corresponding register.
1667 */
1668 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001669 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001670 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001671
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001672 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1673 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001674
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001675 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1676 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001677
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001678 if (q_vector->tx.ring && !q_vector->rx.ring) {
1679 /* tx only vector */
1680 if (adapter->tx_itr_setting == 1)
1681 q_vector->itr = IXGBE_10K_ITR;
1682 else
1683 q_vector->itr = adapter->tx_itr_setting;
1684 } else {
1685 /* rx or rx/tx vector */
1686 if (adapter->rx_itr_setting == 1)
1687 q_vector->itr = IXGBE_20K_ITR;
1688 else
1689 q_vector->itr = adapter->rx_itr_setting;
1690 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001691
Alexander Duyckfe49f042009-06-04 16:00:09 +00001692 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001693 }
1694
Alexander Duyckbd508172010-11-16 19:27:03 -08001695 switch (adapter->hw.mac.type) {
1696 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001697 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001698 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001699 break;
1700 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001701 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001702 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001703 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001704 default:
1705 break;
1706 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001707 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001708
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001709 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001710 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001711 mask &= ~(IXGBE_EIMS_OTHER |
1712 IXGBE_EIMS_MAILBOX |
1713 IXGBE_EIMS_LSC);
1714
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001715 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001716}
1717
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001718enum latency_range {
1719 lowest_latency = 0,
1720 low_latency = 1,
1721 bulk_latency = 2,
1722 latency_invalid = 255
1723};
1724
1725/**
1726 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001727 * @q_vector: structure containing interrupt and ring information
1728 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001729 *
1730 * Stores a new ITR value based on packets and byte
1731 * counts during the last interrupt. The advantage of per interrupt
1732 * computation is faster updates and more accurate ITR for the current
1733 * traffic pattern. Constants in this function were computed
1734 * based on theoretical maximum wire speed and thresholds were set based
1735 * on testing data as well as attempting to minimize response time
1736 * while increasing bulk throughput.
1737 * this functionality is controlled by the InterruptThrottleRate module
1738 * parameter (see ixgbe_param.c)
1739 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001740static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1741 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001742{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001743 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001744 struct ixgbe_adapter *adapter = q_vector->adapter;
1745 int bytes = ring_container->total_bytes;
1746 int packets = ring_container->total_packets;
1747 u32 timepassed_us;
1748 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001749
1750 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001751 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001752
1753 /* simple throttlerate management
1754 * 0-20MB/s lowest (100000 ints/s)
1755 * 20-100MB/s low (20000 ints/s)
1756 * 100-1249MB/s bulk (8000 ints/s)
1757 */
1758 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001759 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001760 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1761
1762 switch (itr_setting) {
1763 case lowest_latency:
1764 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001765 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001766 break;
1767 case low_latency:
1768 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001769 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001770 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001771 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001772 break;
1773 case bulk_latency:
1774 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001775 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001776 break;
1777 }
1778
Alexander Duyckbd198052011-06-11 01:45:08 +00001779 /* clear work counters since we have the values we need */
1780 ring_container->total_bytes = 0;
1781 ring_container->total_packets = 0;
1782
1783 /* write updated itr to ring container */
1784 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001785}
1786
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001787/**
1788 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001789 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001790 *
1791 * This function is made to be called by ethtool and by the driver
1792 * when it needs to update EITR registers at runtime. Hardware
1793 * specific quirks/differences are taken care of here.
1794 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001795void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001796{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001797 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001798 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001799 int v_idx = q_vector->v_idx;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001800 u32 itr_reg = q_vector->itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001801
Alexander Duyckbd508172010-11-16 19:27:03 -08001802 switch (adapter->hw.mac.type) {
1803 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001804 /* must write high and low 16 bits to reset counter */
1805 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001806 break;
1807 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001808 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001809 /*
1810 * set the WDIS bit to not clear the timer bits and cause an
1811 * immediate assertion of the interrupt
1812 */
1813 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001814 break;
1815 default:
1816 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001817 }
1818 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1819}
1820
Alexander Duyckbd198052011-06-11 01:45:08 +00001821static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001822{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001823 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001824 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001825
Alexander Duyckbd198052011-06-11 01:45:08 +00001826 ixgbe_update_itr(q_vector, &q_vector->tx);
1827 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001828
Alexander Duyck08c88332011-06-11 01:45:03 +00001829 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001830
1831 switch (current_itr) {
1832 /* counts and packets in update_itr are dependent on these numbers */
1833 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001834 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001835 break;
1836 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001837 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001838 break;
1839 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001840 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001841 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001842 default:
1843 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001844 }
1845
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001846 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001847 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001848 new_itr = (10 * new_itr * q_vector->itr) /
1849 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001850
Alexander Duyckbd198052011-06-11 01:45:08 +00001851 /* save the algorithm value here */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001852 q_vector->itr = new_itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001853
1854 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001855 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001856}
1857
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001858/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001859 * ixgbe_check_overtemp_subtask - check for over tempurature
1860 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001861 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001862static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001863{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001864 struct ixgbe_hw *hw = &adapter->hw;
1865 u32 eicr = adapter->interrupt_event;
1866
Alexander Duyckf0f97782011-04-22 04:08:09 +00001867 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001868 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001869
Alexander Duyckf0f97782011-04-22 04:08:09 +00001870 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1871 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1872 return;
1873
1874 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1875
Joe Perches7ca647b2010-09-07 21:35:40 +00001876 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001877 case IXGBE_DEV_ID_82599_T3_LOM:
1878 /*
1879 * Since the warning interrupt is for both ports
1880 * we don't have to check if:
1881 * - This interrupt wasn't for our port.
1882 * - We may have missed the interrupt so always have to
1883 * check if we got a LSC
1884 */
1885 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1886 !(eicr & IXGBE_EICR_LSC))
1887 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001888
Alexander Duyckf0f97782011-04-22 04:08:09 +00001889 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1890 u32 autoneg;
1891 bool link_up = false;
1892
Joe Perches7ca647b2010-09-07 21:35:40 +00001893 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1894
Alexander Duyckf0f97782011-04-22 04:08:09 +00001895 if (link_up)
1896 return;
1897 }
1898
1899 /* Check if this is not due to overtemp */
1900 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1901 return;
1902
1903 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001904 default:
1905 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1906 return;
1907 break;
1908 }
1909 e_crit(drv,
1910 "Network adapter has been stopped because it has over heated. "
1911 "Restart the computer. If the problem persists, "
1912 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001913
1914 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001915}
1916
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001917static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1918{
1919 struct ixgbe_hw *hw = &adapter->hw;
1920
1921 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1922 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001923 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001924 /* write to clear the interrupt */
1925 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1926 }
1927}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001928
Jacob Keller4f51bf72011-08-20 04:49:45 +00001929static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1930{
1931 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1932 return;
1933
1934 switch (adapter->hw.mac.type) {
1935 case ixgbe_mac_82599EB:
1936 /*
1937 * Need to check link state so complete overtemp check
1938 * on service task
1939 */
1940 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1941 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1942 adapter->interrupt_event = eicr;
1943 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1944 ixgbe_service_event_schedule(adapter);
1945 return;
1946 }
1947 return;
1948 case ixgbe_mac_X540:
1949 if (!(eicr & IXGBE_EICR_TS))
1950 return;
1951 break;
1952 default:
1953 return;
1954 }
1955
1956 e_crit(drv,
1957 "Network adapter has been stopped because it has over heated. "
1958 "Restart the computer. If the problem persists, "
1959 "power off the system and replace the adapter\n");
1960}
1961
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001962static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1963{
1964 struct ixgbe_hw *hw = &adapter->hw;
1965
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001966 if (eicr & IXGBE_EICR_GPI_SDP2) {
1967 /* Clear the interrupt */
1968 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001969 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1970 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1971 ixgbe_service_event_schedule(adapter);
1972 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001973 }
1974
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001975 if (eicr & IXGBE_EICR_GPI_SDP1) {
1976 /* Clear the interrupt */
1977 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001978 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1979 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1980 ixgbe_service_event_schedule(adapter);
1981 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001982 }
1983}
1984
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001985static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1986{
1987 struct ixgbe_hw *hw = &adapter->hw;
1988
1989 adapter->lsc_int++;
1990 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1991 adapter->link_check_timeout = jiffies;
1992 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1993 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001994 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001995 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001996 }
1997}
1998
Alexander Duyckfe49f042009-06-04 16:00:09 +00001999static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2000 u64 qmask)
2001{
2002 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002003 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002004
Alexander Duyckbd508172010-11-16 19:27:03 -08002005 switch (hw->mac.type) {
2006 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002007 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002008 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2009 break;
2010 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002011 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002012 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002013 if (mask)
2014 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002015 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002016 if (mask)
2017 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2018 break;
2019 default:
2020 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002021 }
2022 /* skip the flush */
2023}
2024
2025static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002026 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002027{
2028 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002029 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002030
Alexander Duyckbd508172010-11-16 19:27:03 -08002031 switch (hw->mac.type) {
2032 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002033 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002034 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2035 break;
2036 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002037 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002038 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002039 if (mask)
2040 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002041 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002042 if (mask)
2043 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2044 break;
2045 default:
2046 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002047 }
2048 /* skip the flush */
2049}
2050
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002051/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002052 * ixgbe_irq_enable - Enable default interrupt generation settings
2053 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002054 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002055static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2056 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002057{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002058 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002059
Alexander Duyck2c4af692011-07-15 07:29:55 +00002060 /* don't reenable LSC while waiting for link */
2061 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2062 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063
Alexander Duyck2c4af692011-07-15 07:29:55 +00002064 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002065 switch (adapter->hw.mac.type) {
2066 case ixgbe_mac_82599EB:
2067 mask |= IXGBE_EIMS_GPI_SDP0;
2068 break;
2069 case ixgbe_mac_X540:
2070 mask |= IXGBE_EIMS_TS;
2071 break;
2072 default:
2073 break;
2074 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002075 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2076 mask |= IXGBE_EIMS_GPI_SDP1;
2077 switch (adapter->hw.mac.type) {
2078 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002079 mask |= IXGBE_EIMS_GPI_SDP1;
2080 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002081 case ixgbe_mac_X540:
2082 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002083 mask |= IXGBE_EIMS_MAILBOX;
2084 break;
2085 default:
2086 break;
2087 }
2088 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2089 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2090 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002091
Alexander Duyck2c4af692011-07-15 07:29:55 +00002092 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2093 if (queues)
2094 ixgbe_irq_enable_queues(adapter, ~0);
2095 if (flush)
2096 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002097}
2098
Alexander Duyck2c4af692011-07-15 07:29:55 +00002099static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002100{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002101 struct ixgbe_adapter *adapter = data;
2102 struct ixgbe_hw *hw = &adapter->hw;
2103 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002104
Alexander Duyck2c4af692011-07-15 07:29:55 +00002105 /*
2106 * Workaround for Silicon errata. Use clear-by-write instead
2107 * of clear-by-read. Reading with EICS will return the
2108 * interrupt causes without clearing, which later be done
2109 * with the write to EICR.
2110 */
2111 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2112 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002113
Alexander Duyck2c4af692011-07-15 07:29:55 +00002114 if (eicr & IXGBE_EICR_LSC)
2115 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002116
Alexander Duyck2c4af692011-07-15 07:29:55 +00002117 if (eicr & IXGBE_EICR_MAILBOX)
2118 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002119
Alexander Duyck2c4af692011-07-15 07:29:55 +00002120 switch (hw->mac.type) {
2121 case ixgbe_mac_82599EB:
2122 case ixgbe_mac_X540:
2123 if (eicr & IXGBE_EICR_ECC)
2124 e_info(link, "Received unrecoverable ECC Err, please "
2125 "reboot\n");
2126 /* Handle Flow Director Full threshold interrupt */
2127 if (eicr & IXGBE_EICR_FLOW_DIR) {
2128 int reinit_count = 0;
2129 int i;
2130 for (i = 0; i < adapter->num_tx_queues; i++) {
2131 struct ixgbe_ring *ring = adapter->tx_ring[i];
2132 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2133 &ring->state))
2134 reinit_count++;
2135 }
2136 if (reinit_count) {
2137 /* no more flow director interrupts until after init */
2138 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2139 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2140 ixgbe_service_event_schedule(adapter);
2141 }
2142 }
2143 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002144 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002145 break;
2146 default:
2147 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002148 }
2149
Alexander Duyck2c4af692011-07-15 07:29:55 +00002150 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002151
Alexander Duyck2c4af692011-07-15 07:29:55 +00002152 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002153 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002154 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002155
Alexander Duyck2c4af692011-07-15 07:29:55 +00002156 return IRQ_HANDLED;
2157}
2158
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002159static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002160{
2161 struct ixgbe_q_vector *q_vector = data;
2162
Auke Kok9a799d72007-09-15 14:07:45 -07002163 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002164
2165 if (q_vector->rx.ring || q_vector->tx.ring)
2166 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002167
2168 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002169}
2170
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002171static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002172 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002173{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002174 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002175 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002176
Alexander Duyck22745432010-11-16 19:27:10 -08002177 rx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002178 rx_ring->next = q_vector->rx.ring;
2179 q_vector->rx.ring = rx_ring;
2180 q_vector->rx.count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002181}
Auke Kok9a799d72007-09-15 14:07:45 -07002182
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002183static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002184 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002185{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002186 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002187 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002188
Alexander Duyck22745432010-11-16 19:27:10 -08002189 tx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002190 tx_ring->next = q_vector->tx.ring;
2191 q_vector->tx.ring = tx_ring;
2192 q_vector->tx.count++;
Alexander Duyckbd198052011-06-11 01:45:08 +00002193 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002194}
Auke Kok9a799d72007-09-15 14:07:45 -07002195
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002196/**
2197 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2198 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002199 *
2200 * This function maps descriptor rings to the queue-specific vectors
2201 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2202 * one vector per ring/queue, but on a constrained vector budget, we
2203 * group the rings as "efficiently" as possible. You would add new
2204 * mapping configurations in here.
2205 **/
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002206static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002207{
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002208 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2209 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2210 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002211 int v_start = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002212
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002213 /* only one q_vector if MSI-X is disabled. */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002214 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002215 q_vectors = 1;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002216
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002217 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002218 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2219 * group them so there are multiple queues per vector.
2220 *
2221 * Re-adjusting *qpv takes care of the remainder.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002222 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002223 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2224 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2225 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226 map_vector_to_rxq(adapter, v_start, rxr_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002227 }
2228
2229 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002230 * If there are not enough q_vectors for each ring to have it's own
2231 * vector then we must pair up Rx/Tx on a each vector
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002232 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002233 if ((v_start + txr_remaining) > q_vectors)
2234 v_start = 0;
2235
2236 for (; v_start < q_vectors && txr_remaining; v_start++) {
2237 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2238 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2239 map_vector_to_txq(adapter, v_start, txr_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07002240 }
Auke Kok9a799d72007-09-15 14:07:45 -07002241}
2242
2243/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2245 * @adapter: board private structure
2246 *
2247 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2248 * interrupts from the kernel.
2249 **/
2250static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2251{
2252 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002253 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2254 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002255 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002258 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002259 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002260
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002261 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002262 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002263 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002264 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002265 } else if (q_vector->rx.ring) {
2266 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2267 "%s-%s-%d", netdev->name, "rx", ri++);
2268 } else if (q_vector->tx.ring) {
2269 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2270 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002271 } else {
2272 /* skip this unused q_vector */
2273 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002274 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002275 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2276 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002277 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002278 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002279 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002280 goto free_queue_irqs;
2281 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002282 /* If Flow Director is enabled, set interrupt affinity */
2283 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2284 /* assign the mask for this irq */
2285 irq_set_affinity_hint(entry->vector,
2286 q_vector->affinity_mask);
2287 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002288 }
2289
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002290 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002291 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002293 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294 goto free_queue_irqs;
2295 }
2296
2297 return 0;
2298
2299free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002300 while (vector) {
2301 vector--;
2302 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2303 NULL);
2304 free_irq(adapter->msix_entries[vector].vector,
2305 adapter->q_vector[vector]);
2306 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002307 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2308 pci_disable_msix(adapter->pdev);
2309 kfree(adapter->msix_entries);
2310 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002311 return err;
2312}
2313
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002314/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002316 * @irq: interrupt number
2317 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002318 **/
2319static irqreturn_t ixgbe_intr(int irq, void *data)
2320{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002321 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002322 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002323 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002324 u32 eicr;
2325
Don Skidmore54037502009-02-21 15:42:56 -08002326 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002327 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002328 * before the read of EICR.
2329 */
2330 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2331
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002332 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002333 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002334 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002335 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002336 /*
2337 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002338 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002339 * have disabled interrupts due to EIAM
2340 * finish the workaround of silicon errata on 82598. Unmask
2341 * the interrupt that we masked before the EICR read.
2342 */
2343 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2344 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002345 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002346 }
Auke Kok9a799d72007-09-15 14:07:45 -07002347
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002348 if (eicr & IXGBE_EICR_LSC)
2349 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002350
Alexander Duyckbd508172010-11-16 19:27:03 -08002351 switch (hw->mac.type) {
2352 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002353 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002354 /* Fall through */
2355 case ixgbe_mac_X540:
2356 if (eicr & IXGBE_EICR_ECC)
2357 e_info(link, "Received unrecoverable ECC err, please "
2358 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002359 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002360 break;
2361 default:
2362 break;
2363 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002364
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002365 ixgbe_check_fan_failure(adapter, eicr);
2366
Alexander Duyck7a921c92009-05-06 10:43:28 +00002367 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002368 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002369 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002370 }
2371
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002372 /*
2373 * re-enable link(maybe) and non-queue interrupts, no flush.
2374 * ixgbe_poll will re-enable the queue interrupts
2375 */
2376
2377 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2378 ixgbe_irq_enable(adapter, false, false);
2379
Auke Kok9a799d72007-09-15 14:07:45 -07002380 return IRQ_HANDLED;
2381}
2382
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002383static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2384{
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002385 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2386 int i;
2387
2388 /* legacy and MSI only use one vector */
2389 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2390 q_vectors = 1;
2391
2392 for (i = 0; i < adapter->num_rx_queues; i++) {
2393 adapter->rx_ring[i]->q_vector = NULL;
2394 adapter->rx_ring[i]->next = NULL;
2395 }
2396 for (i = 0; i < adapter->num_tx_queues; i++) {
2397 adapter->tx_ring[i]->q_vector = NULL;
2398 adapter->tx_ring[i]->next = NULL;
2399 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002400
2401 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002402 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002403 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2404 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002405 }
2406}
2407
Auke Kok9a799d72007-09-15 14:07:45 -07002408/**
2409 * ixgbe_request_irq - initialize interrupts
2410 * @adapter: board private structure
2411 *
2412 * Attempts to configure interrupts using the best available
2413 * capabilities of the hardware and kernel.
2414 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002415static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002416{
2417 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002418 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002419
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002420 /* map all of the rings to the q_vectors */
2421 ixgbe_map_rings_to_vectors(adapter);
2422
2423 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002424 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002425 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002426 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002427 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002428 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002429 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002430 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002431
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002432 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002433 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002434
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002435 /* place q_vectors and rings back into a known good state */
2436 ixgbe_reset_q_vectors(adapter);
2437 }
2438
Auke Kok9a799d72007-09-15 14:07:45 -07002439 return err;
2440}
2441
2442static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2443{
Auke Kok9a799d72007-09-15 14:07:45 -07002444 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002445 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002446
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002447 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002449 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002451
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002453 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002454 if (!adapter->q_vector[i]->rx.ring &&
2455 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002456 continue;
2457
Alexander Duyck207867f2011-07-15 03:05:37 +00002458 /* clear the affinity_mask in the IRQ descriptor */
2459 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2460 NULL);
2461
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002462 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002463 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002464 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002465 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002466 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002467 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002468
2469 /* clear q_vector state information */
2470 ixgbe_reset_q_vectors(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002471}
2472
2473/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002474 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2475 * @adapter: board private structure
2476 **/
2477static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2478{
Alexander Duyckbd508172010-11-16 19:27:03 -08002479 switch (adapter->hw.mac.type) {
2480 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002481 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002482 break;
2483 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002484 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002485 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2486 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002487 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002488 break;
2489 default:
2490 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002491 }
2492 IXGBE_WRITE_FLUSH(&adapter->hw);
2493 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2494 int i;
2495 for (i = 0; i < adapter->num_msix_vectors; i++)
2496 synchronize_irq(adapter->msix_entries[i].vector);
2497 } else {
2498 synchronize_irq(adapter->pdev->irq);
2499 }
2500}
2501
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002502/**
Auke Kok9a799d72007-09-15 14:07:45 -07002503 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2504 *
2505 **/
2506static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2507{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002508 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002509
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002510 /* rx/tx vector */
2511 if (adapter->rx_itr_setting == 1)
2512 q_vector->itr = IXGBE_20K_ITR;
2513 else
2514 q_vector->itr = adapter->rx_itr_setting;
2515
2516 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002517
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002518 ixgbe_set_ivar(adapter, 0, 0, 0);
2519 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520
Emil Tantilov396e7992010-07-01 20:05:12 +00002521 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002522}
2523
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002524/**
2525 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2526 * @adapter: board private structure
2527 * @ring: structure containing ring specific data
2528 *
2529 * Configure the Tx descriptor ring after a reset.
2530 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002531void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2532 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002533{
2534 struct ixgbe_hw *hw = &adapter->hw;
2535 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002536 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002537 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002538 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002539
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002540 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002541 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002542 IXGBE_WRITE_FLUSH(hw);
2543
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002544 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002545 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002546 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2547 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2548 ring->count * sizeof(union ixgbe_adv_tx_desc));
2549 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2550 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002551 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002552
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002553 /*
2554 * set WTHRESH to encourage burst writeback, it should not be set
2555 * higher than 1 when ITR is 0 as it could cause false TX hangs
2556 *
2557 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2558 * to or less than the number of on chip descriptors, which is
2559 * currently 40.
2560 */
2561 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2562 txdctl |= (1 << 16); /* WTHRESH = 1 */
2563 else
2564 txdctl |= (8 << 16); /* WTHRESH = 8 */
2565
2566 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2567 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2568 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002569
2570 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002571 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2572 adapter->atr_sample_rate) {
2573 ring->atr_sample_rate = adapter->atr_sample_rate;
2574 ring->atr_count = 0;
2575 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2576 } else {
2577 ring->atr_sample_rate = 0;
2578 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002579
John Fastabendc84d3242010-11-16 19:27:12 -08002580 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2581
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002582 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002583 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2584
2585 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2586 if (hw->mac.type == ixgbe_mac_82598EB &&
2587 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2588 return;
2589
2590 /* poll to verify queue is enabled */
2591 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002592 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002593 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2594 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2595 if (!wait_loop)
2596 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002597}
2598
Alexander Duyck120ff942010-08-19 13:34:50 +00002599static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2600{
2601 struct ixgbe_hw *hw = &adapter->hw;
2602 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002603 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002604 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002605
2606 if (hw->mac.type == ixgbe_mac_82598EB)
2607 return;
2608
2609 /* disable the arbiter while setting MTQC */
2610 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2611 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2612 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2613
2614 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002615 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002616 case (IXGBE_FLAG_SRIOV_ENABLED):
2617 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2618 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2619 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002620 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002621 if (!tcs)
2622 reg = IXGBE_MTQC_64Q_1PB;
2623 else if (tcs <= 4)
2624 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2625 else
2626 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2627
2628 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2629
2630 /* Enable Security TX Buffer IFG for multiple pb */
2631 if (tcs) {
2632 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2633 reg |= IXGBE_SECTX_DCB;
2634 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2635 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002636 break;
2637 }
2638
2639 /* re-enable the arbiter */
2640 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2641 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2642}
2643
Auke Kok9a799d72007-09-15 14:07:45 -07002644/**
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07002645 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002646 * @adapter: board private structure
2647 *
2648 * Configure the Tx unit of the MAC after a reset.
2649 **/
2650static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2651{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002652 struct ixgbe_hw *hw = &adapter->hw;
2653 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002654 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002655
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002656 ixgbe_setup_mtqc(adapter);
2657
2658 if (hw->mac.type != ixgbe_mac_82598EB) {
2659 /* DMATXCTL.EN must be before Tx queues are enabled */
2660 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2661 dmatxctl |= IXGBE_DMATXCTL_TE;
2662 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2663 }
2664
Auke Kok9a799d72007-09-15 14:07:45 -07002665 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002666 for (i = 0; i < adapter->num_tx_queues; i++)
2667 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002668}
2669
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002670#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002671
Yi Zoua6616b42009-08-06 13:05:23 +00002672static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002673 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002674{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002675 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002676 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002677
Alexander Duyckbd508172010-11-16 19:27:03 -08002678 switch (adapter->hw.mac.type) {
2679 case ixgbe_mac_82598EB: {
2680 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2681 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002682 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002683 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002684 break;
2685 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002686 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002687 default:
2688 break;
2689 }
2690
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002691 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002692
2693 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2694 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002695 if (adapter->num_vfs)
2696 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002697
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002698 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2699 IXGBE_SRRCTL_BSIZEHDR_MASK;
2700
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002701 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002702#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2703 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2704#else
2705 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2706#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002707 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002708 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002709 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2710 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002711 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002712 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002713
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002714 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002715}
2716
Alexander Duyck05abb122010-08-19 13:35:41 +00002717static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002718{
Alexander Duyck05abb122010-08-19 13:35:41 +00002719 struct ixgbe_hw *hw = &adapter->hw;
2720 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002721 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2722 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002723 u32 mrqc = 0, reta = 0;
2724 u32 rxcsum;
2725 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002726 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002727 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2728
2729 if (tcs)
2730 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002731
Alexander Duyck05abb122010-08-19 13:35:41 +00002732 /* Fill out hash function seeds */
2733 for (i = 0; i < 10; i++)
2734 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002735
Alexander Duyck05abb122010-08-19 13:35:41 +00002736 /* Fill out redirection table */
2737 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002738 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002739 j = 0;
2740 /* reta = 4-byte sliding window of
2741 * 0x00..(indices-1)(indices-1)00..etc. */
2742 reta = (reta << 8) | (j * 0x11);
2743 if ((i & 3) == 3)
2744 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2745 }
2746
2747 /* Disable indicating checksum in descriptor, enables RSS hash */
2748 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2749 rxcsum |= IXGBE_RXCSUM_PCSD;
2750 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2751
John Fastabend8b1c0b22011-05-03 02:26:48 +00002752 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2753 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002754 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002755 } else {
2756 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2757 | IXGBE_FLAG_SRIOV_ENABLED);
2758
2759 switch (mask) {
2760 case (IXGBE_FLAG_RSS_ENABLED):
2761 if (!tcs)
2762 mrqc = IXGBE_MRQC_RSSEN;
2763 else if (tcs <= 4)
2764 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2765 else
2766 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2767 break;
2768 case (IXGBE_FLAG_SRIOV_ENABLED):
2769 mrqc = IXGBE_MRQC_VMDQEN;
2770 break;
2771 default:
2772 break;
2773 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002774 }
2775
Alexander Duyck05abb122010-08-19 13:35:41 +00002776 /* Perform hash on these packet types */
2777 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2778 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2779 | IXGBE_MRQC_RSS_FIELD_IPV6
2780 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2781
2782 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002783}
2784
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002785/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002786 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2787 * @adapter: address of board private structure
2788 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002789 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002790static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002791 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002792{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002793 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002794 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002795 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002796 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002797
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002798 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002799 return;
2800
2801 rx_buf_len = ring->rx_buf_len;
2802 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002803 rscctrl |= IXGBE_RSCCTL_RSCEN;
2804 /*
2805 * we must limit the number of descriptors so that the
2806 * total size of max desc * buf_len is not greater
2807 * than 65535
2808 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002809 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002810#if (MAX_SKB_FRAGS > 16)
2811 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2812#elif (MAX_SKB_FRAGS > 8)
2813 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2814#elif (MAX_SKB_FRAGS > 4)
2815 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2816#else
2817 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2818#endif
2819 } else {
Alexander Duyck919e78a2011-08-26 09:52:38 +00002820 if (rx_buf_len < IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002821 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck919e78a2011-08-26 09:52:38 +00002822 else if (rx_buf_len < IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002823 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2824 else
2825 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2826 }
Alexander Duyck73670962010-08-19 13:38:34 +00002827 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002828}
2829
Alexander Duyck9e10e042010-08-19 13:40:06 +00002830/**
2831 * ixgbe_set_uta - Set unicast filter table address
2832 * @adapter: board private structure
2833 *
2834 * The unicast table address is a register array of 32-bit registers.
2835 * The table is meant to be used in a way similar to how the MTA is used
2836 * however due to certain limitations in the hardware it is necessary to
2837 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2838 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2839 **/
2840static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2841{
2842 struct ixgbe_hw *hw = &adapter->hw;
2843 int i;
2844
2845 /* The UTA table only exists on 82599 hardware and newer */
2846 if (hw->mac.type < ixgbe_mac_82599EB)
2847 return;
2848
2849 /* we only need to do this if VMDq is enabled */
2850 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2851 return;
2852
2853 for (i = 0; i < 128; i++)
2854 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2855}
2856
2857#define IXGBE_MAX_RX_DESC_POLL 10
2858static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2859 struct ixgbe_ring *ring)
2860{
2861 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002862 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2863 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002864 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002865
2866 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2867 if (hw->mac.type == ixgbe_mac_82598EB &&
2868 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2869 return;
2870
2871 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002872 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002873 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2874 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2875
2876 if (!wait_loop) {
2877 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2878 "the polling period\n", reg_idx);
2879 }
2880}
2881
Yi Zou2d39d572011-01-06 14:29:56 +00002882void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2883 struct ixgbe_ring *ring)
2884{
2885 struct ixgbe_hw *hw = &adapter->hw;
2886 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2887 u32 rxdctl;
2888 u8 reg_idx = ring->reg_idx;
2889
2890 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2891 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2892
2893 /* write value back with RXDCTL.ENABLE bit cleared */
2894 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2895
2896 if (hw->mac.type == ixgbe_mac_82598EB &&
2897 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2898 return;
2899
2900 /* the hardware may take up to 100us to really disable the rx queue */
2901 do {
2902 udelay(10);
2903 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2904 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2905
2906 if (!wait_loop) {
2907 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2908 "the polling period\n", reg_idx);
2909 }
2910}
2911
Alexander Duyck84418e32010-08-19 13:40:54 +00002912void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2913 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002914{
2915 struct ixgbe_hw *hw = &adapter->hw;
2916 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002917 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002918 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002919
Alexander Duyck9e10e042010-08-19 13:40:06 +00002920 /* disable queue to avoid issues while updating state */
2921 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002922 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002923
Alexander Duyckacd37172010-08-19 13:36:05 +00002924 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2925 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2926 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2927 ring->count * sizeof(union ixgbe_adv_rx_desc));
2928 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2929 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002930 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002931
2932 ixgbe_configure_srrctl(adapter, ring);
2933 ixgbe_configure_rscctl(adapter, ring);
2934
Greg Rosee9f98072011-01-26 01:06:07 +00002935 /* If operating in IOV mode set RLPML for X540 */
2936 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2937 hw->mac.type == ixgbe_mac_X540) {
2938 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2939 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2940 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2941 }
2942
Alexander Duyck9e10e042010-08-19 13:40:06 +00002943 if (hw->mac.type == ixgbe_mac_82598EB) {
2944 /*
2945 * enable cache line friendly hardware writes:
2946 * PTHRESH=32 descriptors (half the internal cache),
2947 * this also removes ugly rx_no_buffer_count increment
2948 * HTHRESH=4 descriptors (to minimize latency on fetch)
2949 * WTHRESH=8 burst writeback up to two cache lines
2950 */
2951 rxdctl &= ~0x3FFFFF;
2952 rxdctl |= 0x080420;
2953 }
2954
2955 /* enable receive descriptor ring */
2956 rxdctl |= IXGBE_RXDCTL_ENABLE;
2957 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2958
2959 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002960 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002961}
2962
Alexander Duyck48654522010-08-19 13:36:27 +00002963static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2964{
2965 struct ixgbe_hw *hw = &adapter->hw;
2966 int p;
2967
2968 /* PSRTYPE must be initialized in non 82598 adapters */
2969 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002970 IXGBE_PSRTYPE_UDPHDR |
2971 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002972 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002973 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002974
2975 if (hw->mac.type == ixgbe_mac_82598EB)
2976 return;
2977
2978 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
2979 psrtype |= (adapter->num_rx_queues_per_pool << 29);
2980
2981 for (p = 0; p < adapter->num_rx_pools; p++)
2982 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
2983 psrtype);
2984}
2985
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002986static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
2987{
2988 struct ixgbe_hw *hw = &adapter->hw;
2989 u32 gcr_ext;
2990 u32 vt_reg_bits;
2991 u32 reg_offset, vf_shift;
2992 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00002993 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00002994
2995 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2996 return;
2997
2998 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
2999 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3000 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3001 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3002
3003 vf_shift = adapter->num_vfs % 32;
3004 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3005
3006 /* Enable only the PF's pool for Tx/Rx */
3007 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3008 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3009 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3010 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3011 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3012
3013 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3014 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3015
3016 /*
3017 * Set up VF register offsets for selected VT Mode,
3018 * i.e. 32 or 64 VFs for SR-IOV
3019 */
3020 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3021 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3022 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3023 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3024
3025 /* enable Tx loopback for VF/PF communication */
3026 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003027 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003028 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003029 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003030 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003031 /* For VFs that have spoof checking turned off */
3032 for (i = 0; i < adapter->num_vfs; i++) {
3033 if (!adapter->vfinfo[i].spoofchk_enabled)
3034 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3035 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003036}
3037
Alexander Duyck477de6e2010-08-19 13:38:11 +00003038static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003039{
Auke Kok9a799d72007-09-15 14:07:45 -07003040 struct ixgbe_hw *hw = &adapter->hw;
3041 struct net_device *netdev = adapter->netdev;
3042 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003043 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003044 struct ixgbe_ring *rx_ring;
3045 int i;
3046 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003047
Auke Kok9a799d72007-09-15 14:07:45 -07003048 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003049 /* On by default */
3050 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3051
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003052 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003053 if (adapter->num_vfs)
3054 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3055
3056 /* Disable packet split due to 82599 erratum #45 */
3057 if (hw->mac.type == ixgbe_mac_82599EB)
3058 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003059
Alexander Duyck477de6e2010-08-19 13:38:11 +00003060#ifdef IXGBE_FCOE
3061 /* adjust max frame to be able to do baby jumbo for FCoE */
3062 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3063 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3064 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3065
3066#endif /* IXGBE_FCOE */
3067 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3068 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3069 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3070 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3071
3072 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003073 }
3074
Alexander Duyck919e78a2011-08-26 09:52:38 +00003075 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3076 max_frame += VLAN_HLEN;
3077
3078 /* Set the RX buffer length according to the mode */
3079 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3080 rx_buf_len = IXGBE_RX_HDR_SIZE;
3081 } else {
3082 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3083 (netdev->mtu <= ETH_DATA_LEN))
3084 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3085 /*
3086 * Make best use of allocation by using all but 1K of a
3087 * power of 2 allocation that will be used for skb->head.
3088 */
3089 else if (max_frame <= IXGBE_RXBUFFER_3K)
3090 rx_buf_len = IXGBE_RXBUFFER_3K;
3091 else if (max_frame <= IXGBE_RXBUFFER_7K)
3092 rx_buf_len = IXGBE_RXBUFFER_7K;
3093 else if (max_frame <= IXGBE_RXBUFFER_15K)
3094 rx_buf_len = IXGBE_RXBUFFER_15K;
3095 else
3096 rx_buf_len = IXGBE_MAX_RXBUFFER;
3097 }
3098
Auke Kok9a799d72007-09-15 14:07:45 -07003099 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003100 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3101 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003102 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3103
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003104 /*
3105 * Setup the HW Rx Head and Tail Descriptor Pointers and
3106 * the Base and Length of the Rx Descriptor Ring
3107 */
Auke Kok9a799d72007-09-15 14:07:45 -07003108 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003109 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003110 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003111
Yi Zou6e455b892009-08-06 13:05:44 +00003112 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003113 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003114 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003115 clear_ring_ps_enabled(rx_ring);
3116
3117 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3118 set_ring_rsc_enabled(rx_ring);
3119 else
3120 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003121
Yi Zou63f39bd2009-05-17 12:34:35 +00003122#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003123 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003124 struct ixgbe_ring_feature *f;
3125 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003126 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003127 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003128 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3129 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003130 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003131 } else if (!ring_is_rsc_enabled(rx_ring) &&
3132 !ring_is_ps_enabled(rx_ring)) {
3133 rx_ring->rx_buf_len =
3134 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003135 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003136 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003137#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003138 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003139}
3140
Alexander Duyck73670962010-08-19 13:38:34 +00003141static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3142{
3143 struct ixgbe_hw *hw = &adapter->hw;
3144 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3145
3146 switch (hw->mac.type) {
3147 case ixgbe_mac_82598EB:
3148 /*
3149 * For VMDq support of different descriptor types or
3150 * buffer sizes through the use of multiple SRRCTL
3151 * registers, RDRXCTL.MVMEN must be set to 1
3152 *
3153 * also, the manual doesn't mention it clearly but DCA hints
3154 * will only use queue 0's tags unless this bit is set. Side
3155 * effects of setting this bit are only that SRRCTL must be
3156 * fully programmed [0..15]
3157 */
3158 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3159 break;
3160 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003161 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003162 /* Disable RSC for ACK packets */
3163 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3164 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3165 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3166 /* hardware requires some bits to be set by default */
3167 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3168 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3169 break;
3170 default:
3171 /* We should do nothing since we don't know this hardware */
3172 return;
3173 }
3174
3175 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3176}
3177
Alexander Duyck477de6e2010-08-19 13:38:11 +00003178/**
3179 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3180 * @adapter: board private structure
3181 *
3182 * Configure the Rx unit of the MAC after a reset.
3183 **/
3184static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3185{
3186 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003187 int i;
3188 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003189
3190 /* disable receives while setting up the descriptors */
3191 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3192 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3193
3194 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003195 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003196
Alexander Duyck9e10e042010-08-19 13:40:06 +00003197 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003198 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003199
Alexander Duyck9e10e042010-08-19 13:40:06 +00003200 ixgbe_set_uta(adapter);
3201
Alexander Duyck477de6e2010-08-19 13:38:11 +00003202 /* set_rx_buffer_len must be called before ring initialization */
3203 ixgbe_set_rx_buffer_len(adapter);
3204
3205 /*
3206 * Setup the HW Rx Head and Tail Descriptor Pointers and
3207 * the Base and Length of the Rx Descriptor Ring
3208 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003209 for (i = 0; i < adapter->num_rx_queues; i++)
3210 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003211
Alexander Duyck9e10e042010-08-19 13:40:06 +00003212 /* disable drop enable for 82598 parts */
3213 if (hw->mac.type == ixgbe_mac_82598EB)
3214 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3215
3216 /* enable all receives */
3217 rxctrl |= IXGBE_RXCTRL_RXEN;
3218 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003219}
3220
Jiri Pirko8e586132011-12-08 19:52:37 -05003221static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003222{
3223 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003224 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003225 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003226
3227 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003228 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003229 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003230
3231 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003232}
3233
Jiri Pirko8e586132011-12-08 19:52:37 -05003234static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003235{
3236 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003237 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003238 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003239
Auke Kok9a799d72007-09-15 14:07:45 -07003240 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003241 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003242 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003243
3244 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003245}
3246
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003247/**
3248 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3249 * @adapter: driver data
3250 */
3251static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3252{
3253 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003254 u32 vlnctrl;
3255
3256 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3257 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3258 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3259}
3260
3261/**
3262 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3263 * @adapter: driver data
3264 */
3265static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3266{
3267 struct ixgbe_hw *hw = &adapter->hw;
3268 u32 vlnctrl;
3269
3270 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3271 vlnctrl |= IXGBE_VLNCTRL_VFE;
3272 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3273 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3274}
3275
3276/**
3277 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3278 * @adapter: driver data
3279 */
3280static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3281{
3282 struct ixgbe_hw *hw = &adapter->hw;
3283 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003284 int i, j;
3285
3286 switch (hw->mac.type) {
3287 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003288 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3289 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003290 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3291 break;
3292 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003293 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003294 for (i = 0; i < adapter->num_rx_queues; i++) {
3295 j = adapter->rx_ring[i]->reg_idx;
3296 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3297 vlnctrl &= ~IXGBE_RXDCTL_VME;
3298 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3299 }
3300 break;
3301 default:
3302 break;
3303 }
3304}
3305
3306/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003307 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003308 * @adapter: driver data
3309 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003310static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003311{
3312 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003313 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003314 int i, j;
3315
3316 switch (hw->mac.type) {
3317 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003318 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3319 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003320 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3321 break;
3322 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003323 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003324 for (i = 0; i < adapter->num_rx_queues; i++) {
3325 j = adapter->rx_ring[i]->reg_idx;
3326 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3327 vlnctrl |= IXGBE_RXDCTL_VME;
3328 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3329 }
3330 break;
3331 default:
3332 break;
3333 }
3334}
3335
Auke Kok9a799d72007-09-15 14:07:45 -07003336static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3337{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003338 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003339
Jesse Grossf62bbb52010-10-20 13:56:10 +00003340 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3341
3342 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3343 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003344}
3345
3346/**
Alexander Duyck28500622010-06-15 09:25:48 +00003347 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3348 * @netdev: network interface device structure
3349 *
3350 * Writes unicast address list to the RAR table.
3351 * Returns: -ENOMEM on failure/insufficient address space
3352 * 0 on no addresses written
3353 * X on writing X addresses to the RAR table
3354 **/
3355static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3356{
3357 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3358 struct ixgbe_hw *hw = &adapter->hw;
3359 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003360 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003361 int count = 0;
3362
3363 /* return ENOMEM indicating insufficient memory for addresses */
3364 if (netdev_uc_count(netdev) > rar_entries)
3365 return -ENOMEM;
3366
3367 if (!netdev_uc_empty(netdev) && rar_entries) {
3368 struct netdev_hw_addr *ha;
3369 /* return error if we do not support writing to RAR table */
3370 if (!hw->mac.ops.set_rar)
3371 return -ENOMEM;
3372
3373 netdev_for_each_uc_addr(ha, netdev) {
3374 if (!rar_entries)
3375 break;
3376 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3377 vfn, IXGBE_RAH_AV);
3378 count++;
3379 }
3380 }
3381 /* write the addresses in reverse order to avoid write combining */
3382 for (; rar_entries > 0 ; rar_entries--)
3383 hw->mac.ops.clear_rar(hw, rar_entries);
3384
3385 return count;
3386}
3387
3388/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003389 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003390 * @netdev: network interface device structure
3391 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003392 * The set_rx_method entry point is called whenever the unicast/multicast
3393 * address list or the network interface flags are updated. This routine is
3394 * responsible for configuring the hardware for proper unicast, multicast and
3395 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003396 **/
Greg Rose7f870472010-01-09 02:25:29 +00003397void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003398{
3399 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3400 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003401 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3402 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003403
3404 /* Check for Promiscuous and All Multicast modes */
3405
3406 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3407
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003408 /* set all bits that we expect to always be set */
3409 fctrl |= IXGBE_FCTRL_BAM;
3410 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3411 fctrl |= IXGBE_FCTRL_PMCF;
3412
Alexander Duyck28500622010-06-15 09:25:48 +00003413 /* clear the bits we are changing the status of */
3414 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3415
Auke Kok9a799d72007-09-15 14:07:45 -07003416 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003417 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003418 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003419 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003420 /* don't hardware filter vlans in promisc mode */
3421 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003422 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003423 if (netdev->flags & IFF_ALLMULTI) {
3424 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003425 vmolr |= IXGBE_VMOLR_MPE;
3426 } else {
3427 /*
3428 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003429 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003430 * that we can at least receive multicast traffic
3431 */
3432 hw->mac.ops.update_mc_addr_list(hw, netdev);
3433 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003434 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003435 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003436 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003437 /*
3438 * Write addresses to available RAR registers, if there is not
3439 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003440 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003441 */
3442 count = ixgbe_write_uc_addr_list(netdev);
3443 if (count < 0) {
3444 fctrl |= IXGBE_FCTRL_UPE;
3445 vmolr |= IXGBE_VMOLR_ROPE;
3446 }
3447 }
3448
3449 if (adapter->num_vfs) {
3450 ixgbe_restore_vf_multicasts(adapter);
3451 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3452 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3453 IXGBE_VMOLR_ROPE);
3454 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003455 }
3456
3457 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003458
3459 if (netdev->features & NETIF_F_HW_VLAN_RX)
3460 ixgbe_vlan_strip_enable(adapter);
3461 else
3462 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003463}
3464
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003465static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3466{
3467 int q_idx;
3468 struct ixgbe_q_vector *q_vector;
3469 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3470
3471 /* legacy and MSI only use one vector */
3472 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3473 q_vectors = 1;
3474
3475 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003476 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003477 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003478 }
3479}
3480
3481static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3482{
3483 int q_idx;
3484 struct ixgbe_q_vector *q_vector;
3485 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3486
3487 /* legacy and MSI only use one vector */
3488 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3489 q_vectors = 1;
3490
3491 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003492 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003493 napi_disable(&q_vector->napi);
3494 }
3495}
3496
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003497#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003498/*
3499 * ixgbe_configure_dcb - Configure DCB hardware
3500 * @adapter: ixgbe adapter struct
3501 *
3502 * This is called by the driver on open to configure the DCB hardware.
3503 * This is also called by the gennetlink interface when reconfiguring
3504 * the DCB state.
3505 */
3506static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3507{
3508 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003509 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003510
Alexander Duyck67ebd792010-08-19 13:34:04 +00003511 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3512 if (hw->mac.type == ixgbe_mac_82598EB)
3513 netif_set_gso_max_size(adapter->netdev, 65536);
3514 return;
3515 }
3516
3517 if (hw->mac.type == ixgbe_mac_82598EB)
3518 netif_set_gso_max_size(adapter->netdev, 32768);
3519
Alexander Duyck2f90b862008-11-20 20:52:10 -08003520
Alexander Duyck2f90b862008-11-20 20:52:10 -08003521 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003522 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003523
Alexander Duyck2f90b862008-11-20 20:52:10 -08003524 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003525
John Fastabendb1208182011-10-15 05:00:10 +00003526#ifdef IXGBE_FCOE
3527 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3528 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3529#endif
3530
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003531 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003532 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003533 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3534 DCB_TX_CONFIG);
3535 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3536 DCB_RX_CONFIG);
3537 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003538 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3539 ixgbe_dcb_hw_ets(&adapter->hw,
3540 adapter->ixgbe_ieee_ets,
3541 max_frame);
3542 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3543 adapter->ixgbe_ieee_pfc->pfc_en,
3544 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003545 }
John Fastabend8187cd42011-02-23 05:58:08 +00003546
3547 /* Enable RSS Hash per TC */
3548 if (hw->mac.type != ixgbe_mac_82598EB) {
3549 int i;
3550 u32 reg = 0;
3551
3552 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3553 u8 msb = 0;
3554 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3555
3556 while (cnt >>= 1)
3557 msb++;
3558
3559 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3560 }
3561 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3562 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003563}
John Fastabend9da712d2011-08-23 03:14:22 +00003564#endif
3565
3566/* Additional bittime to account for IXGBE framing */
3567#define IXGBE_ETH_FRAMING 20
3568
3569/*
3570 * ixgbe_hpbthresh - calculate high water mark for flow control
3571 *
3572 * @adapter: board private structure to calculate for
3573 * @pb - packet buffer to calculate
3574 */
3575static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3576{
3577 struct ixgbe_hw *hw = &adapter->hw;
3578 struct net_device *dev = adapter->netdev;
3579 int link, tc, kb, marker;
3580 u32 dv_id, rx_pba;
3581
3582 /* Calculate max LAN frame size */
3583 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3584
3585#ifdef IXGBE_FCOE
3586 /* FCoE traffic class uses FCOE jumbo frames */
3587 if (dev->features & NETIF_F_FCOE_MTU) {
3588 int fcoe_pb = 0;
3589
3590#ifdef CONFIG_IXGBE_DCB
3591 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003592
3593#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003594 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3595 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3596 }
3597#endif
3598
3599 /* Calculate delay value for device */
3600 switch (hw->mac.type) {
3601 case ixgbe_mac_X540:
3602 dv_id = IXGBE_DV_X540(link, tc);
3603 break;
3604 default:
3605 dv_id = IXGBE_DV(link, tc);
3606 break;
3607 }
3608
3609 /* Loopback switch introduces additional latency */
3610 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3611 dv_id += IXGBE_B2BT(tc);
3612
3613 /* Delay value is calculated in bit times convert to KB */
3614 kb = IXGBE_BT2KB(dv_id);
3615 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3616
3617 marker = rx_pba - kb;
3618
3619 /* It is possible that the packet buffer is not large enough
3620 * to provide required headroom. In this case throw an error
3621 * to user and a do the best we can.
3622 */
3623 if (marker < 0) {
3624 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3625 "headroom to support flow control."
3626 "Decrease MTU or number of traffic classes\n", pb);
3627 marker = tc + 1;
3628 }
3629
3630 return marker;
3631}
3632
3633/*
3634 * ixgbe_lpbthresh - calculate low water mark for for flow control
3635 *
3636 * @adapter: board private structure to calculate for
3637 * @pb - packet buffer to calculate
3638 */
3639static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3640{
3641 struct ixgbe_hw *hw = &adapter->hw;
3642 struct net_device *dev = adapter->netdev;
3643 int tc;
3644 u32 dv_id;
3645
3646 /* Calculate max LAN frame size */
3647 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3648
3649 /* Calculate delay value for device */
3650 switch (hw->mac.type) {
3651 case ixgbe_mac_X540:
3652 dv_id = IXGBE_LOW_DV_X540(tc);
3653 break;
3654 default:
3655 dv_id = IXGBE_LOW_DV(tc);
3656 break;
3657 }
3658
3659 /* Delay value is calculated in bit times convert to KB */
3660 return IXGBE_BT2KB(dv_id);
3661}
3662
3663/*
3664 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3665 */
3666static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3667{
3668 struct ixgbe_hw *hw = &adapter->hw;
3669 int num_tc = netdev_get_num_tc(adapter->netdev);
3670 int i;
3671
3672 if (!num_tc)
3673 num_tc = 1;
3674
3675 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3676
3677 for (i = 0; i < num_tc; i++) {
3678 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3679
3680 /* Low water marks must not be larger than high water marks */
3681 if (hw->fc.low_water > hw->fc.high_water[i])
3682 hw->fc.low_water = 0;
3683 }
3684}
John Fastabend80605c652011-05-02 12:34:10 +00003685
3686static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3687{
John Fastabend80605c652011-05-02 12:34:10 +00003688 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003689 int hdrm;
3690 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003691
3692 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3693 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003694 hdrm = 32 << adapter->fdir_pballoc;
3695 else
3696 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003697
Alexander Duyckf7e10272011-07-21 00:40:35 +00003698 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003699 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003700}
3701
Alexander Duycke4911d52011-05-11 07:18:52 +00003702static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3703{
3704 struct ixgbe_hw *hw = &adapter->hw;
3705 struct hlist_node *node, *node2;
3706 struct ixgbe_fdir_filter *filter;
3707
3708 spin_lock(&adapter->fdir_perfect_lock);
3709
3710 if (!hlist_empty(&adapter->fdir_filter_list))
3711 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3712
3713 hlist_for_each_entry_safe(filter, node, node2,
3714 &adapter->fdir_filter_list, fdir_node) {
3715 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003716 &filter->filter,
3717 filter->sw_idx,
3718 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3719 IXGBE_FDIR_DROP_QUEUE :
3720 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003721 }
3722
3723 spin_unlock(&adapter->fdir_perfect_lock);
3724}
3725
Auke Kok9a799d72007-09-15 14:07:45 -07003726static void ixgbe_configure(struct ixgbe_adapter *adapter)
3727{
John Fastabend80605c652011-05-02 12:34:10 +00003728 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003729#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003730 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003731#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003732
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003733 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003734 ixgbe_restore_vlan(adapter);
3735
Yi Zoueacd73f2009-05-13 13:11:06 +00003736#ifdef IXGBE_FCOE
3737 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3738 ixgbe_configure_fcoe(adapter);
3739
3740#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003741 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003742 ixgbe_init_fdir_signature_82599(&adapter->hw,
3743 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003744 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3745 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3746 adapter->fdir_pballoc);
3747 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003748 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003749
Alexander Duyck933d41f2010-09-07 21:34:29 +00003750 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003751
Auke Kok9a799d72007-09-15 14:07:45 -07003752 ixgbe_configure_tx(adapter);
3753 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003754}
3755
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003756static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3757{
3758 switch (hw->phy.type) {
3759 case ixgbe_phy_sfp_avago:
3760 case ixgbe_phy_sfp_ftl:
3761 case ixgbe_phy_sfp_intel:
3762 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003763 case ixgbe_phy_sfp_passive_tyco:
3764 case ixgbe_phy_sfp_passive_unknown:
3765 case ixgbe_phy_sfp_active_unknown:
3766 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003767 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003768 case ixgbe_phy_nl:
3769 if (hw->mac.type == ixgbe_mac_82598EB)
3770 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003771 default:
3772 return false;
3773 }
3774}
3775
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003776/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003777 * ixgbe_sfp_link_config - set up SFP+ link
3778 * @adapter: pointer to private adapter struct
3779 **/
3780static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3781{
Alexander Duyck70864002011-04-27 09:13:56 +00003782 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003783 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003784 * is that an SFP was inserted/removed after the reset
3785 * but before SFP detection was enabled. As such the best
3786 * solution is to just start searching as soon as we start
3787 */
3788 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3789 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003790
Alexander Duyck70864002011-04-27 09:13:56 +00003791 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003792}
3793
3794/**
3795 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003796 * @hw: pointer to private hardware struct
3797 *
3798 * Returns 0 on success, negative on failure
3799 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003800static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003801{
3802 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003803 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003804 u32 ret = IXGBE_ERR_LINK_SETUP;
3805
3806 if (hw->mac.ops.check_link)
3807 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3808
3809 if (ret)
3810 goto link_cfg_out;
3811
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003812 autoneg = hw->phy.autoneg_advertised;
3813 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003814 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3815 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003816 if (ret)
3817 goto link_cfg_out;
3818
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003819 if (hw->mac.ops.setup_link)
3820 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003821link_cfg_out:
3822 return ret;
3823}
3824
Alexander Duycka34bcff2010-08-19 13:39:20 +00003825static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003826{
Auke Kok9a799d72007-09-15 14:07:45 -07003827 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003828 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003829
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003830 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003831 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3832 IXGBE_GPIE_OCD;
3833 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003834 /*
3835 * use EIAM to auto-mask when MSI-X interrupt is asserted
3836 * this saves a register write for every interrupt
3837 */
3838 switch (hw->mac.type) {
3839 case ixgbe_mac_82598EB:
3840 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3841 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003842 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003843 case ixgbe_mac_X540:
3844 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003845 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3846 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3847 break;
3848 }
3849 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003850 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3851 * specifically only auto mask tx and rx interrupts */
3852 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003853 }
3854
Alexander Duycka34bcff2010-08-19 13:39:20 +00003855 /* XXX: to interrupt immediately for EICS writes, enable this */
3856 /* gpie |= IXGBE_GPIE_EIMEN; */
3857
3858 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3859 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3860 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003861 }
3862
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003863 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003864 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3865 switch (adapter->hw.mac.type) {
3866 case ixgbe_mac_82599EB:
3867 gpie |= IXGBE_SDP0_GPIEN;
3868 break;
3869 case ixgbe_mac_X540:
3870 gpie |= IXGBE_EIMS_TS;
3871 break;
3872 default:
3873 break;
3874 }
3875 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003876
Alexander Duycka34bcff2010-08-19 13:39:20 +00003877 /* Enable fan failure interrupt */
3878 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003879 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003880
Don Skidmore2698b202011-04-13 07:01:52 +00003881 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003882 gpie |= IXGBE_SDP1_GPIEN;
3883 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003884 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003885
3886 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3887}
3888
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003889static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003890{
3891 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003892 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003893 u32 ctrl_ext;
3894
3895 ixgbe_get_hw_control(adapter);
3896 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003897
Auke Kok9a799d72007-09-15 14:07:45 -07003898 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3899 ixgbe_configure_msix(adapter);
3900 else
3901 ixgbe_configure_msi_and_legacy(adapter);
3902
Don Skidmorec6ecf392010-12-03 03:31:51 +00003903 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3904 if (hw->mac.ops.enable_tx_laser &&
3905 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003906 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003907 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003908 hw->mac.ops.enable_tx_laser(hw);
3909
Auke Kok9a799d72007-09-15 14:07:45 -07003910 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003911 ixgbe_napi_enable_all(adapter);
3912
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003913 if (ixgbe_is_sfp(hw)) {
3914 ixgbe_sfp_link_config(adapter);
3915 } else {
3916 err = ixgbe_non_sfp_link_config(hw);
3917 if (err)
3918 e_err(probe, "link_config FAILED %d\n", err);
3919 }
3920
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003921 /* clear any pending interrupts, may auto mask */
3922 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003923 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003924
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003925 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003926 * If this adapter has a fan, check to see if we had a failure
3927 * before we enabled the interrupt.
3928 */
3929 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3930 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3931 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003932 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003933 }
3934
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003935 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003936 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003937
Auke Kok9a799d72007-09-15 14:07:45 -07003938 /* bring the link up in the watchdog, this could race with our first
3939 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003940 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3941 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003942 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003943
3944 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3945 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3946 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3947 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003948}
3949
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003950void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3951{
3952 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003953 /* put off any impending NetWatchDogTimeout */
3954 adapter->netdev->trans_start = jiffies;
3955
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003956 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003957 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003958 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003959 /*
3960 * If SR-IOV enabled then wait a bit before bringing the adapter
3961 * back up to give the VFs time to respond to the reset. The
3962 * two second wait is based upon the watchdog timer cycle in
3963 * the VF driver.
3964 */
3965 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3966 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003967 ixgbe_up(adapter);
3968 clear_bit(__IXGBE_RESETTING, &adapter->state);
3969}
3970
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003971void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003972{
3973 /* hardware has been reset, we need to reload some things */
3974 ixgbe_configure(adapter);
3975
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003976 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003977}
3978
3979void ixgbe_reset(struct ixgbe_adapter *adapter)
3980{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003981 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003982 int err;
3983
Alexander Duyck70864002011-04-27 09:13:56 +00003984 /* lock SFP init bit to prevent race conditions with the watchdog */
3985 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3986 usleep_range(1000, 2000);
3987
3988 /* clear all SFP and link config related flags while holding SFP_INIT */
3989 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3990 IXGBE_FLAG2_SFP_NEEDS_RESET);
3991 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3992
Don Skidmore8ca783a2009-05-26 20:40:47 -07003993 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003994 switch (err) {
3995 case 0:
3996 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003997 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003998 break;
3999 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004000 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004001 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004002 case IXGBE_ERR_EEPROM_VERSION:
4003 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004004 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004005 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004006 "your hardware. If you are experiencing problems "
4007 "please contact your Intel or hardware "
4008 "representative who provided you with this "
4009 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004010 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004011 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004012 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004013 }
Auke Kok9a799d72007-09-15 14:07:45 -07004014
Alexander Duyck70864002011-04-27 09:13:56 +00004015 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4016
Auke Kok9a799d72007-09-15 14:07:45 -07004017 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004018 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4019 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004020}
4021
Auke Kok9a799d72007-09-15 14:07:45 -07004022/**
4023 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004024 * @rx_ring: ring to free buffers from
4025 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004026static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004027{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004028 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004029 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004030 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004031
Alexander Duyck84418e32010-08-19 13:40:54 +00004032 /* ring already cleared, nothing to do */
4033 if (!rx_ring->rx_buffer_info)
4034 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004035
Alexander Duyck84418e32010-08-19 13:40:54 +00004036 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004037 for (i = 0; i < rx_ring->count; i++) {
4038 struct ixgbe_rx_buffer *rx_buffer_info;
4039
4040 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4041 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004042 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004043 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004044 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004045 rx_buffer_info->dma = 0;
4046 }
4047 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004048 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004049 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004050 /* We need to clean up RSC frag lists */
4051 skb = ixgbe_merge_active_tail(skb);
4052 ixgbe_close_active_frag_list(skb);
4053 if (IXGBE_CB(skb)->delay_unmap) {
4054 dma_unmap_single(dev,
4055 IXGBE_CB(skb)->dma,
4056 rx_ring->rx_buf_len,
4057 DMA_FROM_DEVICE);
4058 IXGBE_CB(skb)->dma = 0;
4059 IXGBE_CB(skb)->delay_unmap = false;
4060 }
4061 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004062 }
4063 if (!rx_buffer_info->page)
4064 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004065 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004066 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004067 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004068 rx_buffer_info->page_dma = 0;
4069 }
Auke Kok9a799d72007-09-15 14:07:45 -07004070 put_page(rx_buffer_info->page);
4071 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004072 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004073 }
4074
4075 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4076 memset(rx_ring->rx_buffer_info, 0, size);
4077
4078 /* Zero out the descriptor ring */
4079 memset(rx_ring->desc, 0, rx_ring->size);
4080
4081 rx_ring->next_to_clean = 0;
4082 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004083}
4084
4085/**
4086 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004087 * @tx_ring: ring to be cleaned
4088 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004089static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004090{
4091 struct ixgbe_tx_buffer *tx_buffer_info;
4092 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004093 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004094
Alexander Duyck84418e32010-08-19 13:40:54 +00004095 /* ring already cleared, nothing to do */
4096 if (!tx_ring->tx_buffer_info)
4097 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004098
Alexander Duyck84418e32010-08-19 13:40:54 +00004099 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004100 for (i = 0; i < tx_ring->count; i++) {
4101 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004102 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004103 }
4104
4105 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4106 memset(tx_ring->tx_buffer_info, 0, size);
4107
4108 /* Zero out the descriptor ring */
4109 memset(tx_ring->desc, 0, tx_ring->size);
4110
4111 tx_ring->next_to_use = 0;
4112 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004113}
4114
4115/**
Auke Kok9a799d72007-09-15 14:07:45 -07004116 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4117 * @adapter: board private structure
4118 **/
4119static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4120{
4121 int i;
4122
4123 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004124 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004125}
4126
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004127/**
4128 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4129 * @adapter: board private structure
4130 **/
4131static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4132{
4133 int i;
4134
4135 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004136 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004137}
4138
Alexander Duycke4911d52011-05-11 07:18:52 +00004139static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4140{
4141 struct hlist_node *node, *node2;
4142 struct ixgbe_fdir_filter *filter;
4143
4144 spin_lock(&adapter->fdir_perfect_lock);
4145
4146 hlist_for_each_entry_safe(filter, node, node2,
4147 &adapter->fdir_filter_list, fdir_node) {
4148 hlist_del(&filter->fdir_node);
4149 kfree(filter);
4150 }
4151 adapter->fdir_filter_count = 0;
4152
4153 spin_unlock(&adapter->fdir_perfect_lock);
4154}
4155
Auke Kok9a799d72007-09-15 14:07:45 -07004156void ixgbe_down(struct ixgbe_adapter *adapter)
4157{
4158 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004159 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004160 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004161 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004162
4163 /* signal that we are down to the interrupt handler */
4164 set_bit(__IXGBE_DOWN, &adapter->state);
4165
4166 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004167 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4168 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004169
Yi Zou2d39d572011-01-06 14:29:56 +00004170 /* disable all enabled rx queues */
4171 for (i = 0; i < adapter->num_rx_queues; i++)
4172 /* this call also flushes the previous write */
4173 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4174
Don Skidmore032b4322011-03-18 09:32:53 +00004175 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004176
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004177 netif_tx_stop_all_queues(netdev);
4178
Alexander Duyck70864002011-04-27 09:13:56 +00004179 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004180 netif_carrier_off(netdev);
4181 netif_tx_disable(netdev);
4182
4183 ixgbe_irq_disable(adapter);
4184
4185 ixgbe_napi_disable_all(adapter);
4186
Alexander Duyckd034acf2011-04-27 09:25:34 +00004187 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4188 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004189 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4190
4191 del_timer_sync(&adapter->service_timer);
4192
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004193 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004194 /* Clear EITR Select mapping */
4195 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4196
4197 /* Mark all the VFs as inactive */
4198 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004199 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004200
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004201 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004202 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004203
Auke Kok9a799d72007-09-15 14:07:45 -07004204 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004205 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004206 }
4207
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004208 /* disable transmits in the hardware now that interrupts are off */
4209 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004210 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004211 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004212 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004213
4214 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004215 switch (hw->mac.type) {
4216 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004217 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004218 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004219 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4220 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004221 break;
4222 default:
4223 break;
4224 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004225
Paul Larson6f4a0e42008-06-24 17:00:56 -07004226 if (!pci_channel_offline(adapter->pdev))
4227 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004228
4229 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4230 if (hw->mac.ops.disable_tx_laser &&
4231 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004232 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004233 (hw->mac.type == ixgbe_mac_82599EB))))
4234 hw->mac.ops.disable_tx_laser(hw);
4235
Auke Kok9a799d72007-09-15 14:07:45 -07004236 ixgbe_clean_all_tx_rings(adapter);
4237 ixgbe_clean_all_rx_rings(adapter);
4238
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004239#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004240 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004241 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004242#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004243}
4244
Auke Kok9a799d72007-09-15 14:07:45 -07004245/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004246 * ixgbe_poll - NAPI Rx polling callback
4247 * @napi: structure for representing this polling device
4248 * @budget: how many packets driver is allowed to clean
4249 *
4250 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004251 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004252static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004253{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004254 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004255 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004256 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004257 struct ixgbe_ring *ring;
4258 int per_ring_budget;
4259 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004260
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004261#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004262 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4263 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004264#endif
4265
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004266 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4267 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004268
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004269 /* attempt to distribute budget to each queue fairly, but don't allow
4270 * the budget to go below 1 because we'll exit polling */
4271 if (q_vector->rx.count > 1)
4272 per_ring_budget = max(budget/q_vector->rx.count, 1);
4273 else
4274 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004275
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004276 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4277 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4278 per_ring_budget);
4279
4280 /* If all work not completed, return budget and keep polling */
4281 if (!clean_complete)
4282 return budget;
4283
4284 /* all work done, exit the polling mode */
4285 napi_complete(napi);
4286 if (adapter->rx_itr_setting & 1)
4287 ixgbe_set_itr(q_vector);
4288 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4289 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4290
4291 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004292}
4293
4294/**
4295 * ixgbe_tx_timeout - Respond to a Tx Hang
4296 * @netdev: network interface device structure
4297 **/
4298static void ixgbe_tx_timeout(struct net_device *netdev)
4299{
4300 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4301
4302 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004303 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004304}
4305
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004306/**
4307 * ixgbe_set_rss_queues: Allocate queues for RSS
4308 * @adapter: board private structure to initialize
4309 *
4310 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4311 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4312 *
4313 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004314static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4315{
4316 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004317 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004318
4319 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004320 f->mask = 0xF;
4321 adapter->num_rx_queues = f->indices;
4322 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004323 ret = true;
4324 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004325 ret = false;
4326 }
4327
4328 return ret;
4329}
4330
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004331/**
4332 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4333 * @adapter: board private structure to initialize
4334 *
4335 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4336 * to the original CPU that initiated the Tx session. This runs in addition
4337 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4338 * Rx load across CPUs using RSS.
4339 *
4340 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004341static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004342{
4343 bool ret = false;
4344 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4345
4346 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4347 f_fdir->mask = 0;
4348
4349 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004350 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4351 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004352 adapter->num_tx_queues = f_fdir->indices;
4353 adapter->num_rx_queues = f_fdir->indices;
4354 ret = true;
4355 } else {
4356 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004357 }
4358 return ret;
4359}
4360
Yi Zou0331a832009-05-17 12:33:52 +00004361#ifdef IXGBE_FCOE
4362/**
4363 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4364 * @adapter: board private structure to initialize
4365 *
4366 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4367 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4368 * rx queues out of the max number of rx queues, instead, it is used as the
4369 * index of the first rx queue used by FCoE.
4370 *
4371 **/
4372static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4373{
Yi Zou0331a832009-05-17 12:33:52 +00004374 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4375
John Fastabende5b64632011-03-08 03:44:52 +00004376 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4377 return false;
4378
John Fastabende901acd2011-04-26 07:26:08 +00004379 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004380
John Fastabende901acd2011-04-26 07:26:08 +00004381 adapter->num_rx_queues = 1;
4382 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004383
John Fastabende901acd2011-04-26 07:26:08 +00004384 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4385 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004386 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004387 ixgbe_set_fdir_queues(adapter);
4388 else
4389 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004390 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004391
John Fastabende901acd2011-04-26 07:26:08 +00004392 /* adding FCoE rx rings to the end */
4393 f->mask = adapter->num_rx_queues;
4394 adapter->num_rx_queues += f->indices;
4395 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004396
John Fastabende5b64632011-03-08 03:44:52 +00004397 return true;
4398}
4399#endif /* IXGBE_FCOE */
4400
John Fastabende901acd2011-04-26 07:26:08 +00004401/* Artificial max queue cap per traffic class in DCB mode */
4402#define DCB_QUEUE_CAP 8
4403
John Fastabende5b64632011-03-08 03:44:52 +00004404#ifdef CONFIG_IXGBE_DCB
4405static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4406{
John Fastabende901acd2011-04-26 07:26:08 +00004407 int per_tc_q, q, i, offset = 0;
4408 struct net_device *dev = adapter->netdev;
4409 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004410
John Fastabende901acd2011-04-26 07:26:08 +00004411 if (!tcs)
4412 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004413
John Fastabende901acd2011-04-26 07:26:08 +00004414 /* Map queue offset and counts onto allocated tx queues */
4415 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4416 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004417
John Fastabend8b1c0b22011-05-03 02:26:48 +00004418 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004419 netdev_set_tc_queue(dev, i, q, offset);
4420 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004421 }
4422
John Fastabende901acd2011-04-26 07:26:08 +00004423 adapter->num_tx_queues = q * tcs;
4424 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004425
4426#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004427 /* FCoE enabled queues require special configuration indexed
4428 * by feature specific indices and mask. Here we map FCoE
4429 * indices onto the DCB queue pairs allowing FCoE to own
4430 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004431 */
John Fastabende901acd2011-04-26 07:26:08 +00004432 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4433 int tc;
4434 struct ixgbe_ring_feature *f =
4435 &adapter->ring_feature[RING_F_FCOE];
4436
4437 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4438 f->indices = dev->tc_to_txq[tc].count;
4439 f->mask = dev->tc_to_txq[tc].offset;
4440 }
John Fastabende5b64632011-03-08 03:44:52 +00004441#endif
4442
John Fastabende901acd2011-04-26 07:26:08 +00004443 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004444}
John Fastabende5b64632011-03-08 03:44:52 +00004445#endif
Yi Zou0331a832009-05-17 12:33:52 +00004446
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004447/**
4448 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4449 * @adapter: board private structure to initialize
4450 *
4451 * IOV doesn't actually use anything, so just NAK the
4452 * request for now and let the other queue routines
4453 * figure out what to do.
4454 */
4455static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4456{
4457 return false;
4458}
4459
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004460/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004461 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004462 * @adapter: board private structure to initialize
4463 *
4464 * This is the top level queue allocation routine. The order here is very
4465 * important, starting with the "most" number of features turned on at once,
4466 * and ending with the smallest set of features. This way large combinations
4467 * can be allocated if they're turned on, and smaller combinations are the
4468 * fallthrough conditions.
4469 *
4470 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004471static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004472{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004473 /* Start with base case */
4474 adapter->num_rx_queues = 1;
4475 adapter->num_tx_queues = 1;
4476 adapter->num_rx_pools = adapter->num_rx_queues;
4477 adapter->num_rx_queues_per_pool = 1;
4478
4479 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004480 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004481
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004482#ifdef CONFIG_IXGBE_DCB
4483 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004484 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004485
4486#endif
John Fastabende5b64632011-03-08 03:44:52 +00004487#ifdef IXGBE_FCOE
4488 if (ixgbe_set_fcoe_queues(adapter))
4489 goto done;
4490
4491#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004492 if (ixgbe_set_fdir_queues(adapter))
4493 goto done;
4494
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004495 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004496 goto done;
4497
4498 /* fallback to base case */
4499 adapter->num_rx_queues = 1;
4500 adapter->num_tx_queues = 1;
4501
4502done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004503 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004504 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004505 return netif_set_real_num_rx_queues(adapter->netdev,
4506 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004507}
4508
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004509static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004510 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004511{
4512 int err, vector_threshold;
4513
4514 /* We'll want at least 3 (vector_threshold):
4515 * 1) TxQ[0] Cleanup
4516 * 2) RxQ[0] Cleanup
4517 * 3) Other (Link Status Change, etc.)
4518 * 4) TCP Timer (optional)
4519 */
4520 vector_threshold = MIN_MSIX_COUNT;
4521
4522 /* The more we get, the more we will assign to Tx/Rx Cleanup
4523 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4524 * Right now, we simply care about how many we'll get; we'll
4525 * set them up later while requesting irq's.
4526 */
4527 while (vectors >= vector_threshold) {
4528 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004529 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004530 if (!err) /* Success in acquiring all requested vectors. */
4531 break;
4532 else if (err < 0)
4533 vectors = 0; /* Nasty failure, quit now */
4534 else /* err == number of vectors we should try again with */
4535 vectors = err;
4536 }
4537
4538 if (vectors < vector_threshold) {
4539 /* Can't allocate enough MSI-X interrupts? Oh well.
4540 * This just means we'll go with either a single MSI
4541 * vector or fall back to legacy interrupts.
4542 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004543 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4544 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004545 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4546 kfree(adapter->msix_entries);
4547 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004548 } else {
4549 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004550 /*
4551 * Adjust for only the vectors we'll use, which is minimum
4552 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4553 * vectors we were allocated.
4554 */
4555 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004556 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004557 }
4558}
4559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004560/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004561 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004562 * @adapter: board private structure to initialize
4563 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004564 * Cache the descriptor ring offsets for RSS to the assigned rings.
4565 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004566 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004567static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004568{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004569 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004570
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004571 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4572 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004573
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004574 for (i = 0; i < adapter->num_rx_queues; i++)
4575 adapter->rx_ring[i]->reg_idx = i;
4576 for (i = 0; i < adapter->num_tx_queues; i++)
4577 adapter->tx_ring[i]->reg_idx = i;
4578
4579 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004580}
4581
4582#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004583
4584/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004585static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4586 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004587{
4588 struct net_device *dev = adapter->netdev;
4589 struct ixgbe_hw *hw = &adapter->hw;
4590 u8 num_tcs = netdev_get_num_tc(dev);
4591
4592 *tx = 0;
4593 *rx = 0;
4594
4595 switch (hw->mac.type) {
4596 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004597 *tx = tc << 2;
4598 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004599 break;
4600 case ixgbe_mac_82599EB:
4601 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004602 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004603 if (tc < 3) {
4604 *tx = tc << 5;
4605 *rx = tc << 4;
4606 } else if (tc < 5) {
4607 *tx = ((tc + 2) << 4);
4608 *rx = tc << 4;
4609 } else if (tc < num_tcs) {
4610 *tx = ((tc + 8) << 3);
4611 *rx = tc << 4;
4612 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004613 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004614 *rx = tc << 5;
4615 switch (tc) {
4616 case 0:
4617 *tx = 0;
4618 break;
4619 case 1:
4620 *tx = 64;
4621 break;
4622 case 2:
4623 *tx = 96;
4624 break;
4625 case 3:
4626 *tx = 112;
4627 break;
4628 default:
4629 break;
4630 }
4631 }
4632 break;
4633 default:
4634 break;
4635 }
4636}
4637
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004638/**
4639 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4640 * @adapter: board private structure to initialize
4641 *
4642 * Cache the descriptor ring offsets for DCB to the assigned rings.
4643 *
4644 **/
4645static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4646{
John Fastabende5b64632011-03-08 03:44:52 +00004647 struct net_device *dev = adapter->netdev;
4648 int i, j, k;
4649 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004650
John Fastabend8b1c0b22011-05-03 02:26:48 +00004651 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004652 return false;
4653
John Fastabende5b64632011-03-08 03:44:52 +00004654 for (i = 0, k = 0; i < num_tcs; i++) {
4655 unsigned int tx_s, rx_s;
4656 u16 count = dev->tc_to_txq[i].count;
4657
4658 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4659 for (j = 0; j < count; j++, k++) {
4660 adapter->tx_ring[k]->reg_idx = tx_s + j;
4661 adapter->rx_ring[k]->reg_idx = rx_s + j;
4662 adapter->tx_ring[k]->dcb_tc = i;
4663 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004664 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004665 }
John Fastabende5b64632011-03-08 03:44:52 +00004666
4667 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004668}
4669#endif
4670
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004671/**
4672 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4673 * @adapter: board private structure to initialize
4674 *
4675 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4676 *
4677 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004678static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004679{
4680 int i;
4681 bool ret = false;
4682
Alexander Duyck03ecf912011-05-20 07:36:17 +00004683 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4684 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004685 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004686 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004687 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004688 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004689 ret = true;
4690 }
4691
4692 return ret;
4693}
4694
Yi Zou0331a832009-05-17 12:33:52 +00004695#ifdef IXGBE_FCOE
4696/**
4697 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4698 * @adapter: board private structure to initialize
4699 *
4700 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4701 *
4702 */
4703static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4704{
Yi Zou0331a832009-05-17 12:33:52 +00004705 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004706 int i;
4707 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004708
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004709 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4710 return false;
4711
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004712 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004713 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004714 ixgbe_cache_ring_fdir(adapter);
4715 else
4716 ixgbe_cache_ring_rss(adapter);
4717
4718 fcoe_rx_i = f->mask;
4719 fcoe_tx_i = f->mask;
4720 }
4721 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4722 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4723 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4724 }
4725 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004726}
4727
4728#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004729/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004730 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4731 * @adapter: board private structure to initialize
4732 *
4733 * SR-IOV doesn't use any descriptor rings but changes the default if
4734 * no other mapping is used.
4735 *
4736 */
4737static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4738{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004739 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4740 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004741 if (adapter->num_vfs)
4742 return true;
4743 else
4744 return false;
4745}
4746
4747/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004748 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4749 * @adapter: board private structure to initialize
4750 *
4751 * Once we know the feature-set enabled for the device, we'll cache
4752 * the register offset the descriptor ring is assigned to.
4753 *
4754 * Note, the order the various feature calls is important. It must start with
4755 * the "most" features enabled at the same time, then trickle down to the
4756 * least amount of features turned on at once.
4757 **/
4758static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4759{
4760 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004761 adapter->rx_ring[0]->reg_idx = 0;
4762 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004763
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004764 if (ixgbe_cache_ring_sriov(adapter))
4765 return;
4766
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004767#ifdef CONFIG_IXGBE_DCB
4768 if (ixgbe_cache_ring_dcb(adapter))
4769 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004770#endif
John Fastabende5b64632011-03-08 03:44:52 +00004771
4772#ifdef IXGBE_FCOE
4773 if (ixgbe_cache_ring_fcoe(adapter))
4774 return;
4775#endif /* IXGBE_FCOE */
4776
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004777 if (ixgbe_cache_ring_fdir(adapter))
4778 return;
4779
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004780 if (ixgbe_cache_ring_rss(adapter))
4781 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004782}
4783
Auke Kok9a799d72007-09-15 14:07:45 -07004784/**
4785 * ixgbe_alloc_queues - Allocate memory for all rings
4786 * @adapter: board private structure to initialize
4787 *
4788 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004789 * number of queues at compile-time. The polling_netdev array is
4790 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004791 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004792static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004793{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004794 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004795
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004796 if (nid < 0 || !node_online(nid))
4797 nid = first_online_node;
4798
4799 for (; tx < adapter->num_tx_queues; tx++) {
4800 struct ixgbe_ring *ring;
4801
4802 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004803 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004804 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004805 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004806 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004807 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004808 ring->queue_index = tx;
4809 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004810 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004811 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004812
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004813 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004814 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004815
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004816 for (; rx < adapter->num_rx_queues; rx++) {
4817 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004818
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004819 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004820 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004821 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004822 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004823 goto err_allocation;
4824 ring->count = adapter->rx_ring_count;
4825 ring->queue_index = rx;
4826 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004827 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004828 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004829
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004830 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004831 }
4832
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004833 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004834
4835 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004836
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004837err_allocation:
4838 while (tx)
4839 kfree(adapter->tx_ring[--tx]);
4840
4841 while (rx)
4842 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004843 return -ENOMEM;
4844}
4845
4846/**
4847 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4848 * @adapter: board private structure to initialize
4849 *
4850 * Attempt to configure the interrupts using the best available
4851 * capabilities of the hardware and the kernel.
4852 **/
Al Virofeea6a52008-11-27 15:34:07 -08004853static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004854{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004855 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004856 int err = 0;
4857 int vector, v_budget;
4858
4859 /*
4860 * It's easy to be greedy for MSI-X vectors, but it really
4861 * doesn't do us much good if we have a lot more vectors
4862 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004863 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004864 */
4865 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004866 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867
4868 /*
4869 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004870 * hw.mac->max_msix_vectors vectors. With features
4871 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4872 * descriptor queues supported by our device. Thus, we cap it off in
4873 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004874 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004875 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004876
4877 /* A failure in MSI-X entry allocation isn't fatal, but it does
4878 * mean we disable MSI-X capabilities of the adapter. */
4879 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004880 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004881 if (adapter->msix_entries) {
4882 for (vector = 0; vector < v_budget; vector++)
4883 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004884
Alexander Duyck7a921c92009-05-06 10:43:28 +00004885 ixgbe_acquire_msix_vectors(adapter, v_budget);
4886
4887 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4888 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004889 }
David S. Miller26d27842010-05-03 15:18:22 -07004890
Alexander Duyck7a921c92009-05-06 10:43:28 +00004891 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4892 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004893 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004894 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004895 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004896 "queues are disabled. Disabling Flow Director\n");
4897 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004898 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004899 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004900 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4901 ixgbe_disable_sriov(adapter);
4902
Ben Hutchings847f53f2010-09-27 08:28:56 +00004903 err = ixgbe_set_num_queues(adapter);
4904 if (err)
4905 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004906
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004907 err = pci_enable_msi(adapter->pdev);
4908 if (!err) {
4909 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4910 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004911 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4912 "Unable to allocate MSI interrupt, "
4913 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004914 /* reset err */
4915 err = 0;
4916 }
4917
4918out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004919 return err;
4920}
4921
Alexander Duyck7a921c92009-05-06 10:43:28 +00004922/**
4923 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4924 * @adapter: board private structure to initialize
4925 *
4926 * We allocate one q_vector per queue interrupt. If allocation fails we
4927 * return -ENOMEM.
4928 **/
4929static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4930{
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004931 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004932 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004933
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004934 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004935 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004936 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004937 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004938
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004939 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004940 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004941 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004942 if (!q_vector)
4943 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004944 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004945 if (!q_vector)
4946 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004947
Alexander Duyck7a921c92009-05-06 10:43:28 +00004948 q_vector->adapter = adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004949 q_vector->v_idx = v_idx;
4950
Alexander Duyck207867f2011-07-15 03:05:37 +00004951 /* Allocate the affinity_hint cpumask, configure the mask */
4952 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
4953 goto err_out;
4954 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004955 netif_napi_add(adapter->netdev, &q_vector->napi,
4956 ixgbe_poll, 64);
4957 adapter->q_vector[v_idx] = q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004958 }
4959
4960 return 0;
4961
4962err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004963 while (v_idx) {
4964 v_idx--;
4965 q_vector = adapter->q_vector[v_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004966 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00004967 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004968 kfree(q_vector);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004969 adapter->q_vector[v_idx] = NULL;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004970 }
4971 return -ENOMEM;
4972}
4973
4974/**
4975 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4976 * @adapter: board private structure to initialize
4977 *
4978 * This function frees the memory allocated to the q_vectors. In addition if
4979 * NAPI is enabled it will delete any references to the NAPI struct prior
4980 * to freeing the q_vector.
4981 **/
4982static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4983{
Alexander Duyck207867f2011-07-15 03:05:37 +00004984 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004985
Alexander Duyck91281fd2009-06-04 16:00:27 +00004986 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004987 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004988 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004989 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004990
Alexander Duyck207867f2011-07-15 03:05:37 +00004991 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
4992 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
4993 adapter->q_vector[v_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004994 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00004995 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004996 kfree(q_vector);
4997 }
4998}
4999
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005000static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005001{
5002 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5003 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5004 pci_disable_msix(adapter->pdev);
5005 kfree(adapter->msix_entries);
5006 adapter->msix_entries = NULL;
5007 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5008 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5009 pci_disable_msi(adapter->pdev);
5010 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005011}
5012
5013/**
5014 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5015 * @adapter: board private structure to initialize
5016 *
5017 * We determine which interrupt scheme to use based on...
5018 * - Kernel support (MSI, MSI-X)
5019 * - which can be user-defined (via MODULE_PARAM)
5020 * - Hardware queue count (num_*_queues)
5021 * - defined by miscellaneous hardware support/features (RSS, etc.)
5022 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005023int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005024{
5025 int err;
5026
5027 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005028 err = ixgbe_set_num_queues(adapter);
5029 if (err)
5030 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005031
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005032 err = ixgbe_set_interrupt_capability(adapter);
5033 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005034 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005035 goto err_set_interrupt;
5036 }
5037
Alexander Duyck7a921c92009-05-06 10:43:28 +00005038 err = ixgbe_alloc_q_vectors(adapter);
5039 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005040 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041 goto err_alloc_q_vectors;
5042 }
5043
5044 err = ixgbe_alloc_queues(adapter);
5045 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005046 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005047 goto err_alloc_queues;
5048 }
5049
Emil Tantilov849c4542010-06-03 16:53:41 +00005050 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005051 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5052 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005053
5054 set_bit(__IXGBE_DOWN, &adapter->state);
5055
5056 return 0;
5057
Alexander Duyck7a921c92009-05-06 10:43:28 +00005058err_alloc_queues:
5059 ixgbe_free_q_vectors(adapter);
5060err_alloc_q_vectors:
5061 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005062err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005063 return err;
5064}
5065
5066/**
5067 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5068 * @adapter: board private structure to clear interrupt scheme on
5069 *
5070 * We go through and clear interrupt specific resources and reset the structure
5071 * to pre-load conditions
5072 **/
5073void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5074{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005075 int i;
5076
5077 for (i = 0; i < adapter->num_tx_queues; i++) {
5078 kfree(adapter->tx_ring[i]);
5079 adapter->tx_ring[i] = NULL;
5080 }
5081 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005082 struct ixgbe_ring *ring = adapter->rx_ring[i];
5083
5084 /* ixgbe_get_stats64() might access this ring, we must wait
5085 * a grace period before freeing it.
5086 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005087 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005088 adapter->rx_ring[i] = NULL;
5089 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005090
Don Skidmoreb8eb3a102010-12-01 20:54:53 +00005091 adapter->num_tx_queues = 0;
5092 adapter->num_rx_queues = 0;
5093
Alexander Duyck7a921c92009-05-06 10:43:28 +00005094 ixgbe_free_q_vectors(adapter);
5095 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005096}
5097
5098/**
5099 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5100 * @adapter: board private structure to initialize
5101 *
5102 * ixgbe_sw_init initializes the Adapter private data structure.
5103 * Fields are initialized based on PCI device information and
5104 * OS network device settings (MTU size).
5105 **/
5106static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5107{
5108 struct ixgbe_hw *hw = &adapter->hw;
5109 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005110 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005111#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005112 int j;
5113 struct tc_configuration *tc;
5114#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005115
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005116 /* PCI config space info */
5117
5118 hw->vendor_id = pdev->vendor;
5119 hw->device_id = pdev->device;
5120 hw->revision_id = pdev->revision;
5121 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5122 hw->subsystem_device_id = pdev->subsystem_device;
5123
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005124 /* Set capability flags */
5125 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5126 adapter->ring_feature[RING_F_RSS].indices = rss;
5127 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005128 switch (hw->mac.type) {
5129 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005130 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5131 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005132 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005133 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005134 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005135 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5136 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005137 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005138 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5139 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005140 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5141 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005142 /* Flow Director hash filters enabled */
5143 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5144 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005145 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005146 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005147 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005148#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005149 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5150 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5151 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005152#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005153 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005154 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005155#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005156#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005157 break;
5158 default:
5159 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005160 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005161
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005162 /* n-tuple support exists, always init our spinlock */
5163 spin_lock_init(&adapter->fdir_perfect_lock);
5164
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005165#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005166 switch (hw->mac.type) {
5167 case ixgbe_mac_X540:
5168 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5169 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5170 break;
5171 default:
5172 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5173 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5174 break;
5175 }
5176
Alexander Duyck2f90b862008-11-20 20:52:10 -08005177 /* Configure DCB traffic classes */
5178 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5179 tc = &adapter->dcb_cfg.tc_config[j];
5180 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5181 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5182 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5183 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5184 tc->dcb_pfc = pfc_disabled;
5185 }
John Fastabend4de2a022011-09-27 03:52:01 +00005186
5187 /* Initialize default user to priority mapping, UPx->TC0 */
5188 tc = &adapter->dcb_cfg.tc_config[0];
5189 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5190 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5191
Alexander Duyck2f90b862008-11-20 20:52:10 -08005192 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5193 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005194 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005195 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005196 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005197 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005198 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005199
5200#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005201
5202 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005203 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005204 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005205#ifdef CONFIG_DCB
5206 adapter->last_lfc_mode = hw->fc.current_mode;
5207#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005208 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005209 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5210 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005211 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005212
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005213 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005214 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005215 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005216
5217 /* set defaults for eitr in MegaBytes */
5218 adapter->eitr_low = 10;
5219 adapter->eitr_high = 20;
5220
5221 /* set default ring sizes */
5222 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5223 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5224
Alexander Duyckbd198052011-06-11 01:45:08 +00005225 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005226 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005227
Auke Kok9a799d72007-09-15 14:07:45 -07005228 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005229 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005230 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005231 return -EIO;
5232 }
5233
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005234 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005235 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5236
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005237 /* get assigned NUMA node */
5238 adapter->node = dev_to_node(&pdev->dev);
5239
Auke Kok9a799d72007-09-15 14:07:45 -07005240 set_bit(__IXGBE_DOWN, &adapter->state);
5241
5242 return 0;
5243}
5244
5245/**
5246 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005247 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005248 *
5249 * Return 0 on success, negative on failure
5250 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005251int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005252{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005253 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005254 int size;
5255
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005256 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005257 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005258 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005259 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005260 if (!tx_ring->tx_buffer_info)
5261 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005262
5263 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005264 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005265 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005266
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005267 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005268 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005269 if (!tx_ring->desc)
5270 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005271
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005272 tx_ring->next_to_use = 0;
5273 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005274 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005275
5276err:
5277 vfree(tx_ring->tx_buffer_info);
5278 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005279 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005280 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005281}
5282
5283/**
Alexander Duyck69888672008-09-11 20:05:39 -07005284 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5285 * @adapter: board private structure
5286 *
5287 * If this function returns with an error, then it's possible one or
5288 * more of the rings is populated (while the rest are not). It is the
5289 * callers duty to clean those orphaned rings.
5290 *
5291 * Return 0 on success, negative on failure
5292 **/
5293static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5294{
5295 int i, err = 0;
5296
5297 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005298 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005299 if (!err)
5300 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005301 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005302 break;
5303 }
5304
5305 return err;
5306}
5307
5308/**
Auke Kok9a799d72007-09-15 14:07:45 -07005309 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005310 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005311 *
5312 * Returns 0 on success, negative on failure
5313 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005314int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005315{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005316 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005317 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005318
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005319 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005320 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005321 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005322 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005323 if (!rx_ring->rx_buffer_info)
5324 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005325
Auke Kok9a799d72007-09-15 14:07:45 -07005326 /* Round up to nearest 4K */
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005327 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5328 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005329
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005330 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005331 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005332
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005333 if (!rx_ring->desc)
5334 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005335
Jesse Brandeburg3a5810732008-08-26 04:27:08 -07005336 rx_ring->next_to_clean = 0;
5337 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005338
5339 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005340err:
5341 vfree(rx_ring->rx_buffer_info);
5342 rx_ring->rx_buffer_info = NULL;
5343 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005344 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005345}
5346
5347/**
Alexander Duyck69888672008-09-11 20:05:39 -07005348 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5349 * @adapter: board private structure
5350 *
5351 * If this function returns with an error, then it's possible one or
5352 * more of the rings is populated (while the rest are not). It is the
5353 * callers duty to clean those orphaned rings.
5354 *
5355 * Return 0 on success, negative on failure
5356 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005357static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5358{
5359 int i, err = 0;
5360
5361 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005362 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005363 if (!err)
5364 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005365 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005366 break;
5367 }
5368
5369 return err;
5370}
5371
5372/**
Auke Kok9a799d72007-09-15 14:07:45 -07005373 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005374 * @tx_ring: Tx descriptor ring for a specific queue
5375 *
5376 * Free all transmit software resources
5377 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005378void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005379{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005380 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005381
5382 vfree(tx_ring->tx_buffer_info);
5383 tx_ring->tx_buffer_info = NULL;
5384
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005385 /* if not set, then don't free */
5386 if (!tx_ring->desc)
5387 return;
5388
5389 dma_free_coherent(tx_ring->dev, tx_ring->size,
5390 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005391
5392 tx_ring->desc = NULL;
5393}
5394
5395/**
5396 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5397 * @adapter: board private structure
5398 *
5399 * Free all transmit software resources
5400 **/
5401static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5402{
5403 int i;
5404
5405 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005406 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005407 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005408}
5409
5410/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005411 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005412 * @rx_ring: ring to clean the resources from
5413 *
5414 * Free all receive software resources
5415 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005416void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005417{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005418 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005419
5420 vfree(rx_ring->rx_buffer_info);
5421 rx_ring->rx_buffer_info = NULL;
5422
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005423 /* if not set, then don't free */
5424 if (!rx_ring->desc)
5425 return;
5426
5427 dma_free_coherent(rx_ring->dev, rx_ring->size,
5428 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005429
5430 rx_ring->desc = NULL;
5431}
5432
5433/**
5434 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5435 * @adapter: board private structure
5436 *
5437 * Free all receive software resources
5438 **/
5439static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5440{
5441 int i;
5442
5443 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005444 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005445 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005446}
5447
5448/**
Auke Kok9a799d72007-09-15 14:07:45 -07005449 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5450 * @netdev: network interface device structure
5451 * @new_mtu: new value for maximum frame size
5452 *
5453 * Returns 0 on success, negative on failure
5454 **/
5455static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5456{
5457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005458 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005459 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5460
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005461 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005462 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5463 hw->mac.type != ixgbe_mac_X540) {
5464 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5465 return -EINVAL;
5466 } else {
5467 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5468 return -EINVAL;
5469 }
Auke Kok9a799d72007-09-15 14:07:45 -07005470
Emil Tantilov396e7992010-07-01 20:05:12 +00005471 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005472 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005473 netdev->mtu = new_mtu;
5474
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005475 if (netif_running(netdev))
5476 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005477
5478 return 0;
5479}
5480
5481/**
5482 * ixgbe_open - Called when a network interface is made active
5483 * @netdev: network interface device structure
5484 *
5485 * Returns 0 on success, negative value on failure
5486 *
5487 * The open entry point is called when a network interface is made
5488 * active by the system (IFF_UP). At this point all resources needed
5489 * for transmit and receive operations are allocated, the interrupt
5490 * handler is registered with the OS, the watchdog timer is started,
5491 * and the stack is notified that the interface is ready.
5492 **/
5493static int ixgbe_open(struct net_device *netdev)
5494{
5495 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5496 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005497
Auke Kok4bebfaa2008-02-11 09:26:01 -08005498 /* disallow open during test */
5499 if (test_bit(__IXGBE_TESTING, &adapter->state))
5500 return -EBUSY;
5501
Jesse Brandeburg54386462009-04-17 20:44:27 +00005502 netif_carrier_off(netdev);
5503
Auke Kok9a799d72007-09-15 14:07:45 -07005504 /* allocate transmit descriptors */
5505 err = ixgbe_setup_all_tx_resources(adapter);
5506 if (err)
5507 goto err_setup_tx;
5508
Auke Kok9a799d72007-09-15 14:07:45 -07005509 /* allocate receive descriptors */
5510 err = ixgbe_setup_all_rx_resources(adapter);
5511 if (err)
5512 goto err_setup_rx;
5513
5514 ixgbe_configure(adapter);
5515
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005516 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005517 if (err)
5518 goto err_req_irq;
5519
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005520 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005521
5522 return 0;
5523
Auke Kok9a799d72007-09-15 14:07:45 -07005524err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005525err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005526 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005527err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005528 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005529 ixgbe_reset(adapter);
5530
5531 return err;
5532}
5533
5534/**
5535 * ixgbe_close - Disables a network interface
5536 * @netdev: network interface device structure
5537 *
5538 * Returns 0, this is not allowed to fail
5539 *
5540 * The close entry point is called when an interface is de-activated
5541 * by the OS. The hardware is still under the drivers control, but
5542 * needs to be disabled. A global MAC reset is issued to stop the
5543 * hardware, and all transmit and receive resources are freed.
5544 **/
5545static int ixgbe_close(struct net_device *netdev)
5546{
5547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005548
5549 ixgbe_down(adapter);
5550 ixgbe_free_irq(adapter);
5551
Alexander Duycke4911d52011-05-11 07:18:52 +00005552 ixgbe_fdir_filter_exit(adapter);
5553
Auke Kok9a799d72007-09-15 14:07:45 -07005554 ixgbe_free_all_tx_resources(adapter);
5555 ixgbe_free_all_rx_resources(adapter);
5556
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005557 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005558
5559 return 0;
5560}
5561
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005562#ifdef CONFIG_PM
5563static int ixgbe_resume(struct pci_dev *pdev)
5564{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005565 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5566 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005567 u32 err;
5568
5569 pci_set_power_state(pdev, PCI_D0);
5570 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005571 /*
5572 * pci_restore_state clears dev->state_saved so call
5573 * pci_save_state to restore it.
5574 */
5575 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005576
5577 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005578 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005579 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005580 return err;
5581 }
5582 pci_set_master(pdev);
5583
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005584 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005585
5586 err = ixgbe_init_interrupt_scheme(adapter);
5587 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005588 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005589 return err;
5590 }
5591
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005592 ixgbe_reset(adapter);
5593
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005594 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5595
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005596 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005597 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005598 if (err)
5599 return err;
5600 }
5601
5602 netif_device_attach(netdev);
5603
5604 return 0;
5605}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005606#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005607
5608static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005609{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005610 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5611 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005612 struct ixgbe_hw *hw = &adapter->hw;
5613 u32 ctrl, fctrl;
5614 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005615#ifdef CONFIG_PM
5616 int retval = 0;
5617#endif
5618
5619 netif_device_detach(netdev);
5620
5621 if (netif_running(netdev)) {
5622 ixgbe_down(adapter);
5623 ixgbe_free_irq(adapter);
5624 ixgbe_free_all_tx_resources(adapter);
5625 ixgbe_free_all_rx_resources(adapter);
5626 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005627
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005628 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005629#ifdef CONFIG_DCB
5630 kfree(adapter->ixgbe_ieee_pfc);
5631 kfree(adapter->ixgbe_ieee_ets);
5632#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005633
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005634#ifdef CONFIG_PM
5635 retval = pci_save_state(pdev);
5636 if (retval)
5637 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005638
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005639#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005640 if (wufc) {
5641 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005642
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005643 /* turn on all-multi mode if wake on multicast is enabled */
5644 if (wufc & IXGBE_WUFC_MC) {
5645 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5646 fctrl |= IXGBE_FCTRL_MPE;
5647 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5648 }
5649
5650 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5651 ctrl |= IXGBE_CTRL_GIO_DIS;
5652 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5653
5654 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5655 } else {
5656 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5657 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5658 }
5659
Alexander Duyckbd508172010-11-16 19:27:03 -08005660 switch (hw->mac.type) {
5661 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005662 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005663 break;
5664 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005665 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005666 pci_wake_from_d3(pdev, !!wufc);
5667 break;
5668 default:
5669 break;
5670 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005671
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005672 *enable_wake = !!wufc;
5673
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005674 ixgbe_release_hw_control(adapter);
5675
5676 pci_disable_device(pdev);
5677
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005678 return 0;
5679}
5680
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005681#ifdef CONFIG_PM
5682static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5683{
5684 int retval;
5685 bool wake;
5686
5687 retval = __ixgbe_shutdown(pdev, &wake);
5688 if (retval)
5689 return retval;
5690
5691 if (wake) {
5692 pci_prepare_to_sleep(pdev);
5693 } else {
5694 pci_wake_from_d3(pdev, false);
5695 pci_set_power_state(pdev, PCI_D3hot);
5696 }
5697
5698 return 0;
5699}
5700#endif /* CONFIG_PM */
5701
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005702static void ixgbe_shutdown(struct pci_dev *pdev)
5703{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005704 bool wake;
5705
5706 __ixgbe_shutdown(pdev, &wake);
5707
5708 if (system_state == SYSTEM_POWER_OFF) {
5709 pci_wake_from_d3(pdev, wake);
5710 pci_set_power_state(pdev, PCI_D3hot);
5711 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005712}
5713
5714/**
Auke Kok9a799d72007-09-15 14:07:45 -07005715 * ixgbe_update_stats - Update the board statistics counters.
5716 * @adapter: board private structure
5717 **/
5718void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5719{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005720 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005721 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005722 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005723 u64 total_mpc = 0;
5724 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005725 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5726 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5727 u64 bytes = 0, packets = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005728#ifdef IXGBE_FCOE
5729 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5730 unsigned int cpu;
5731 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5732#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005733
Don Skidmored08935c2010-06-11 13:20:29 +00005734 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5735 test_bit(__IXGBE_RESETTING, &adapter->state))
5736 return;
5737
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005738 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005739 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005740 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005741 for (i = 0; i < 16; i++)
5742 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005743 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005744 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005745 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5746 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005747 }
5748 adapter->rsc_total_count = rsc_count;
5749 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005750 }
5751
Alexander Duyck5b7da512010-11-16 19:26:50 -08005752 for (i = 0; i < adapter->num_rx_queues; i++) {
5753 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5754 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5755 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5756 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5757 bytes += rx_ring->stats.bytes;
5758 packets += rx_ring->stats.packets;
5759 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005760 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005761 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5762 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5763 netdev->stats.rx_bytes = bytes;
5764 netdev->stats.rx_packets = packets;
5765
5766 bytes = 0;
5767 packets = 0;
5768 /* gather some stats to the adapter struct that are per queue */
5769 for (i = 0; i < adapter->num_tx_queues; i++) {
5770 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5771 restart_queue += tx_ring->tx_stats.restart_queue;
5772 tx_busy += tx_ring->tx_stats.tx_busy;
5773 bytes += tx_ring->stats.bytes;
5774 packets += tx_ring->stats.packets;
5775 }
5776 adapter->restart_queue = restart_queue;
5777 adapter->tx_busy = tx_busy;
5778 netdev->stats.tx_bytes = bytes;
5779 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005780
Joe Perches7ca647b2010-09-07 21:35:40 +00005781 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005782
5783 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005784 for (i = 0; i < 8; i++) {
5785 /* for packet buffers not used, the register should read 0 */
5786 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5787 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005788 hwstats->mpc[i] += mpc;
5789 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005790 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5791 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005792 switch (hw->mac.type) {
5793 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005794 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5795 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5796 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005797 hwstats->pxonrxc[i] +=
5798 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005799 break;
5800 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005801 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005802 hwstats->pxonrxc[i] +=
5803 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005804 break;
5805 default:
5806 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005807 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005808 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005809
5810 /*16 register reads */
5811 for (i = 0; i < 16; i++) {
5812 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5813 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5814 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5815 (hw->mac.type == ixgbe_mac_X540)) {
5816 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5817 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5818 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5819 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5820 }
5821 }
5822
Joe Perches7ca647b2010-09-07 21:35:40 +00005823 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005824 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005825 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005826
John Fastabendc84d3242010-11-16 19:27:12 -08005827 ixgbe_update_xoff_received(adapter);
5828
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005829 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005830 switch (hw->mac.type) {
5831 case ixgbe_mac_82598EB:
5832 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005833 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5834 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5835 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5836 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005837 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005838 /* OS2BMC stats are X540 only*/
5839 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5840 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5841 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5842 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5843 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005844 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005845 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005846 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005847 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005848 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005849 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005850 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005851 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5852 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005853#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005854 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5855 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5856 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5857 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5858 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5859 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005860 /* Add up per cpu counters for total ddp aloc fail */
5861 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5862 for_each_possible_cpu(cpu) {
5863 fcoe_noddp_counts_sum +=
5864 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5865 fcoe_noddp_ext_buff_counts_sum +=
5866 *per_cpu_ptr(fcoe->
5867 pcpu_noddp_ext_buff, cpu);
5868 }
5869 }
5870 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5871 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005872#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005873 break;
5874 default:
5875 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005876 }
Auke Kok9a799d72007-09-15 14:07:45 -07005877 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005878 hwstats->bprc += bprc;
5879 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005880 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005881 hwstats->mprc -= bprc;
5882 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5883 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5884 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5885 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5886 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5887 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5888 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5889 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005890 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005891 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005892 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005893 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005894 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5895 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005896 /*
5897 * 82598 errata - tx of flow control packets is included in tx counters
5898 */
5899 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005900 hwstats->gptc -= xon_off_tot;
5901 hwstats->mptc -= xon_off_tot;
5902 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5903 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5904 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5905 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5906 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5907 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5908 hwstats->ptc64 -= xon_off_tot;
5909 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5910 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5911 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5912 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5913 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5914 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005915
5916 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005917 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005918
5919 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005920 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005921 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005922 netdev->stats.rx_length_errors = hwstats->rlec;
5923 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005924 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005925}
5926
5927/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005928 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5929 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005930 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005931static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005932{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005933 struct ixgbe_hw *hw = &adapter->hw;
5934 int i;
5935
Alexander Duyckd034acf2011-04-27 09:25:34 +00005936 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5937 return;
5938
5939 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5940
5941 /* if interface is down do nothing */
5942 if (test_bit(__IXGBE_DOWN, &adapter->state))
5943 return;
5944
5945 /* do nothing if we are not using signature filters */
5946 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5947 return;
5948
5949 adapter->fdir_overflow++;
5950
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005951 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5952 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005953 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005954 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005955 /* re-enable flow director interrupts */
5956 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005957 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005958 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005959 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005960 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005961}
5962
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005963/**
5964 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5965 * @adapter - pointer to the device adapter structure
5966 *
5967 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005968 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005969 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005970 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005971 */
5972static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5973{
Auke Kok9a799d72007-09-15 14:07:45 -07005974 struct ixgbe_hw *hw = &adapter->hw;
5975 u64 eics = 0;
5976 int i;
5977
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005978 /* If we're down or resetting, just bail */
5979 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5980 test_bit(__IXGBE_RESETTING, &adapter->state))
5981 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005982
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005983 /* Force detection of hung controller */
5984 if (netif_carrier_ok(adapter->netdev)) {
5985 for (i = 0; i < adapter->num_tx_queues; i++)
5986 set_check_for_tx_hang(adapter->tx_ring[i]);
5987 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005988
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005989 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005990 /*
5991 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005992 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005993 * would set *both* EIMS and EICS for any bit in EIAM
5994 */
5995 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5996 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005997 } else {
5998 /* get one bit for every active tx/rx interrupt vector */
5999 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6000 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006001 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006002 eics |= ((u64)1 << i);
6003 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006004 }
6005
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006006 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006007 ixgbe_irq_rearm_queues(adapter, eics);
6008
Alexander Duyckfe49f042009-06-04 16:00:09 +00006009}
6010
6011/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006012 * ixgbe_watchdog_update_link - update the link status
6013 * @adapter - pointer to the device adapter structure
6014 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006015 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006016static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006017{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006018 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006019 u32 link_speed = adapter->link_speed;
6020 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006021 int i;
6022
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006023 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6024 return;
6025
6026 if (hw->mac.ops.check_link) {
6027 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006028 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006029 /* always assume link is up, if no check link function */
6030 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6031 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006032 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006033 if (link_up) {
6034 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6035 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6036 hw->mac.ops.fc_enable(hw, i);
6037 } else {
6038 hw->mac.ops.fc_enable(hw, 0);
6039 }
6040 }
6041
6042 if (link_up ||
6043 time_after(jiffies, (adapter->link_check_timeout +
6044 IXGBE_TRY_LINK_TIMEOUT))) {
6045 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6046 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6047 IXGBE_WRITE_FLUSH(hw);
6048 }
6049
6050 adapter->link_up = link_up;
6051 adapter->link_speed = link_speed;
6052}
6053
6054/**
6055 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6056 * print link up message
6057 * @adapter - pointer to the device adapter structure
6058 **/
6059static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6060{
6061 struct net_device *netdev = adapter->netdev;
6062 struct ixgbe_hw *hw = &adapter->hw;
6063 u32 link_speed = adapter->link_speed;
6064 bool flow_rx, flow_tx;
6065
6066 /* only continue if link was previously down */
6067 if (netif_carrier_ok(netdev))
6068 return;
6069
6070 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6071
6072 switch (hw->mac.type) {
6073 case ixgbe_mac_82598EB: {
6074 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6075 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6076 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6077 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6078 }
6079 break;
6080 case ixgbe_mac_X540:
6081 case ixgbe_mac_82599EB: {
6082 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6083 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6084 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6085 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6086 }
6087 break;
6088 default:
6089 flow_tx = false;
6090 flow_rx = false;
6091 break;
6092 }
6093 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6094 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6095 "10 Gbps" :
6096 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6097 "1 Gbps" :
6098 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6099 "100 Mbps" :
6100 "unknown speed"))),
6101 ((flow_rx && flow_tx) ? "RX/TX" :
6102 (flow_rx ? "RX" :
6103 (flow_tx ? "TX" : "None"))));
6104
6105 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006106 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006107}
6108
6109/**
6110 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6111 * print link down message
6112 * @adapter - pointer to the adapter structure
6113 **/
6114static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6115{
6116 struct net_device *netdev = adapter->netdev;
6117 struct ixgbe_hw *hw = &adapter->hw;
6118
6119 adapter->link_up = false;
6120 adapter->link_speed = 0;
6121
6122 /* only continue if link was up previously */
6123 if (!netif_carrier_ok(netdev))
6124 return;
6125
6126 /* poll for SFP+ cable when link is down */
6127 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6128 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6129
6130 e_info(drv, "NIC Link is Down\n");
6131 netif_carrier_off(netdev);
6132}
6133
6134/**
6135 * ixgbe_watchdog_flush_tx - flush queues on link down
6136 * @adapter - pointer to the device adapter structure
6137 **/
6138static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6139{
6140 int i;
6141 int some_tx_pending = 0;
6142
6143 if (!netif_carrier_ok(adapter->netdev)) {
6144 for (i = 0; i < adapter->num_tx_queues; i++) {
6145 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6146 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6147 some_tx_pending = 1;
6148 break;
6149 }
6150 }
6151
6152 if (some_tx_pending) {
6153 /* We've lost link, so the controller stops DMA,
6154 * but we've got queued Tx work that's never going
6155 * to get done, so reset controller to flush Tx.
6156 * (Do the reset outside of interrupt context).
6157 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006158 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006159 }
6160 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006161}
6162
Greg Rosea985b6c32010-11-18 03:02:52 +00006163static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6164{
6165 u32 ssvpc;
6166
6167 /* Do not perform spoof check for 82598 */
6168 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6169 return;
6170
6171 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6172
6173 /*
6174 * ssvpc register is cleared on read, if zero then no
6175 * spoofed packets in the last interval.
6176 */
6177 if (!ssvpc)
6178 return;
6179
6180 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6181}
6182
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006183/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006184 * ixgbe_watchdog_subtask - check and bring link up
6185 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006186 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006187static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006188{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006189 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006190 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6191 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006192 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006193
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006194 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006195
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006196 if (adapter->link_up)
6197 ixgbe_watchdog_link_is_up(adapter);
6198 else
6199 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006200
Greg Rosea985b6c32010-11-18 03:02:52 +00006201 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006202 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006203
6204 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006205}
6206
Alexander Duyck70864002011-04-27 09:13:56 +00006207/**
6208 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6209 * @adapter - the ixgbe adapter structure
6210 **/
6211static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6212{
6213 struct ixgbe_hw *hw = &adapter->hw;
6214 s32 err;
6215
6216 /* not searching for SFP so there is nothing to do here */
6217 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6218 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6219 return;
6220
6221 /* someone else is in init, wait until next service event */
6222 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6223 return;
6224
6225 err = hw->phy.ops.identify_sfp(hw);
6226 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6227 goto sfp_out;
6228
6229 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6230 /* If no cable is present, then we need to reset
6231 * the next time we find a good cable. */
6232 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6233 }
6234
6235 /* exit on error */
6236 if (err)
6237 goto sfp_out;
6238
6239 /* exit if reset not needed */
6240 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6241 goto sfp_out;
6242
6243 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6244
6245 /*
6246 * A module may be identified correctly, but the EEPROM may not have
6247 * support for that module. setup_sfp() will fail in that case, so
6248 * we should not allow that module to load.
6249 */
6250 if (hw->mac.type == ixgbe_mac_82598EB)
6251 err = hw->phy.ops.reset(hw);
6252 else
6253 err = hw->mac.ops.setup_sfp(hw);
6254
6255 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6256 goto sfp_out;
6257
6258 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6259 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6260
6261sfp_out:
6262 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6263
6264 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6265 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6266 e_dev_err("failed to initialize because an unsupported "
6267 "SFP+ module type was detected.\n");
6268 e_dev_err("Reload the driver after installing a "
6269 "supported module.\n");
6270 unregister_netdev(adapter->netdev);
6271 }
6272}
6273
6274/**
6275 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6276 * @adapter - the ixgbe adapter structure
6277 **/
6278static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6279{
6280 struct ixgbe_hw *hw = &adapter->hw;
6281 u32 autoneg;
6282 bool negotiation;
6283
6284 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6285 return;
6286
6287 /* someone else is in init, wait until next service event */
6288 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6289 return;
6290
6291 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6292
6293 autoneg = hw->phy.autoneg_advertised;
6294 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6295 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006296 if (hw->mac.ops.setup_link)
6297 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6298
6299 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6300 adapter->link_check_timeout = jiffies;
6301 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6302}
6303
Greg Rose83c61fa2011-09-07 05:59:35 +00006304#ifdef CONFIG_PCI_IOV
6305static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6306{
6307 int vf;
6308 struct ixgbe_hw *hw = &adapter->hw;
6309 struct net_device *netdev = adapter->netdev;
6310 u32 gpc;
6311 u32 ciaa, ciad;
6312
6313 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6314 if (gpc) /* If incrementing then no need for the check below */
6315 return;
6316 /*
6317 * Check to see if a bad DMA write target from an errant or
6318 * malicious VF has caused a PCIe error. If so then we can
6319 * issue a VFLR to the offending VF(s) and then resume without
6320 * requesting a full slot reset.
6321 */
6322
6323 for (vf = 0; vf < adapter->num_vfs; vf++) {
6324 ciaa = (vf << 16) | 0x80000000;
6325 /* 32 bit read so align, we really want status at offset 6 */
6326 ciaa |= PCI_COMMAND;
6327 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6328 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6329 ciaa &= 0x7FFFFFFF;
6330 /* disable debug mode asap after reading data */
6331 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6332 /* Get the upper 16 bits which will be the PCI status reg */
6333 ciad >>= 16;
6334 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6335 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6336 /* Issue VFLR */
6337 ciaa = (vf << 16) | 0x80000000;
6338 ciaa |= 0xA8;
6339 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6340 ciad = 0x00008000; /* VFLR */
6341 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6342 ciaa &= 0x7FFFFFFF;
6343 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6344 }
6345 }
6346}
6347
6348#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006349/**
6350 * ixgbe_service_timer - Timer Call-back
6351 * @data: pointer to adapter cast into an unsigned long
6352 **/
6353static void ixgbe_service_timer(unsigned long data)
6354{
6355 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6356 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006357 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006358
Greg Rose83c61fa2011-09-07 05:59:35 +00006359#ifdef CONFIG_PCI_IOV
6360 ready = false;
6361
6362 /*
6363 * don't bother with SR-IOV VF DMA hang check if there are
6364 * no VFs or the link is down
6365 */
6366 if (!adapter->num_vfs ||
6367 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6368 ready = true;
6369 goto normal_timer_service;
6370 }
6371
6372 /* If we have VFs allocated then we must check for DMA hangs */
6373 ixgbe_check_for_bad_vf(adapter);
6374 next_event_offset = HZ / 50;
6375 adapter->timer_event_accumulator++;
6376
6377 if (adapter->timer_event_accumulator >= 100) {
6378 ready = true;
6379 adapter->timer_event_accumulator = 0;
6380 }
6381
6382 goto schedule_event;
6383
6384normal_timer_service:
6385#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006386 /* poll faster when waiting for link */
6387 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6388 next_event_offset = HZ / 10;
6389 else
6390 next_event_offset = HZ * 2;
6391
Greg Rose83c61fa2011-09-07 05:59:35 +00006392#ifdef CONFIG_PCI_IOV
6393schedule_event:
6394#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006395 /* Reset the timer */
6396 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6397
Greg Rose83c61fa2011-09-07 05:59:35 +00006398 if (ready)
6399 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006400}
6401
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006402static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6403{
6404 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6405 return;
6406
6407 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6408
6409 /* If we're already down or resetting, just bail */
6410 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6411 test_bit(__IXGBE_RESETTING, &adapter->state))
6412 return;
6413
6414 ixgbe_dump(adapter);
6415 netdev_err(adapter->netdev, "Reset adapter\n");
6416 adapter->tx_timeout_count++;
6417
6418 ixgbe_reinit_locked(adapter);
6419}
6420
Alexander Duyck70864002011-04-27 09:13:56 +00006421/**
6422 * ixgbe_service_task - manages and runs subtasks
6423 * @work: pointer to work_struct containing our data
6424 **/
6425static void ixgbe_service_task(struct work_struct *work)
6426{
6427 struct ixgbe_adapter *adapter = container_of(work,
6428 struct ixgbe_adapter,
6429 service_task);
6430
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006431 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006432 ixgbe_sfp_detection_subtask(adapter);
6433 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006434 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006435 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006436 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006437 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006438
6439 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006440}
6441
Alexander Duyck897ab152011-05-27 05:31:47 +00006442void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6443 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006444{
6445 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006446 u16 i = tx_ring->next_to_use;
6447
6448 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6449
6450 i++;
6451 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6452
6453 /* set bits to identify this as an advanced context descriptor */
6454 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6455
6456 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6457 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6458 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6459 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6460}
6461
6462static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6463 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6464{
Auke Kok9a799d72007-09-15 14:07:45 -07006465 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006466 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006467 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006468
Alexander Duyck897ab152011-05-27 05:31:47 +00006469 if (!skb_is_gso(skb))
6470 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006471
Alexander Duyck897ab152011-05-27 05:31:47 +00006472 if (skb_header_cloned(skb)) {
6473 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6474 if (err)
6475 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006476 }
6477
Alexander Duyck897ab152011-05-27 05:31:47 +00006478 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6479 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6480
6481 if (protocol == __constant_htons(ETH_P_IP)) {
6482 struct iphdr *iph = ip_hdr(skb);
6483 iph->tot_len = 0;
6484 iph->check = 0;
6485 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6486 iph->daddr, 0,
6487 IPPROTO_TCP,
6488 0);
6489 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6490 } else if (skb_is_gso_v6(skb)) {
6491 ipv6_hdr(skb)->payload_len = 0;
6492 tcp_hdr(skb)->check =
6493 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6494 &ipv6_hdr(skb)->daddr,
6495 0, IPPROTO_TCP, 0);
6496 }
6497
6498 l4len = tcp_hdrlen(skb);
6499 *hdr_len = skb_transport_offset(skb) + l4len;
6500
6501 /* mss_l4len_id: use 1 as index for TSO */
6502 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6503 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6504 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6505
6506 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6507 vlan_macip_lens = skb_network_header_len(skb);
6508 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6509 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6510
6511 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6512 mss_l4len_idx);
6513
6514 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006515}
6516
Alexander Duyck897ab152011-05-27 05:31:47 +00006517static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006518 struct sk_buff *skb, u32 tx_flags,
6519 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006520{
Alexander Duyck897ab152011-05-27 05:31:47 +00006521 u32 vlan_macip_lens = 0;
6522 u32 mss_l4len_idx = 0;
6523 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006524
Alexander Duyck897ab152011-05-27 05:31:47 +00006525 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006526 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6527 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006528 return false;
6529 } else {
6530 u8 l4_hdr = 0;
6531 switch (protocol) {
6532 case __constant_htons(ETH_P_IP):
6533 vlan_macip_lens |= skb_network_header_len(skb);
6534 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6535 l4_hdr = ip_hdr(skb)->protocol;
6536 break;
6537 case __constant_htons(ETH_P_IPV6):
6538 vlan_macip_lens |= skb_network_header_len(skb);
6539 l4_hdr = ipv6_hdr(skb)->nexthdr;
6540 break;
6541 default:
6542 if (unlikely(net_ratelimit())) {
6543 dev_warn(tx_ring->dev,
6544 "partial checksum but proto=%x!\n",
6545 skb->protocol);
6546 }
6547 break;
6548 }
Auke Kok9a799d72007-09-15 14:07:45 -07006549
Alexander Duyck897ab152011-05-27 05:31:47 +00006550 switch (l4_hdr) {
6551 case IPPROTO_TCP:
6552 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6553 mss_l4len_idx = tcp_hdrlen(skb) <<
6554 IXGBE_ADVTXD_L4LEN_SHIFT;
6555 break;
6556 case IPPROTO_SCTP:
6557 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6558 mss_l4len_idx = sizeof(struct sctphdr) <<
6559 IXGBE_ADVTXD_L4LEN_SHIFT;
6560 break;
6561 case IPPROTO_UDP:
6562 mss_l4len_idx = sizeof(struct udphdr) <<
6563 IXGBE_ADVTXD_L4LEN_SHIFT;
6564 break;
6565 default:
6566 if (unlikely(net_ratelimit())) {
6567 dev_warn(tx_ring->dev,
6568 "partial checksum but l4 proto=%x!\n",
6569 skb->protocol);
6570 }
6571 break;
6572 }
Auke Kok9a799d72007-09-15 14:07:45 -07006573 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006574
Alexander Duyck897ab152011-05-27 05:31:47 +00006575 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6576 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6577
6578 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6579 type_tucmd, mss_l4len_idx);
6580
6581 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006582}
6583
Alexander Duyckd3d00232011-07-15 02:31:25 +00006584static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6585{
6586 /* set type for advanced descriptor with frame checksum insertion */
6587 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6588 IXGBE_ADVTXD_DCMD_IFCS |
6589 IXGBE_ADVTXD_DCMD_DEXT);
6590
6591 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006592 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006593 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6594
6595 /* set segmentation enable bits for TSO/FSO */
6596#ifdef IXGBE_FCOE
6597 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6598#else
6599 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6600#endif
6601 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6602
6603 return cmd_type;
6604}
6605
6606static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6607{
6608 __le32 olinfo_status =
6609 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6610
6611 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6612 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6613 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6614 /* enble IPv4 checksum for TSO */
6615 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6616 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6617 }
6618
6619 /* enable L4 checksum for TSO and TX checksum offload */
6620 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6621 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6622
6623#ifdef IXGBE_FCOE
6624 /* use index 1 context for FCOE/FSO */
6625 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6626 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6627 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6628
6629#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006630 /*
6631 * Check Context must be set if Tx switch is enabled, which it
6632 * always is for case where virtual functions are running
6633 */
6634 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6635 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6636
Alexander Duyckd3d00232011-07-15 02:31:25 +00006637 return olinfo_status;
6638}
6639
6640#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6641 IXGBE_TXD_CMD_RS)
6642
6643static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6644 struct sk_buff *skb,
6645 struct ixgbe_tx_buffer *first,
6646 u32 tx_flags,
6647 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006648{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006649 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006650 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006651 union ixgbe_adv_tx_desc *tx_desc;
6652 dma_addr_t dma;
6653 __le32 cmd_type, olinfo_status;
6654 struct skb_frag_struct *frag;
6655 unsigned int f = 0;
6656 unsigned int data_len = skb->data_len;
6657 unsigned int size = skb_headlen(skb);
6658 u32 offset = 0;
6659 u32 paylen = skb->len - hdr_len;
6660 u16 i = tx_ring->next_to_use;
6661 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006662
Alexander Duyckd3d00232011-07-15 02:31:25 +00006663#ifdef IXGBE_FCOE
6664 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6665 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6666 data_len -= sizeof(struct fcoe_crc_eof);
6667 } else {
6668 size -= sizeof(struct fcoe_crc_eof) - data_len;
6669 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006670 }
Auke Kok9a799d72007-09-15 14:07:45 -07006671 }
6672
Alexander Duyckd3d00232011-07-15 02:31:25 +00006673#endif
6674 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6675 if (dma_mapping_error(dev, dma))
6676 goto dma_error;
6677
6678 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6679 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6680
6681 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6682
6683 for (;;) {
6684 while (size > IXGBE_MAX_DATA_PER_TXD) {
6685 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6686 tx_desc->read.cmd_type_len =
6687 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6688 tx_desc->read.olinfo_status = olinfo_status;
6689
6690 offset += IXGBE_MAX_DATA_PER_TXD;
6691 size -= IXGBE_MAX_DATA_PER_TXD;
6692
6693 tx_desc++;
6694 i++;
6695 if (i == tx_ring->count) {
6696 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6697 i = 0;
6698 }
6699 }
6700
6701 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6702 tx_buffer_info->length = offset + size;
6703 tx_buffer_info->tx_flags = tx_flags;
6704 tx_buffer_info->dma = dma;
6705
6706 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6707 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6708 tx_desc->read.olinfo_status = olinfo_status;
6709
6710 if (!data_len)
6711 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006712
6713 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006714#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006715 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006716#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006717 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006718#endif
6719 data_len -= size;
6720 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006721
Alexander Duyckd3d00232011-07-15 02:31:25 +00006722 offset = 0;
6723 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006724
Ian Campbell877749b2011-08-29 23:18:26 +00006725 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006726 if (dma_mapping_error(dev, dma))
6727 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006728
Alexander Duyckd3d00232011-07-15 02:31:25 +00006729 tx_desc++;
6730 i++;
6731 if (i == tx_ring->count) {
6732 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6733 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006734 }
6735 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006736
Alexander Duyckd3d00232011-07-15 02:31:25 +00006737 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6738
6739 i++;
6740 if (i == tx_ring->count)
6741 i = 0;
6742
6743 tx_ring->next_to_use = i;
6744
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006745 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6746 gso_segs = skb_shinfo(skb)->gso_segs;
6747#ifdef IXGBE_FCOE
6748 /* adjust for FCoE Sequence Offload */
6749 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6750 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6751 skb_shinfo(skb)->gso_size);
6752#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006753 else
6754 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006755
6756 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006757 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6758 tx_buffer_info->gso_segs = gso_segs;
6759 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006760
Alexander Duyckd3d00232011-07-15 02:31:25 +00006761 /* set the timestamp */
6762 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006763
6764 /*
6765 * Force memory writes to complete before letting h/w
6766 * know there are new descriptors to fetch. (Only
6767 * applicable for weak-ordered memory model archs,
6768 * such as IA-64).
6769 */
6770 wmb();
6771
Alexander Duyckd3d00232011-07-15 02:31:25 +00006772 /* set next_to_watch value indicating a packet is present */
6773 first->next_to_watch = tx_desc;
6774
6775 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006776 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006777
6778 return;
6779dma_error:
6780 dev_err(dev, "TX DMA map failed\n");
6781
6782 /* clear dma mappings for failed tx_buffer_info map */
6783 for (;;) {
6784 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6785 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6786 if (tx_buffer_info == first)
6787 break;
6788 if (i == 0)
6789 i = tx_ring->count;
6790 i--;
6791 }
6792
6793 dev_kfree_skb_any(skb);
6794
6795 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006796}
6797
Alexander Duyck69830522011-01-06 14:29:58 +00006798static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6799 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006800{
Alexander Duyck69830522011-01-06 14:29:58 +00006801 struct ixgbe_q_vector *q_vector = ring->q_vector;
6802 union ixgbe_atr_hash_dword input = { .dword = 0 };
6803 union ixgbe_atr_hash_dword common = { .dword = 0 };
6804 union {
6805 unsigned char *network;
6806 struct iphdr *ipv4;
6807 struct ipv6hdr *ipv6;
6808 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006809 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006810 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006811
Alexander Duyck69830522011-01-06 14:29:58 +00006812 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6813 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006814 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006815
Alexander Duyck69830522011-01-06 14:29:58 +00006816 /* do nothing if sampling is disabled */
6817 if (!ring->atr_sample_rate)
6818 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006819
Alexander Duyck69830522011-01-06 14:29:58 +00006820 ring->atr_count++;
6821
6822 /* snag network header to get L4 type and address */
6823 hdr.network = skb_network_header(skb);
6824
6825 /* Currently only IPv4/IPv6 with TCP is supported */
6826 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6827 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6828 (protocol != __constant_htons(ETH_P_IP) ||
6829 hdr.ipv4->protocol != IPPROTO_TCP))
6830 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006831
6832 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006833
Alexander Duyck66f32a82011-06-29 05:43:22 +00006834 /* skip this packet since it is invalid or the socket is closing */
6835 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006836 return;
6837
6838 /* sample on all syn packets or once every atr sample count */
6839 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6840 return;
6841
6842 /* reset sample count */
6843 ring->atr_count = 0;
6844
6845 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6846
6847 /*
6848 * src and dst are inverted, think how the receiver sees them
6849 *
6850 * The input is broken into two sections, a non-compressed section
6851 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6852 * is XORed together and stored in the compressed dword.
6853 */
6854 input.formatted.vlan_id = vlan_id;
6855
6856 /*
6857 * since src port and flex bytes occupy the same word XOR them together
6858 * and write the value to source port portion of compressed dword
6859 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006860 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006861 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6862 else
6863 common.port.src ^= th->dest ^ protocol;
6864 common.port.dst ^= th->source;
6865
6866 if (protocol == __constant_htons(ETH_P_IP)) {
6867 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6868 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6869 } else {
6870 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6871 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6872 hdr.ipv6->saddr.s6_addr32[1] ^
6873 hdr.ipv6->saddr.s6_addr32[2] ^
6874 hdr.ipv6->saddr.s6_addr32[3] ^
6875 hdr.ipv6->daddr.s6_addr32[0] ^
6876 hdr.ipv6->daddr.s6_addr32[1] ^
6877 hdr.ipv6->daddr.s6_addr32[2] ^
6878 hdr.ipv6->daddr.s6_addr32[3];
6879 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006880
6881 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006882 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6883 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006884}
6885
Alexander Duyck63544e92011-05-27 05:31:42 +00006886static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006887{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006888 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006889 /* Herbert's original patch had:
6890 * smp_mb__after_netif_stop_queue();
6891 * but since that doesn't exist yet, just open code it. */
6892 smp_mb();
6893
6894 /* We need to check again in a case another CPU has just
6895 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006896 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006897 return -EBUSY;
6898
6899 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006900 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006901 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006902 return 0;
6903}
6904
Alexander Duyck82d4e462011-06-11 01:44:58 +00006905static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006906{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006907 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006908 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006909 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006910}
6911
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006912static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6913{
6914 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006915 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6916 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006917#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006918 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006919
John Fastabende5b64632011-03-08 03:44:52 +00006920 if (((protocol == htons(ETH_P_FCOE)) ||
6921 (protocol == htons(ETH_P_FIP))) &&
6922 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6923 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6924 txq += adapter->ring_feature[RING_F_FCOE].mask;
6925 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006926 }
6927#endif
6928
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006929 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6930 while (unlikely(txq >= dev->real_num_tx_queues))
6931 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006932 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006933 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006934
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006935 return skb_tx_hash(dev, skb);
6936}
6937
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006938netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006939 struct ixgbe_adapter *adapter,
6940 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006941{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006942 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006943 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006944 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006945#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6946 unsigned short f;
6947#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006948 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006949 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006950 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006951
Alexander Duycka535c302011-05-27 05:31:52 +00006952 /*
6953 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6954 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6955 * + 2 desc gap to keep tail from touching head,
6956 * + 1 desc for context descriptor,
6957 * otherwise try next time
6958 */
6959#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6960 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6961 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6962#else
6963 count += skb_shinfo(skb)->nr_frags;
6964#endif
6965 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6966 tx_ring->tx_stats.tx_busy++;
6967 return NETDEV_TX_BUSY;
6968 }
6969
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006970#ifdef CONFIG_PCI_IOV
6971 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6972 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6973
6974#endif
Alexander Duyck66f32a82011-06-29 05:43:22 +00006975 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006976 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006977 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6978 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6979 /* else if it is a SW VLAN check the next protocol and store the tag */
6980 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6981 struct vlan_hdr *vhdr, _vhdr;
6982 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6983 if (!vhdr)
6984 goto out_drop;
6985
6986 protocol = vhdr->h_vlan_encapsulated_proto;
6987 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6988 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006989 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006990
John Fastabend32701dc2011-09-27 03:51:56 +00006991 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006992 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00006993 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
6994 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006995 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00006996 tx_flags |= (skb->priority & 0x7) <<
6997 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006998 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6999 struct vlan_ethhdr *vhdr;
7000 if (skb_header_cloned(skb) &&
7001 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7002 goto out_drop;
7003 vhdr = (struct vlan_ethhdr *)skb->data;
7004 vhdr->h_vlan_TCI = htons(tx_flags >>
7005 IXGBE_TX_FLAGS_VLAN_SHIFT);
7006 } else {
7007 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7008 }
7009 }
Alexander Duycka535c302011-05-27 05:31:52 +00007010
Alexander Duycka535c302011-05-27 05:31:52 +00007011 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007012 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007013
Yi Zoueacd73f2009-05-13 13:11:06 +00007014#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007015 /* setup tx offload for FCoE */
7016 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7017 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007018 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7019 if (tso < 0)
7020 goto out_drop;
7021 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007022 tx_flags |= IXGBE_TX_FLAGS_FSO |
7023 IXGBE_TX_FLAGS_FCOE;
7024 else
7025 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007026
Alexander Duyck66f32a82011-06-29 05:43:22 +00007027 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007028 }
Auke Kok9a799d72007-09-15 14:07:45 -07007029
Auke Kok9a799d72007-09-15 14:07:45 -07007030#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007031 /* setup IPv4/IPv6 offloads */
7032 if (protocol == __constant_htons(ETH_P_IP))
7033 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007034
Alexander Duyck66f32a82011-06-29 05:43:22 +00007035 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7036 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007037 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007038 else if (tso)
7039 tx_flags |= IXGBE_TX_FLAGS_TSO;
7040 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7041 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7042
7043 /* add the ATR filter if ATR is on */
7044 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7045 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7046
7047#ifdef IXGBE_FCOE
7048xmit_fcoe:
7049#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007050 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7051
7052 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007053
7054 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007055
7056out_drop:
7057 dev_kfree_skb_any(skb);
7058 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007059}
7060
7061static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7062{
7063 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7064 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007065
Auke Kok9a799d72007-09-15 14:07:45 -07007066 tx_ring = adapter->tx_ring[skb->queue_mapping];
7067 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7068}
7069
7070/**
7071 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007072 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007073 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007074 *
Auke Kok9a799d72007-09-15 14:07:45 -07007075 * Returns 0 on success, negative on failure
7076 **/
7077static int ixgbe_set_mac(struct net_device *netdev, void *p)
7078{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007079 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7080 struct ixgbe_hw *hw = &adapter->hw;
7081 struct sockaddr *addr = p;
7082
7083 if (!is_valid_ether_addr(addr->sa_data))
7084 return -EADDRNOTAVAIL;
7085
7086 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7087 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7088
7089 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7090 IXGBE_RAH_AV);
7091
7092 return 0;
7093}
7094
7095static int
7096ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7097{
7098 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7099 struct ixgbe_hw *hw = &adapter->hw;
7100 u16 value;
7101 int rc;
7102
7103 if (prtad != hw->phy.mdio.prtad)
7104 return -EINVAL;
7105 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7106 if (!rc)
7107 rc = value;
7108 return rc;
7109}
7110
7111static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7112 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007113{
7114 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007115 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007116
7117 if (prtad != hw->phy.mdio.prtad)
7118 return -EINVAL;
7119 return hw->phy.ops.write_reg(hw, addr, devad, value);
7120}
7121
7122static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7123{
7124 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7125
7126 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7127}
7128
7129/**
7130 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7131 * netdev->dev_addrs
7132 * @netdev: network interface device structure
7133 *
7134 * Returns non-zero on failure
7135 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007136static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007137{
7138 int err = 0;
7139 struct ixgbe_adapter *adapter = netdev_priv(dev);
7140 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7141
7142 if (is_valid_ether_addr(mac->san_addr)) {
7143 rtnl_lock();
7144 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7145 rtnl_unlock();
7146 }
7147 return err;
7148}
7149
7150/**
7151 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7152 * netdev->dev_addrs
7153 * @netdev: network interface device structure
7154 *
Auke Kok9a799d72007-09-15 14:07:45 -07007155 * Returns non-zero on failure
7156 **/
7157static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7158{
7159 int err = 0;
7160 struct ixgbe_adapter *adapter = netdev_priv(dev);
7161 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7162
7163 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007164 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007165 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007166 rtnl_unlock();
7167 }
7168 return err;
7169}
Auke Kok9a799d72007-09-15 14:07:45 -07007170
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007171#ifdef CONFIG_NET_POLL_CONTROLLER
7172/*
7173 * Polling 'interrupt' - used by things like netconsole to send skbs
7174 * without having to re-enable interrupts. It's not called while
7175 * the interrupt routine is executing.
7176 */
7177static void ixgbe_netpoll(struct net_device *netdev)
7178{
7179 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007180 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007181
7182 /* if interface is down do nothing */
7183 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007184 return;
7185
7186 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007187 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007188 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007189 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007190 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007191 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007192 }
7193 } else {
7194 ixgbe_intr(adapter->pdev->irq, netdev);
7195 }
7196 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7197}
7198#endif
7199
Eric Dumazetde1036b2010-10-20 23:00:04 +00007200static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7201 struct rtnl_link_stats64 *stats)
7202{
7203 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7204 int i;
7205
Eric Dumazet1a515022010-11-16 19:26:42 -08007206 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007207 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007208 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007209 u64 bytes, packets;
7210 unsigned int start;
7211
Eric Dumazet1a515022010-11-16 19:26:42 -08007212 if (ring) {
7213 do {
7214 start = u64_stats_fetch_begin_bh(&ring->syncp);
7215 packets = ring->stats.packets;
7216 bytes = ring->stats.bytes;
7217 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7218 stats->rx_packets += packets;
7219 stats->rx_bytes += bytes;
7220 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007221 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007222
7223 for (i = 0; i < adapter->num_tx_queues; i++) {
7224 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7225 u64 bytes, packets;
7226 unsigned int start;
7227
7228 if (ring) {
7229 do {
7230 start = u64_stats_fetch_begin_bh(&ring->syncp);
7231 packets = ring->stats.packets;
7232 bytes = ring->stats.bytes;
7233 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7234 stats->tx_packets += packets;
7235 stats->tx_bytes += bytes;
7236 }
7237 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007238 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007239 /* following stats updated by ixgbe_watchdog_task() */
7240 stats->multicast = netdev->stats.multicast;
7241 stats->rx_errors = netdev->stats.rx_errors;
7242 stats->rx_length_errors = netdev->stats.rx_length_errors;
7243 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7244 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7245 return stats;
7246}
7247
John Fastabend8b1c0b22011-05-03 02:26:48 +00007248/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7249 * #adapter: pointer to ixgbe_adapter
7250 * @tc: number of traffic classes currently enabled
7251 *
7252 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7253 * 802.1Q priority maps to a packet buffer that exists.
7254 */
7255static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7256{
7257 struct ixgbe_hw *hw = &adapter->hw;
7258 u32 reg, rsave;
7259 int i;
7260
7261 /* 82598 have a static priority to TC mapping that can not
7262 * be changed so no validation is needed.
7263 */
7264 if (hw->mac.type == ixgbe_mac_82598EB)
7265 return;
7266
7267 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7268 rsave = reg;
7269
7270 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7271 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7272
7273 /* If up2tc is out of bounds default to zero */
7274 if (up2tc > tc)
7275 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7276 }
7277
7278 if (reg != rsave)
7279 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7280
7281 return;
7282}
7283
7284
7285/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7286 * classes.
7287 *
7288 * @netdev: net device to configure
7289 * @tc: number of traffic classes to enable
7290 */
7291int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7292{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007293 struct ixgbe_adapter *adapter = netdev_priv(dev);
7294 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007295
John Fastabende7589ea2011-07-18 22:38:36 +00007296 /* Multiple traffic classes requires multiple queues */
7297 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7298 e_err(drv, "Enable failed, needs MSI-X\n");
7299 return -EINVAL;
7300 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007301
7302 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007303 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007304 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7305 return -EINVAL;
7306
7307 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007308 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007309 * hardware is not flexible enough to do this dynamically.
7310 */
7311 if (netif_running(dev))
7312 ixgbe_close(dev);
7313 ixgbe_clear_interrupt_scheme(adapter);
7314
John Fastabende7589ea2011-07-18 22:38:36 +00007315 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007316 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007317 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7318
7319 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7320 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7321
7322 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7323 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7324 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007325 netdev_reset_tc(dev);
7326
John Fastabende7589ea2011-07-18 22:38:36 +00007327 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7328
7329 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7330 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7331
7332 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7333 adapter->dcb_cfg.pfc_mode_enable = false;
7334 }
7335
John Fastabend8b1c0b22011-05-03 02:26:48 +00007336 ixgbe_init_interrupt_scheme(adapter);
7337 ixgbe_validate_rtr(adapter, tc);
7338 if (netif_running(dev))
7339 ixgbe_open(dev);
7340
7341 return 0;
7342}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007343
Don Skidmore082757a2011-07-21 05:55:00 +00007344void ixgbe_do_reset(struct net_device *netdev)
7345{
7346 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7347
7348 if (netif_running(netdev))
7349 ixgbe_reinit_locked(adapter);
7350 else
7351 ixgbe_reset(adapter);
7352}
7353
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007354static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7355 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007356{
7357 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7358
7359#ifdef CONFIG_DCB
7360 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7361 data &= ~NETIF_F_HW_VLAN_RX;
7362#endif
7363
7364 /* return error if RXHASH is being enabled when RSS is not supported */
7365 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7366 data &= ~NETIF_F_RXHASH;
7367
7368 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7369 if (!(data & NETIF_F_RXCSUM))
7370 data &= ~NETIF_F_LRO;
7371
7372 /* Turn off LRO if not RSC capable or invalid ITR settings */
7373 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7374 data &= ~NETIF_F_LRO;
7375 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7376 (adapter->rx_itr_setting != 1 &&
7377 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7378 data &= ~NETIF_F_LRO;
7379 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7380 }
7381
7382 return data;
7383}
7384
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007385static int ixgbe_set_features(struct net_device *netdev,
7386 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007387{
7388 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7389 bool need_reset = false;
7390
7391 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7392 if (!(data & NETIF_F_RXCSUM))
7393 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7394 else
7395 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7396
7397 /* Make sure RSC matches LRO, reset if change */
7398 if (!!(data & NETIF_F_LRO) !=
7399 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7400 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7401 switch (adapter->hw.mac.type) {
7402 case ixgbe_mac_X540:
7403 case ixgbe_mac_82599EB:
7404 need_reset = true;
7405 break;
7406 default:
7407 break;
7408 }
7409 }
7410
7411 /*
7412 * Check if Flow Director n-tuple support was enabled or disabled. If
7413 * the state changed, we need to reset.
7414 */
7415 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7416 /* turn off ATR, enable perfect filters and reset */
7417 if (data & NETIF_F_NTUPLE) {
7418 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7419 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7420 need_reset = true;
7421 }
7422 } else if (!(data & NETIF_F_NTUPLE)) {
7423 /* turn off Flow Director, set ATR and reset */
7424 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7425 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7426 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7427 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7428 need_reset = true;
7429 }
7430
7431 if (need_reset)
7432 ixgbe_do_reset(netdev);
7433
7434 return 0;
7435
7436}
7437
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007438static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007439 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007440 .ndo_stop = ixgbe_close,
7441 .ndo_start_xmit = ixgbe_xmit_frame,
7442 .ndo_select_queue = ixgbe_select_queue,
7443 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007444 .ndo_validate_addr = eth_validate_addr,
7445 .ndo_set_mac_address = ixgbe_set_mac,
7446 .ndo_change_mtu = ixgbe_change_mtu,
7447 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007448 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7449 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007450 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007451 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7452 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7453 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007454 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007455 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007456 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007457 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007458#ifdef CONFIG_NET_POLL_CONTROLLER
7459 .ndo_poll_controller = ixgbe_netpoll,
7460#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007461#ifdef IXGBE_FCOE
7462 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007463 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007464 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007465 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7466 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007467 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007468 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007469#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007470 .ndo_set_features = ixgbe_set_features,
7471 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007472};
7473
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007474static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7475 const struct ixgbe_info *ii)
7476{
7477#ifdef CONFIG_PCI_IOV
7478 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007479
Greg Rosec6bda302011-08-24 02:37:55 +00007480 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007481 return;
7482
7483 /* The 82599 supports up to 64 VFs per physical function
7484 * but this implementation limits allocation to 63 so that
7485 * basic networking resources are still available to the
7486 * physical function
7487 */
7488 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007489 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007490#endif /* CONFIG_PCI_IOV */
7491}
7492
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007493/**
Auke Kok9a799d72007-09-15 14:07:45 -07007494 * ixgbe_probe - Device Initialization Routine
7495 * @pdev: PCI device information struct
7496 * @ent: entry in ixgbe_pci_tbl
7497 *
7498 * Returns 0 on success, negative on failure
7499 *
7500 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7501 * The OS initialization, configuring of the adapter private structure,
7502 * and a hardware reset occur.
7503 **/
7504static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007505 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007506{
7507 struct net_device *netdev;
7508 struct ixgbe_adapter *adapter = NULL;
7509 struct ixgbe_hw *hw;
7510 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007511 static int cards_found;
7512 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007513 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007514 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007515#ifdef IXGBE_FCOE
7516 u16 device_caps;
7517#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007518 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007519 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007520
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007521 /* Catch broken hardware that put the wrong VF device ID in
7522 * the PCIe SR-IOV capability.
7523 */
7524 if (pdev->is_virtfn) {
7525 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7526 pci_name(pdev), pdev->vendor, pdev->device);
7527 return -EINVAL;
7528 }
7529
gouji-new9ce77662009-05-06 10:44:45 +00007530 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007531 if (err)
7532 return err;
7533
Nick Nunley1b507732010-04-27 13:10:27 +00007534 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7535 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007536 pci_using_dac = 1;
7537 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007538 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007539 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007540 err = dma_set_coherent_mask(&pdev->dev,
7541 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007542 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007543 dev_err(&pdev->dev,
7544 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007545 goto err_dma;
7546 }
7547 }
7548 pci_using_dac = 0;
7549 }
7550
gouji-new9ce77662009-05-06 10:44:45 +00007551 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007552 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007553 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007554 dev_err(&pdev->dev,
7555 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007556 goto err_pci_reg;
7557 }
7558
Frans Pop19d5afd2009-10-02 10:04:12 -07007559 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007560
Auke Kok9a799d72007-09-15 14:07:45 -07007561 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007562 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007563
John Fastabende901acd2011-04-26 07:26:08 +00007564#ifdef CONFIG_IXGBE_DCB
7565 indices *= MAX_TRAFFIC_CLASS;
7566#endif
7567
John Fastabendc85a2612010-02-25 23:15:21 +00007568 if (ii->mac == ixgbe_mac_82598EB)
7569 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7570 else
7571 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7572
John Fastabende901acd2011-04-26 07:26:08 +00007573#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007574 indices += min_t(unsigned int, num_possible_cpus(),
7575 IXGBE_MAX_FCOE_INDICES);
7576#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007577 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007578 if (!netdev) {
7579 err = -ENOMEM;
7580 goto err_alloc_etherdev;
7581 }
7582
Auke Kok9a799d72007-09-15 14:07:45 -07007583 SET_NETDEV_DEV(netdev, &pdev->dev);
7584
Auke Kok9a799d72007-09-15 14:07:45 -07007585 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007586 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007587
7588 adapter->netdev = netdev;
7589 adapter->pdev = pdev;
7590 hw = &adapter->hw;
7591 hw->back = adapter;
7592 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7593
Jeff Kirsher05857982008-09-11 19:57:00 -07007594 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007595 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007596 if (!hw->hw_addr) {
7597 err = -EIO;
7598 goto err_ioremap;
7599 }
7600
7601 for (i = 1; i <= 5; i++) {
7602 if (pci_resource_len(pdev, i) == 0)
7603 continue;
7604 }
7605
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007606 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007607 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007608 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007609 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007610
Auke Kok9a799d72007-09-15 14:07:45 -07007611 adapter->bd_number = cards_found;
7612
Auke Kok9a799d72007-09-15 14:07:45 -07007613 /* Setup hw api */
7614 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007615 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007616
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007617 /* EEPROM */
7618 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7619 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7620 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7621 if (!(eec & (1 << 8)))
7622 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7623
7624 /* PHY */
7625 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007626 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007627 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7628 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7629 hw->phy.mdio.mmds = 0;
7630 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7631 hw->phy.mdio.dev = netdev;
7632 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7633 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007634
Don Skidmore8ca783a2009-05-26 20:40:47 -07007635 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007636
7637 /* setup the private structure */
7638 err = ixgbe_sw_init(adapter);
7639 if (err)
7640 goto err_sw_init;
7641
Don Skidmoree86bff02010-02-11 04:14:08 +00007642 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007643 switch (adapter->hw.mac.type) {
7644 case ixgbe_mac_82599EB:
7645 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007646 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007647 break;
7648 default:
7649 break;
7650 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007651
Don Skidmorebf069c92009-05-07 10:39:54 +00007652 /*
7653 * If there is a fan on this device and it has failed log the
7654 * failure.
7655 */
7656 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7657 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7658 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007659 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007660 }
7661
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007662 if (allow_unsupported_sfp)
7663 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7664
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007665 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007666 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007667 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007668 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007669 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7670 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007671 err = 0;
7672 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007673 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007674 "module type was detected.\n");
7675 e_dev_err("Reload the driver after installing a supported "
7676 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007677 goto err_sw_init;
7678 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007679 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007680 goto err_sw_init;
7681 }
7682
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007683 ixgbe_probe_vf(adapter, ii);
7684
Emil Tantilov396e7992010-07-01 20:05:12 +00007685 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007686 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007687 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007688 NETIF_F_HW_VLAN_TX |
7689 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007690 NETIF_F_HW_VLAN_FILTER |
7691 NETIF_F_TSO |
7692 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007693 NETIF_F_RXHASH |
7694 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007695
Don Skidmore082757a2011-07-21 05:55:00 +00007696 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007697
Don Skidmore58be7662011-04-12 09:42:11 +00007698 switch (adapter->hw.mac.type) {
7699 case ixgbe_mac_82599EB:
7700 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007701 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007702 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7703 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007704 break;
7705 default:
7706 break;
7707 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007708
Jeff Kirsherad31c402008-06-05 04:05:30 -07007709 netdev->vlan_features |= NETIF_F_TSO;
7710 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007711 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007712 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007713 netdev->vlan_features |= NETIF_F_SG;
7714
Jiri Pirko01789342011-08-16 06:29:00 +00007715 netdev->priv_flags |= IFF_UNICAST_FLT;
7716
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007717 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7718 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7719 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007720
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007721#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007722 netdev->dcbnl_ops = &dcbnl_ops;
7723#endif
7724
Yi Zoueacd73f2009-05-13 13:11:06 +00007725#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007726 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007727 if (hw->mac.ops.get_device_caps) {
7728 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007729 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7730 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007731 }
7732 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007733 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7734 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7735 netdev->vlan_features |= NETIF_F_FSO;
7736 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7737 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007738#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007739 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007740 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007741 netdev->vlan_features |= NETIF_F_HIGHDMA;
7742 }
Auke Kok9a799d72007-09-15 14:07:45 -07007743
Don Skidmore082757a2011-07-21 05:55:00 +00007744 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7745 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007746 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007747 netdev->features |= NETIF_F_LRO;
7748
Auke Kok9a799d72007-09-15 14:07:45 -07007749 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007750 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007751 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007752 err = -EIO;
7753 goto err_eeprom;
7754 }
7755
7756 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7757 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7758
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007759 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007760 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007761 err = -EIO;
7762 goto err_eeprom;
7763 }
7764
Alexander Duyck70864002011-04-27 09:13:56 +00007765 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7766 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007767
Alexander Duyck70864002011-04-27 09:13:56 +00007768 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7769 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007770
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007771 err = ixgbe_init_interrupt_scheme(adapter);
7772 if (err)
7773 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007774
Don Skidmore082757a2011-07-21 05:55:00 +00007775 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7776 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007777 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007778 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007779
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007780 /* WOL not supported for all but the following */
7781 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007782 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007783 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007784 /* Only these subdevice supports WOL */
7785 switch (pdev->subsystem_device) {
7786 case IXGBE_SUBDEV_ID_82599_560FLR:
7787 /* only support first port */
7788 if (hw->bus.func != 0)
7789 break;
7790 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007791 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007792 break;
7793 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007794 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007795 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7796 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007797 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007798 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007799 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007800 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007801 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007802 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007803 case IXGBE_DEV_ID_X540T:
7804 /* Check eeprom to see if it is enabled */
7805 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7806 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7807
7808 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7809 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7810 (hw->bus.func == 0)))
7811 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007812 break;
7813 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007814 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7815
Emil Tantilov15e52092011-09-29 05:01:29 +00007816 /* save off EEPROM version number */
7817 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7818 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7819
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007820 /* pick up the PCI bus settings for reporting later */
7821 hw->mac.ops.get_bus_info(hw);
7822
Auke Kok9a799d72007-09-15 14:07:45 -07007823 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007824 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007825 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7826 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007827 "Unknown"),
7828 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7829 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7830 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7831 "Unknown"),
7832 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007833
7834 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7835 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007836 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007837 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007838 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007839 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007840 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007841 else
Don Skidmore289700db2010-12-03 03:32:58 +00007842 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7843 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007844
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007845 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007846 e_dev_warn("PCI-Express bandwidth available for this card is "
7847 "not sufficient for optimal performance.\n");
7848 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7849 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007850 }
7851
Auke Kok9a799d72007-09-15 14:07:45 -07007852 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007853 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007854
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007855 if (err == IXGBE_ERR_EEPROM_VERSION) {
7856 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007857 e_dev_warn("This device is a pre-production adapter/LOM. "
7858 "Please be aware there may be issues associated "
7859 "with your hardware. If you are experiencing "
7860 "problems please contact your Intel or hardware "
7861 "representative who provided you with this "
7862 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007863 }
Auke Kok9a799d72007-09-15 14:07:45 -07007864 strcpy(netdev->name, "eth%d");
7865 err = register_netdev(netdev);
7866 if (err)
7867 goto err_register;
7868
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007869 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7870 if (hw->mac.ops.disable_tx_laser &&
7871 ((hw->phy.multispeed_fiber) ||
7872 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7873 (hw->mac.type == ixgbe_mac_82599EB))))
7874 hw->mac.ops.disable_tx_laser(hw);
7875
Jesse Brandeburg54386462009-04-17 20:44:27 +00007876 /* carrier off reporting is important to ethtool even BEFORE open */
7877 netif_carrier_off(netdev);
7878
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007879#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007880 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007881 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007882 ixgbe_setup_dca(adapter);
7883 }
7884#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007885 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007886 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007887 for (i = 0; i < adapter->num_vfs; i++)
7888 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7889 }
7890
Jacob Keller2466dd92011-09-08 03:50:54 +00007891 /* firmware requires driver version to be 0xFFFFFFFF
7892 * since os does not support feature
7893 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007894 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007895 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7896 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007897
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007898 /* add san mac addr to netdev */
7899 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007900
Neerav Parikhea818752012-01-04 20:23:40 +00007901 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007902 cards_found++;
7903 return 0;
7904
7905err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007906 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007907 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007908err_sw_init:
7909err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007910 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7911 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007912 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007913 iounmap(hw->hw_addr);
7914err_ioremap:
7915 free_netdev(netdev);
7916err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007917 pci_release_selected_regions(pdev,
7918 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007919err_pci_reg:
7920err_dma:
7921 pci_disable_device(pdev);
7922 return err;
7923}
7924
7925/**
7926 * ixgbe_remove - Device Removal Routine
7927 * @pdev: PCI device information struct
7928 *
7929 * ixgbe_remove is called by the PCI subsystem to alert the driver
7930 * that it should release a PCI device. The could be caused by a
7931 * Hot-Plug event, or because the driver is going to be removed from
7932 * memory.
7933 **/
7934static void __devexit ixgbe_remove(struct pci_dev *pdev)
7935{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007936 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7937 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007938
7939 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007940 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007941
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007942#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007943 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7944 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7945 dca_remove_requester(&pdev->dev);
7946 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7947 }
7948
7949#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007950#ifdef IXGBE_FCOE
7951 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7952 ixgbe_cleanup_fcoe(adapter);
7953
7954#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007955
7956 /* remove the added san mac */
7957 ixgbe_del_sanmac_netdev(netdev);
7958
Donald Skidmorec4900be2008-11-20 21:11:42 -08007959 if (netdev->reg_state == NETREG_REGISTERED)
7960 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007961
Greg Rosec6bda302011-08-24 02:37:55 +00007962 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7963 if (!(ixgbe_check_vf_assignment(adapter)))
7964 ixgbe_disable_sriov(adapter);
7965 else
7966 e_dev_warn("Unloading driver while VFs are assigned "
7967 "- VFs will not be deallocated\n");
7968 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007969
Alexander Duyck7a921c92009-05-06 10:43:28 +00007970 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007971
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007972 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007973
7974 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007975 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007976 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007977
Emil Tantilov849c4542010-06-03 16:53:41 +00007978 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007979
Auke Kok9a799d72007-09-15 14:07:45 -07007980 free_netdev(netdev);
7981
Frans Pop19d5afd2009-10-02 10:04:12 -07007982 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007983
Auke Kok9a799d72007-09-15 14:07:45 -07007984 pci_disable_device(pdev);
7985}
7986
7987/**
7988 * ixgbe_io_error_detected - called when PCI error is detected
7989 * @pdev: Pointer to PCI device
7990 * @state: The current pci connection state
7991 *
7992 * This function is called after a PCI bus error affecting
7993 * this device has been detected.
7994 */
7995static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007996 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007997{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007998 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7999 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008000
Greg Rose83c61fa2011-09-07 05:59:35 +00008001#ifdef CONFIG_PCI_IOV
8002 struct pci_dev *bdev, *vfdev;
8003 u32 dw0, dw1, dw2, dw3;
8004 int vf, pos;
8005 u16 req_id, pf_func;
8006
8007 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8008 adapter->num_vfs == 0)
8009 goto skip_bad_vf_detection;
8010
8011 bdev = pdev->bus->self;
8012 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8013 bdev = bdev->bus->self;
8014
8015 if (!bdev)
8016 goto skip_bad_vf_detection;
8017
8018 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8019 if (!pos)
8020 goto skip_bad_vf_detection;
8021
8022 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8023 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8024 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8025 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8026
8027 req_id = dw1 >> 16;
8028 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8029 if (!(req_id & 0x0080))
8030 goto skip_bad_vf_detection;
8031
8032 pf_func = req_id & 0x01;
8033 if ((pf_func & 1) == (pdev->devfn & 1)) {
8034 unsigned int device_id;
8035
8036 vf = (req_id & 0x7F) >> 1;
8037 e_dev_err("VF %d has caused a PCIe error\n", vf);
8038 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8039 "%8.8x\tdw3: %8.8x\n",
8040 dw0, dw1, dw2, dw3);
8041 switch (adapter->hw.mac.type) {
8042 case ixgbe_mac_82599EB:
8043 device_id = IXGBE_82599_VF_DEVICE_ID;
8044 break;
8045 case ixgbe_mac_X540:
8046 device_id = IXGBE_X540_VF_DEVICE_ID;
8047 break;
8048 default:
8049 device_id = 0;
8050 break;
8051 }
8052
8053 /* Find the pci device of the offending VF */
8054 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8055 while (vfdev) {
8056 if (vfdev->devfn == (req_id & 0xFF))
8057 break;
8058 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8059 device_id, vfdev);
8060 }
8061 /*
8062 * There's a slim chance the VF could have been hot plugged,
8063 * so if it is no longer present we don't need to issue the
8064 * VFLR. Just clean up the AER in that case.
8065 */
8066 if (vfdev) {
8067 e_dev_err("Issuing VFLR to VF %d\n", vf);
8068 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8069 }
8070
8071 pci_cleanup_aer_uncorrect_error_status(pdev);
8072 }
8073
8074 /*
8075 * Even though the error may have occurred on the other port
8076 * we still need to increment the vf error reference count for
8077 * both ports because the I/O resume function will be called
8078 * for both of them.
8079 */
8080 adapter->vferr_refcount++;
8081
8082 return PCI_ERS_RESULT_RECOVERED;
8083
8084skip_bad_vf_detection:
8085#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008086 netif_device_detach(netdev);
8087
Breno Leitao3044b8d2009-05-06 10:44:26 +00008088 if (state == pci_channel_io_perm_failure)
8089 return PCI_ERS_RESULT_DISCONNECT;
8090
Auke Kok9a799d72007-09-15 14:07:45 -07008091 if (netif_running(netdev))
8092 ixgbe_down(adapter);
8093 pci_disable_device(pdev);
8094
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008095 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008096 return PCI_ERS_RESULT_NEED_RESET;
8097}
8098
8099/**
8100 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8101 * @pdev: Pointer to PCI device
8102 *
8103 * Restart the card from scratch, as if from a cold-boot.
8104 */
8105static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8106{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008107 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008108 pci_ers_result_t result;
8109 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008110
gouji-new9ce77662009-05-06 10:44:45 +00008111 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008112 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008113 result = PCI_ERS_RESULT_DISCONNECT;
8114 } else {
8115 pci_set_master(pdev);
8116 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008117 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008118
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008119 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008120
8121 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008122 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008123 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008124 }
Auke Kok9a799d72007-09-15 14:07:45 -07008125
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008126 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8127 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008128 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8129 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008130 /* non-fatal, continue */
8131 }
Auke Kok9a799d72007-09-15 14:07:45 -07008132
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008133 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008134}
8135
8136/**
8137 * ixgbe_io_resume - called when traffic can start flowing again.
8138 * @pdev: Pointer to PCI device
8139 *
8140 * This callback is called when the error recovery driver tells us that
8141 * its OK to resume normal operation.
8142 */
8143static void ixgbe_io_resume(struct pci_dev *pdev)
8144{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008145 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8146 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008147
Greg Rose83c61fa2011-09-07 05:59:35 +00008148#ifdef CONFIG_PCI_IOV
8149 if (adapter->vferr_refcount) {
8150 e_info(drv, "Resuming after VF err\n");
8151 adapter->vferr_refcount--;
8152 return;
8153 }
8154
8155#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008156 if (netif_running(netdev))
8157 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008158
8159 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008160}
8161
8162static struct pci_error_handlers ixgbe_err_handler = {
8163 .error_detected = ixgbe_io_error_detected,
8164 .slot_reset = ixgbe_io_slot_reset,
8165 .resume = ixgbe_io_resume,
8166};
8167
8168static struct pci_driver ixgbe_driver = {
8169 .name = ixgbe_driver_name,
8170 .id_table = ixgbe_pci_tbl,
8171 .probe = ixgbe_probe,
8172 .remove = __devexit_p(ixgbe_remove),
8173#ifdef CONFIG_PM
8174 .suspend = ixgbe_suspend,
8175 .resume = ixgbe_resume,
8176#endif
8177 .shutdown = ixgbe_shutdown,
8178 .err_handler = &ixgbe_err_handler
8179};
8180
8181/**
8182 * ixgbe_init_module - Driver Registration Routine
8183 *
8184 * ixgbe_init_module is the first routine called when the driver is
8185 * loaded. All it does is register with the PCI subsystem.
8186 **/
8187static int __init ixgbe_init_module(void)
8188{
8189 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008190 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008191 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008192
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008193#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008194 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008195#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008196
Auke Kok9a799d72007-09-15 14:07:45 -07008197 ret = pci_register_driver(&ixgbe_driver);
8198 return ret;
8199}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008200
Auke Kok9a799d72007-09-15 14:07:45 -07008201module_init(ixgbe_init_module);
8202
8203/**
8204 * ixgbe_exit_module - Driver Exit Cleanup Routine
8205 *
8206 * ixgbe_exit_module is called just before the driver is removed
8207 * from memory.
8208 **/
8209static void __exit ixgbe_exit_module(void)
8210{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008211#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008212 dca_unregister_notify(&dca_notifier);
8213#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008214 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008215 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008216}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008217
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008218#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008219static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008220 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008221{
8222 int ret_val;
8223
8224 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008225 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008226
8227 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8228}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008229
Alexander Duyckb4533682009-03-31 21:32:42 +00008230#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008231
Auke Kok9a799d72007-09-15 14:07:45 -07008232module_exit(ixgbe_exit_module);
8233
8234/* ixgbe_main.c */