blob: 23a466530a04cb86955ca1190a704729104194a8 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duycke4f74022012-01-31 02:59:44 +0000369 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 tx_buffer_info = &tx_ring->tx_buffer_info[i];
371 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000373 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 le64_to_cpu(u0->a),
375 le64_to_cpu(u0->b),
376 (u64)tx_buffer_info->dma,
377 tx_buffer_info->length,
378 tx_buffer_info->next_to_watch,
379 (u64)tx_buffer_info->time_stamp,
380 tx_buffer_info->skb);
381 if (i == tx_ring->next_to_use &&
382 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 else
Joe Perchesc7689572010-09-07 21:35:17 +0000389 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390
391 if (netif_msg_pktdata(adapter) &&
392 tx_buffer_info->dma != 0)
393 print_hex_dump(KERN_INFO, "",
394 DUMP_PREFIX_ADDRESS, 16, 1,
395 phys_to_virt(tx_buffer_info->dma),
396 tx_buffer_info->length, true);
397 }
398 }
399
400 /* Print RX Rings Summary */
401rx_ring_summary:
402 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000403 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 for (n = 0; n < adapter->num_rx_queues; n++) {
405 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000406 pr_info("%5d %5X %5X\n",
407 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 }
409
410 /* Print RX Rings */
411 if (!netif_msg_rx_status(adapter))
412 goto exit;
413
414 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
415
416 /* Advanced Receive Descriptor (Read) Format
417 * 63 1 0
418 * +-----------------------------------------------------+
419 * 0 | Packet Buffer Address [63:1] |A0/NSE|
420 * +----------------------------------------------+------+
421 * 8 | Header Buffer Address [63:1] | DD |
422 * +-----------------------------------------------------+
423 *
424 *
425 * Advanced Receive Descriptor (Write-Back) Format
426 *
427 * 63 48 47 32 31 30 21 20 16 15 4 3 0
428 * +------------------------------------------------------+
429 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
430 * | Checksum Ident | | | | Type | Type |
431 * +------------------------------------------------------+
432 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
433 * +------------------------------------------------------+
434 * 63 48 47 32 31 20 19 0
435 */
436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
440 pr_info("------------------------------------\n");
441 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
443 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000444 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 "[vl er S cks ln] ---------------- [bi->skb] "
446 "<-- Adv Rx Write-Back format\n");
447
448 for (i = 0; i < rx_ring->count; i++) {
449 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000450 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 u0 = (struct my_u0 *)rx_desc;
452 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
453 if (staterr & IXGBE_RXD_STAT_DD) {
454 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 "%016llX ---------------- %p", i,
457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
459 rx_buffer_info->skb);
460 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000461 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 "%016llX %016llX %p", i,
463 le64_to_cpu(u0->a),
464 le64_to_cpu(u0->b),
465 (u64)rx_buffer_info->dma,
466 rx_buffer_info->skb);
467
468 if (netif_msg_pktdata(adapter)) {
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
471 phys_to_virt(rx_buffer_info->dma),
472 rx_ring->rx_buf_len, true);
473
474 if (rx_ring->rx_buf_len
Alexander Duyck919e78a2011-08-26 09:52:38 +0000475 < IXGBE_RXBUFFER_2K)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000476 print_hex_dump(KERN_INFO, "",
477 DUMP_PREFIX_ADDRESS, 16, 1,
478 phys_to_virt(
479 rx_buffer_info->page_dma +
480 rx_buffer_info->page_offset
481 ),
482 PAGE_SIZE/2, true);
483 }
484 }
485
486 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000488 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 else
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492
493 }
494 }
495
496exit:
497 return;
498}
499
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800500static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware take over control of h/w */
505 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000507 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800508}
509
510static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
511{
512 u32 ctrl_ext;
513
514 /* Let firmware know the driver has taken over */
515 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
516 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000517 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800518}
Auke Kok9a799d72007-09-15 14:07:45 -0700519
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000520/*
521 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
522 * @adapter: pointer to adapter struct
523 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
524 * @queue: queue to map the corresponding interrupt to
525 * @msix_vector: the vector to map to the corresponding queue
526 *
527 */
528static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000529 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
531 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000532 struct ixgbe_hw *hw = &adapter->hw;
533 switch (hw->mac.type) {
534 case ixgbe_mac_82598EB:
535 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
536 if (direction == -1)
537 direction = 0;
538 index = (((direction * 64) + queue) >> 2) & 0x1F;
539 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
540 ivar &= ~(0xFF << (8 * (queue & 0x3)));
541 ivar |= (msix_vector << (8 * (queue & 0x3)));
542 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
543 break;
544 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800545 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000546 if (direction == -1) {
547 /* other causes */
548 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
549 index = ((queue & 1) * 8);
550 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
551 ivar &= ~(0xFF << index);
552 ivar |= (msix_vector << index);
553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
554 break;
555 } else {
556 /* tx or rx causes */
557 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
558 index = ((16 * (queue & 1)) + (8 * direction));
559 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
560 ivar &= ~(0xFF << index);
561 ivar |= (msix_vector << index);
562 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
563 break;
564 }
565 default:
566 break;
567 }
Auke Kok9a799d72007-09-15 14:07:45 -0700568}
569
Alexander Duyckfe49f042009-06-04 16:00:09 +0000570static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572{
573 u32 mask;
574
Alexander Duyckbd508172010-11-16 19:27:03 -0800575 switch (adapter->hw.mac.type) {
576 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000577 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
578 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800579 break;
580 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800581 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000582 mask = (qmask & 0xFFFFFFFF);
583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
584 mask = (qmask >> 32);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800586 break;
587 default:
588 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000589 }
590}
591
Alexander Duyckd3d00232011-07-15 02:31:25 +0000592static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
593 struct ixgbe_tx_buffer *tx_buffer)
594{
595 if (tx_buffer->dma) {
596 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
597 dma_unmap_page(ring->dev,
598 tx_buffer->dma,
599 tx_buffer->length,
600 DMA_TO_DEVICE);
601 else
602 dma_unmap_single(ring->dev,
603 tx_buffer->dma,
604 tx_buffer->length,
605 DMA_TO_DEVICE);
606 }
607 tx_buffer->dma = 0;
608}
609
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800610void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
611 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700612{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000613 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
614 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700615 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000616 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700617 /* tx_buffer_info must be completely set up in the transmit path */
618}
619
John Fastabendc84d3242010-11-16 19:27:12 -0800620static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700621{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700622 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800623 struct ixgbe_hw_stats *hwstats = &adapter->stats;
624 u32 data = 0;
625 u32 xoff[8] = {0};
626 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700627
John Fastabendc84d3242010-11-16 19:27:12 -0800628 if ((hw->fc.current_mode == ixgbe_fc_full) ||
629 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
630 switch (hw->mac.type) {
631 case ixgbe_mac_82598EB:
632 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
633 break;
634 default:
635 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
636 }
637 hwstats->lxoffrxc += data;
638
639 /* refill credits (no tx hang) if we received xoff */
640 if (!data)
641 return;
642
643 for (i = 0; i < adapter->num_tx_queues; i++)
644 clear_bit(__IXGBE_HANG_CHECK_ARMED,
645 &adapter->tx_ring[i]->state);
646 return;
647 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
648 return;
649
650 /* update stats for each tc, only valid with PFC enabled */
651 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
652 switch (hw->mac.type) {
653 case ixgbe_mac_82598EB:
654 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
655 break;
656 default:
657 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
658 }
659 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700660 }
661
John Fastabendc84d3242010-11-16 19:27:12 -0800662 /* disarm tx queues that have received xoff frames */
663 for (i = 0; i < adapter->num_tx_queues; i++) {
664 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000665 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800666
667 if (xoff[tc])
668 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
669 }
670}
671
672static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
673{
674 return ring->tx_stats.completed;
675}
676
677static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
678{
679 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
680 struct ixgbe_hw *hw = &adapter->hw;
681
682 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
683 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
684
685 if (head != tail)
686 return (head < tail) ?
687 tail - head : (tail + ring->count - head);
688
689 return 0;
690}
691
692static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
693{
694 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
695 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
696 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
697 bool ret = false;
698
699 clear_check_for_tx_hang(tx_ring);
700
701 /*
702 * Check for a hung queue, but be thorough. This verifies
703 * that a transmit has been completed since the previous
704 * check AND there is at least one packet pending. The
705 * ARMED bit is set to indicate a potential hang. The
706 * bit is cleared if a pause frame is received to remove
707 * false hang detection due to PFC or 802.3x frames. By
708 * requiring this to fail twice we avoid races with
709 * pfc clearing the ARMED bit and conditions where we
710 * run the check_tx_hang logic with a transmit completion
711 * pending but without time to complete it yet.
712 */
713 if ((tx_done_old == tx_done) && tx_pending) {
714 /* make sure it is true for two checks in a row */
715 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
716 &tx_ring->state);
717 } else {
718 /* update completed stats and continue */
719 tx_ring->tx_stats.tx_done_old = tx_done;
720 /* reset the countdown */
721 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
722 }
723
724 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700725}
726
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000727/**
728 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
729 * @adapter: driver private struct
730 **/
731static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
732{
733
734 /* Do the reset outside of interrupt context */
735 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
736 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
737 ixgbe_service_event_schedule(adapter);
738 }
739}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700740
Auke Kok9a799d72007-09-15 14:07:45 -0700741/**
742 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000743 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700744 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700745 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000746static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000747 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700748{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000749 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 struct ixgbe_tx_buffer *tx_buffer;
751 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700752 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000753 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000754 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700755
Alexander Duyckd3d00232011-07-15 02:31:25 +0000756 tx_buffer = &tx_ring->tx_buffer_info[i];
Alexander Duycke4f74022012-01-31 02:59:44 +0000757 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800758
Alexander Duyck30065e62011-07-15 03:05:14 +0000759 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000760 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700761
Alexander Duyckd3d00232011-07-15 02:31:25 +0000762 /* if next_to_watch is not set then there is no work pending */
763 if (!eop_desc)
764 break;
765
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;
Alexander Duycke4f74022012-01-31 02:59:44 +0000798 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000799 }
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 Duycke4f74022012-01-31 02:59:44 +0000815 tx_desc = IXGBE_TX_DESC(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
Alexander Duyck8a0da212012-01-31 02:59:49 +0000994static inline void ixgbe_rx_hash(struct ixgbe_ring *ring,
995 union ixgbe_adv_rx_desc *rx_desc,
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000996 struct sk_buff *skb)
997{
Alexander Duyck8a0da212012-01-31 02:59:49 +0000998 if (ring->netdev->features & NETIF_F_RXHASH)
999 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001000}
1001
Auke Kok9a799d72007-09-15 14:07:45 -07001002/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001003 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1004 * @adapter: address of board private structure
1005 * @rx_desc: advanced rx descriptor
1006 *
1007 * Returns : true if it is FCoE pkt
1008 */
1009static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1010 union ixgbe_adv_rx_desc *rx_desc)
1011{
1012 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1013
1014 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1015 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1016 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1017 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1018}
1019
1020/**
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001021 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
Alexander Duyck8a0da212012-01-31 02:59:49 +00001022 * @ring: structure containing ring specific data
1023 * @rx_desc: current Rx descriptor being processed
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001024 * @skb: skb currently being received and modified
1025 **/
Alexander Duyck8a0da212012-01-31 02:59:49 +00001026static inline void ixgbe_rx_checksum(struct ixgbe_ring *ring,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001027 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001028 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001029{
Alexander Duyck8a0da212012-01-31 02:59:49 +00001030 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001031
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001032 /* Rx csum disabled */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001033 if (!(ring->netdev->features & NETIF_F_RXCSUM))
Auke Kok9a799d72007-09-15 14:07:45 -07001034 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001035
1036 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001037 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1038 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Alexander Duyck8a0da212012-01-31 02:59:49 +00001039 ring->rx_stats.csum_err++;
Auke Kok9a799d72007-09-15 14:07:45 -07001040 return;
1041 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001042
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001043 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001044 return;
1045
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001046 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001047 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1048
1049 /*
1050 * 82599 errata, UDP frames with a 0 checksum can be marked as
1051 * checksum errors.
1052 */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001053 if ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_UDP)) &&
1054 test_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state))
Don Skidmore8bae1b22009-07-23 18:00:39 +00001055 return;
1056
Alexander Duyck8a0da212012-01-31 02:59:49 +00001057 ring->rx_stats.csum_err++;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001058 return;
1059 }
1060
Auke Kok9a799d72007-09-15 14:07:45 -07001061 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001062 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001063}
1064
Alexander Duyck84ea2592010-11-16 19:26:49 -08001065static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001066{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001067 rx_ring->next_to_use = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001068 /*
1069 * Force memory writes to complete before letting h/w
1070 * know there are new descriptors to fetch. (Only
1071 * applicable for weak-ordered memory model archs,
1072 * such as IA-64).
1073 */
1074 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001075 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001076}
1077
Alexander Duyckf990b792012-01-31 02:59:34 +00001078static bool ixgbe_alloc_mapped_skb(struct ixgbe_ring *rx_ring,
1079 struct ixgbe_rx_buffer *bi)
1080{
1081 struct sk_buff *skb = bi->skb;
1082 dma_addr_t dma = bi->dma;
1083
1084 if (dma)
1085 return true;
1086
1087 if (likely(!skb)) {
1088 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1089 rx_ring->rx_buf_len);
1090 bi->skb = skb;
1091 if (!skb) {
1092 rx_ring->rx_stats.alloc_rx_buff_failed++;
1093 return false;
1094 }
Alexander Duyckf990b792012-01-31 02:59:34 +00001095 }
1096
1097 dma = dma_map_single(rx_ring->dev, skb->data,
1098 rx_ring->rx_buf_len, DMA_FROM_DEVICE);
1099
1100 if (dma_mapping_error(rx_ring->dev, dma)) {
1101 rx_ring->rx_stats.alloc_rx_buff_failed++;
1102 return false;
1103 }
1104
1105 bi->dma = dma;
1106 return true;
1107}
1108
1109static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1110 struct ixgbe_rx_buffer *bi)
1111{
1112 struct page *page = bi->page;
1113 dma_addr_t page_dma = bi->page_dma;
1114 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
1115
1116 if (page_dma)
1117 return true;
1118
1119 if (!page) {
1120 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1121 bi->page = page;
1122 if (unlikely(!page)) {
1123 rx_ring->rx_stats.alloc_rx_page_failed++;
1124 return false;
1125 }
1126 }
1127
1128 page_dma = dma_map_page(rx_ring->dev, page,
1129 page_offset, PAGE_SIZE / 2,
1130 DMA_FROM_DEVICE);
1131
1132 if (dma_mapping_error(rx_ring->dev, page_dma)) {
1133 rx_ring->rx_stats.alloc_rx_page_failed++;
1134 return false;
1135 }
1136
1137 bi->page_dma = page_dma;
1138 bi->page_offset = page_offset;
1139 return true;
1140}
1141
Auke Kok9a799d72007-09-15 14:07:45 -07001142/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001143 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001144 * @rx_ring: ring to place buffers on
1145 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001146 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001147void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001148{
Auke Kok9a799d72007-09-15 14:07:45 -07001149 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001150 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001151 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001152
Alexander Duyckf990b792012-01-31 02:59:34 +00001153 /* nothing to do or no valid netdev defined */
1154 if (!cleaned_count || !rx_ring->netdev)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001155 return;
1156
Alexander Duycke4f74022012-01-31 02:59:44 +00001157 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Alexander Duyckf990b792012-01-31 02:59:34 +00001158 bi = &rx_ring->rx_buffer_info[i];
1159 i -= rx_ring->count;
1160
Auke Kok9a799d72007-09-15 14:07:45 -07001161 while (cleaned_count--) {
Alexander Duyckf990b792012-01-31 02:59:34 +00001162 if (!ixgbe_alloc_mapped_skb(rx_ring, bi))
1163 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001164
Alexander Duyckf990b792012-01-31 02:59:34 +00001165 /* Refresh the desc even if buffer_addrs didn't change
1166 * because each write-back erases this info. */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001167 if (ring_is_ps_enabled(rx_ring)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001168 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Alexander Duyckf990b792012-01-31 02:59:34 +00001169
1170 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1171 break;
1172
1173 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001174 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001175 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001176 }
1177
Alexander Duyckf990b792012-01-31 02:59:34 +00001178 rx_desc++;
1179 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001180 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001181 if (unlikely(!i)) {
Alexander Duycke4f74022012-01-31 02:59:44 +00001182 rx_desc = IXGBE_RX_DESC(rx_ring, 0);
Alexander Duyckf990b792012-01-31 02:59:34 +00001183 bi = rx_ring->rx_buffer_info;
1184 i -= rx_ring->count;
1185 }
1186
1187 /* clear the hdr_addr for the next_to_use descriptor */
1188 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001189 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001190
Alexander Duyckf990b792012-01-31 02:59:34 +00001191 i += rx_ring->count;
1192
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001193 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001194 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001195}
1196
Alexander Duyckc267fc12010-11-16 19:27:00 -08001197static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001198{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001199 /* HW will not DMA in data larger than the given buffer, even if it
1200 * parses the (NFS, of course) header to be larger. In that case, it
1201 * fills the header buffer and spills the rest into the page.
1202 */
1203 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1204 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1205 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1206 if (hlen > IXGBE_RX_HDR_SIZE)
1207 hlen = IXGBE_RX_HDR_SIZE;
1208 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001209}
1210
Alexander Duyckf8212f92009-04-27 22:42:37 +00001211/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001212 * ixgbe_merge_active_tail - merge active tail into lro skb
1213 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001214 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001215 * This function merges the length and data of an active tail into the
1216 * skb containing the frag_list. It resets the tail's pointer to the head,
1217 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001218 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001219static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001220{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001221 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001222
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001223 if (!head)
1224 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001225
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001226 head->len += tail->len;
1227 head->data_len += tail->len;
1228 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001229
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001230 IXGBE_CB(tail)->head = NULL;
1231
1232 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001233}
1234
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001235/**
1236 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1237 * @head: pointer to the start of the skb
1238 * @tail: pointer to active tail to add to frag_list
1239 *
1240 * This function adds an active tail to the end of the frag list. This tail
1241 * will still be receiving data so we cannot yet ad it's stats to the main
1242 * skb. That is done via ixgbe_merge_active_tail.
1243 **/
1244static inline void ixgbe_add_active_tail(struct sk_buff *head,
1245 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001246{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001247 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1248
1249 if (old_tail) {
1250 ixgbe_merge_active_tail(old_tail);
1251 old_tail->next = tail;
1252 } else {
1253 skb_shinfo(head)->frag_list = tail;
1254 }
1255
1256 IXGBE_CB(tail)->head = head;
1257 IXGBE_CB(head)->tail = tail;
1258}
1259
1260/**
1261 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1262 * @head: pointer to head of an active frag list
1263 *
1264 * This function will clear the frag_tail_tracker pointer on an active
1265 * frag_list and returns true if the pointer was actually set
1266 **/
1267static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1268{
1269 struct sk_buff *tail = IXGBE_CB(head)->tail;
1270
1271 if (!tail)
1272 return false;
1273
1274 ixgbe_merge_active_tail(tail);
1275
1276 IXGBE_CB(head)->tail = NULL;
1277
1278 return true;
1279}
1280
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001281/**
1282 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1283 * @data: pointer to the start of the headers
1284 * @max_len: total length of section to find headers in
1285 *
1286 * This function is meant to determine the length of headers that will
1287 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1288 * motivation of doing this is to only perform one pull for IPv4 TCP
1289 * packets so that we can do basic things like calculating the gso_size
1290 * based on the average data per packet.
1291 **/
1292static unsigned int ixgbe_get_headlen(unsigned char *data,
1293 unsigned int max_len)
1294{
1295 union {
1296 unsigned char *network;
1297 /* l2 headers */
1298 struct ethhdr *eth;
1299 struct vlan_hdr *vlan;
1300 /* l3 headers */
1301 struct iphdr *ipv4;
1302 } hdr;
1303 __be16 protocol;
1304 u8 nexthdr = 0; /* default to not TCP */
1305 u8 hlen;
1306
1307 /* this should never happen, but better safe than sorry */
1308 if (max_len < ETH_HLEN)
1309 return max_len;
1310
1311 /* initialize network frame pointer */
1312 hdr.network = data;
1313
1314 /* set first protocol and move network header forward */
1315 protocol = hdr.eth->h_proto;
1316 hdr.network += ETH_HLEN;
1317
1318 /* handle any vlan tag if present */
1319 if (protocol == __constant_htons(ETH_P_8021Q)) {
1320 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1321 return max_len;
1322
1323 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1324 hdr.network += VLAN_HLEN;
1325 }
1326
1327 /* handle L3 protocols */
1328 if (protocol == __constant_htons(ETH_P_IP)) {
1329 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1330 return max_len;
1331
1332 /* access ihl as a u8 to avoid unaligned access on ia64 */
1333 hlen = (hdr.network[0] & 0x0F) << 2;
1334
1335 /* verify hlen meets minimum size requirements */
1336 if (hlen < sizeof(struct iphdr))
1337 return hdr.network - data;
1338
1339 /* record next protocol */
1340 nexthdr = hdr.ipv4->protocol;
1341 hdr.network += hlen;
1342#ifdef CONFIG_FCOE
1343 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1344 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1345 return max_len;
1346 hdr.network += FCOE_HEADER_LEN;
1347#endif
1348 } else {
1349 return hdr.network - data;
1350 }
1351
1352 /* finally sort out TCP */
1353 if (nexthdr == IPPROTO_TCP) {
1354 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1355 return max_len;
1356
1357 /* access doff as a u8 to avoid unaligned access on ia64 */
1358 hlen = (hdr.network[12] & 0xF0) >> 2;
1359
1360 /* verify hlen meets minimum size requirements */
1361 if (hlen < sizeof(struct tcphdr))
1362 return hdr.network - data;
1363
1364 hdr.network += hlen;
1365 }
1366
1367 /*
1368 * If everything has gone correctly hdr.network should be the
1369 * data section of the packet and will be the end of the header.
1370 * If not then it probably represents the end of the last recognized
1371 * header.
1372 */
1373 if ((hdr.network - data) < max_len)
1374 return hdr.network - data;
1375 else
1376 return max_len;
1377}
1378
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001379static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1380 union ixgbe_adv_rx_desc *rx_desc,
1381 struct sk_buff *skb)
1382{
1383 __le32 rsc_enabled;
1384 u32 rsc_cnt;
1385
1386 if (!ring_is_rsc_enabled(rx_ring))
1387 return;
1388
1389 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1390 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1391
1392 /* If this is an RSC frame rsc_cnt should be non-zero */
1393 if (!rsc_enabled)
1394 return;
1395
1396 rsc_cnt = le32_to_cpu(rsc_enabled);
1397 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1398
1399 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001400}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001401
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001402static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1403 struct sk_buff *skb)
1404{
1405 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1406
1407 /* set gso_size to avoid messing up TCP MSS */
1408 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1409 IXGBE_CB(skb)->append_cnt);
1410}
1411
1412static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1413 struct sk_buff *skb)
1414{
1415 /* if append_cnt is 0 then frame is not RSC */
1416 if (!IXGBE_CB(skb)->append_cnt)
1417 return;
1418
1419 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1420 rx_ring->rx_stats.rsc_flush++;
1421
1422 ixgbe_set_rsc_gso_size(rx_ring, skb);
1423
1424 /* gso_size is computed using append_cnt so always clear it last */
1425 IXGBE_CB(skb)->append_cnt = 0;
1426}
1427
Alexander Duyck8a0da212012-01-31 02:59:49 +00001428/**
1429 * ixgbe_process_skb_fields - Populate skb header fields from Rx descriptor
1430 * @rx_ring: rx descriptor ring packet is being transacted on
1431 * @rx_desc: pointer to the EOP Rx descriptor
1432 * @skb: pointer to current skb being populated
1433 *
1434 * This function checks the ring, descriptor, and packet information in
1435 * order to populate the hash, checksum, VLAN, timestamp, protocol, and
1436 * other fields within the skb.
1437 **/
1438static void ixgbe_process_skb_fields(struct ixgbe_ring *rx_ring,
1439 union ixgbe_adv_rx_desc *rx_desc,
1440 struct sk_buff *skb)
1441{
1442 ixgbe_update_rsc_stats(rx_ring, skb);
1443
1444 ixgbe_rx_hash(rx_ring, rx_desc, skb);
1445
1446 ixgbe_rx_checksum(rx_ring, rx_desc, skb);
1447
1448 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1449 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1450 __vlan_hwaccel_put_tag(skb, vid);
1451 }
1452
1453 skb_record_rx_queue(skb, rx_ring->queue_index);
1454
1455 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
1456}
1457
1458static void ixgbe_rx_skb(struct ixgbe_q_vector *q_vector,
1459 struct sk_buff *skb)
1460{
1461 struct ixgbe_adapter *adapter = q_vector->adapter;
1462
1463 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1464 napi_gro_receive(&q_vector->napi, skb);
1465 else
1466 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001467}
1468
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001469static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001470 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001471 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001472{
Auke Kok9a799d72007-09-15 14:07:45 -07001473 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001474 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001475 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001476 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001477 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001478#ifdef IXGBE_FCOE
Alexander Duyck8a0da212012-01-31 02:59:49 +00001479 struct ixgbe_adapter *adapter = q_vector->adapter;
Yi Zou3d8fd382009-06-08 14:38:44 +00001480 int ddp_bytes = 0;
1481#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001482 u16 i;
1483 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001484
1485 i = rx_ring->next_to_clean;
Alexander Duycke4f74022012-01-31 02:59:44 +00001486 rx_desc = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001487
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001488 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001489 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001490
Milton Miller3c945e52010-02-19 17:44:42 +00001491 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001492
Alexander Duyckc267fc12010-11-16 19:27:00 -08001493 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1494
Auke Kok9a799d72007-09-15 14:07:45 -07001495 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001496 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001497 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001498
David S. Miller8decf862011-09-22 03:23:13 -04001499 /* linear means we are building an skb from multiple pages */
1500 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001501 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001502 if (ring_is_ps_enabled(rx_ring)) {
1503 hlen = ixgbe_get_hlen(rx_desc);
1504 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1505 } else {
1506 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1507 }
1508
1509 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001510
1511 /*
1512 * Delay unmapping of the first packet. It carries the
1513 * header information, HW may still access the header
1514 * after writeback. Only unmap it when EOP is reached
1515 */
1516 if (!IXGBE_CB(skb)->head) {
1517 IXGBE_CB(skb)->delay_unmap = true;
1518 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1519 } else {
1520 skb = ixgbe_merge_active_tail(skb);
1521 dma_unmap_single(rx_ring->dev,
1522 rx_buffer_info->dma,
1523 rx_ring->rx_buf_len,
1524 DMA_FROM_DEVICE);
1525 }
1526 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001527 } else {
1528 /* assume packet split since header is unmapped */
1529 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001530 }
1531
1532 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001533 dma_unmap_page(rx_ring->dev,
1534 rx_buffer_info->page_dma,
1535 PAGE_SIZE / 2,
1536 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001537 rx_buffer_info->page_dma = 0;
1538 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001539 rx_buffer_info->page,
1540 rx_buffer_info->page_offset,
1541 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001542
Alexander Duyckc267fc12010-11-16 19:27:00 -08001543 if ((page_count(rx_buffer_info->page) == 1) &&
1544 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001545 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001546 else
1547 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001548
1549 skb->len += upper_len;
1550 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001551 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001552 }
1553
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001554 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1555
Auke Kok9a799d72007-09-15 14:07:45 -07001556 i++;
1557 if (i == rx_ring->count)
1558 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001559
Alexander Duycke4f74022012-01-31 02:59:44 +00001560 next_rxd = IXGBE_RX_DESC(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001561 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001562 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001563
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001564 if ((!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001565 struct ixgbe_rx_buffer *next_buffer;
1566 u32 nextp;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001567
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001568 if (IXGBE_CB(skb)->append_cnt) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001569 nextp = le32_to_cpu(
1570 rx_desc->wb.upper.status_error);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001571 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1572 } else {
1573 nextp = i;
1574 }
1575
1576 next_buffer = &rx_ring->rx_buffer_info[nextp];
1577
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001578 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001579 rx_buffer_info->skb = next_buffer->skb;
1580 rx_buffer_info->dma = next_buffer->dma;
1581 next_buffer->skb = skb;
1582 next_buffer->dma = 0;
1583 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001584 struct sk_buff *next_skb = next_buffer->skb;
1585 ixgbe_add_active_tail(skb, next_skb);
1586 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001587 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001588 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001589 goto next_desc;
1590 }
1591
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001592 dma_unmap_single(rx_ring->dev,
1593 IXGBE_CB(skb)->dma,
1594 rx_ring->rx_buf_len,
1595 DMA_FROM_DEVICE);
1596 IXGBE_CB(skb)->dma = 0;
1597 IXGBE_CB(skb)->delay_unmap = false;
1598
1599 if (ixgbe_close_active_frag_list(skb) &&
1600 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001601 /* if we got here without RSC the packet is invalid */
Alexander Duyckff886df2011-06-11 01:45:13 +00001602 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001603 goto next_desc;
1604 }
1605
Auke Kok9a799d72007-09-15 14:07:45 -07001606 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001607 if (unlikely(ixgbe_test_staterr(rx_desc,
1608 IXGBE_RXDADV_ERR_FRAME_ERR_MASK))) {
Auke Kok9a799d72007-09-15 14:07:45 -07001609 dev_kfree_skb_any(skb);
1610 goto next_desc;
1611 }
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001612
1613 /* probably a little skewed due to removing CRC */
1614 total_rx_bytes += skb->len;
1615 total_rx_packets++;
1616
Alexander Duyck8a0da212012-01-31 02:59:49 +00001617 /* populate checksum, timestamp, VLAN, and protocol */
1618 ixgbe_process_skb_fields(rx_ring, rx_desc, skb);
1619
Yi Zou332d4a72009-05-13 13:11:53 +00001620#ifdef IXGBE_FCOE
1621 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001622 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001623 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001624 if (!ddp_bytes) {
1625 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001626 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001627 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001628 }
Yi Zou332d4a72009-05-13 13:11:53 +00001629#endif /* IXGBE_FCOE */
Alexander Duyck8a0da212012-01-31 02:59:49 +00001630 ixgbe_rx_skb(q_vector, skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001631
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001632 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001633next_desc:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001634 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001635 break;
1636
Auke Kok9a799d72007-09-15 14:07:45 -07001637 /* return some buffers to hardware, one at a time is too slow */
1638 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001639 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001640 cleaned_count = 0;
1641 }
1642
1643 /* use prefetched values */
1644 rx_desc = next_rxd;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001645 }
1646
Auke Kok9a799d72007-09-15 14:07:45 -07001647 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001648 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001649
1650 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001651 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001652
Yi Zou3d8fd382009-06-08 14:38:44 +00001653#ifdef IXGBE_FCOE
1654 /* include DDPed FCoE data */
1655 if (ddp_bytes > 0) {
1656 unsigned int mss;
1657
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001658 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001659 sizeof(struct fc_frame_header) -
1660 sizeof(struct fcoe_crc_eof);
1661 if (mss > 512)
1662 mss &= ~511;
1663 total_rx_bytes += ddp_bytes;
1664 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1665 }
1666#endif /* IXGBE_FCOE */
1667
Alexander Duyckc267fc12010-11-16 19:27:00 -08001668 u64_stats_update_begin(&rx_ring->syncp);
1669 rx_ring->stats.packets += total_rx_packets;
1670 rx_ring->stats.bytes += total_rx_bytes;
1671 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001672 q_vector->rx.total_packets += total_rx_packets;
1673 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001674
1675 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001676}
1677
Auke Kok9a799d72007-09-15 14:07:45 -07001678/**
1679 * ixgbe_configure_msix - Configure MSI-X hardware
1680 * @adapter: board private structure
1681 *
1682 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1683 * interrupts.
1684 **/
1685static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1686{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001687 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001688 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001689 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001690
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001691 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1692
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001693 /* Populate MSIX to EITR Select */
1694 if (adapter->num_vfs > 32) {
1695 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1696 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1697 }
1698
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001699 /*
1700 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001701 * corresponding register.
1702 */
1703 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001704 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001705 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001706
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001707 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1708 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001709
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001710 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1711 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001712
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001713 if (q_vector->tx.ring && !q_vector->rx.ring) {
1714 /* tx only vector */
1715 if (adapter->tx_itr_setting == 1)
1716 q_vector->itr = IXGBE_10K_ITR;
1717 else
1718 q_vector->itr = adapter->tx_itr_setting;
1719 } else {
1720 /* rx or rx/tx vector */
1721 if (adapter->rx_itr_setting == 1)
1722 q_vector->itr = IXGBE_20K_ITR;
1723 else
1724 q_vector->itr = adapter->rx_itr_setting;
1725 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001726
Alexander Duyckfe49f042009-06-04 16:00:09 +00001727 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001728 }
1729
Alexander Duyckbd508172010-11-16 19:27:03 -08001730 switch (adapter->hw.mac.type) {
1731 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001732 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001733 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001734 break;
1735 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001736 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001737 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001738 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001739 default:
1740 break;
1741 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001742 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001743
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001744 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001745 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001746 mask &= ~(IXGBE_EIMS_OTHER |
1747 IXGBE_EIMS_MAILBOX |
1748 IXGBE_EIMS_LSC);
1749
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001750 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001751}
1752
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001753enum latency_range {
1754 lowest_latency = 0,
1755 low_latency = 1,
1756 bulk_latency = 2,
1757 latency_invalid = 255
1758};
1759
1760/**
1761 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001762 * @q_vector: structure containing interrupt and ring information
1763 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001764 *
1765 * Stores a new ITR value based on packets and byte
1766 * counts during the last interrupt. The advantage of per interrupt
1767 * computation is faster updates and more accurate ITR for the current
1768 * traffic pattern. Constants in this function were computed
1769 * based on theoretical maximum wire speed and thresholds were set based
1770 * on testing data as well as attempting to minimize response time
1771 * while increasing bulk throughput.
1772 * this functionality is controlled by the InterruptThrottleRate module
1773 * parameter (see ixgbe_param.c)
1774 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001775static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1776 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001777{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001778 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001779 struct ixgbe_adapter *adapter = q_vector->adapter;
1780 int bytes = ring_container->total_bytes;
1781 int packets = ring_container->total_packets;
1782 u32 timepassed_us;
1783 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001784
1785 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001786 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001787
1788 /* simple throttlerate management
1789 * 0-20MB/s lowest (100000 ints/s)
1790 * 20-100MB/s low (20000 ints/s)
1791 * 100-1249MB/s bulk (8000 ints/s)
1792 */
1793 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001794 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001795 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1796
1797 switch (itr_setting) {
1798 case lowest_latency:
1799 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001800 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001801 break;
1802 case low_latency:
1803 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001804 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001805 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001806 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001807 break;
1808 case bulk_latency:
1809 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001810 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001811 break;
1812 }
1813
Alexander Duyckbd198052011-06-11 01:45:08 +00001814 /* clear work counters since we have the values we need */
1815 ring_container->total_bytes = 0;
1816 ring_container->total_packets = 0;
1817
1818 /* write updated itr to ring container */
1819 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001820}
1821
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001822/**
1823 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001824 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001825 *
1826 * This function is made to be called by ethtool and by the driver
1827 * when it needs to update EITR registers at runtime. Hardware
1828 * specific quirks/differences are taken care of here.
1829 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001830void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001831{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001832 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001833 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001834 int v_idx = q_vector->v_idx;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001835 u32 itr_reg = q_vector->itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001836
Alexander Duyckbd508172010-11-16 19:27:03 -08001837 switch (adapter->hw.mac.type) {
1838 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001839 /* must write high and low 16 bits to reset counter */
1840 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001841 break;
1842 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001843 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001844 /*
1845 * set the WDIS bit to not clear the timer bits and cause an
1846 * immediate assertion of the interrupt
1847 */
1848 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001849 break;
1850 default:
1851 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001852 }
1853 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1854}
1855
Alexander Duyckbd198052011-06-11 01:45:08 +00001856static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001857{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001858 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001859 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001860
Alexander Duyckbd198052011-06-11 01:45:08 +00001861 ixgbe_update_itr(q_vector, &q_vector->tx);
1862 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001863
Alexander Duyck08c88332011-06-11 01:45:03 +00001864 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001865
1866 switch (current_itr) {
1867 /* counts and packets in update_itr are dependent on these numbers */
1868 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001869 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001870 break;
1871 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001872 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001873 break;
1874 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001875 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001876 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001877 default:
1878 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001879 }
1880
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001881 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001882 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001883 new_itr = (10 * new_itr * q_vector->itr) /
1884 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001885
Alexander Duyckbd198052011-06-11 01:45:08 +00001886 /* save the algorithm value here */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001887 q_vector->itr = new_itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001888
1889 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001890 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001891}
1892
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001893/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001894 * ixgbe_check_overtemp_subtask - check for over tempurature
1895 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001896 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001897static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001898{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001899 struct ixgbe_hw *hw = &adapter->hw;
1900 u32 eicr = adapter->interrupt_event;
1901
Alexander Duyckf0f97782011-04-22 04:08:09 +00001902 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001903 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001904
Alexander Duyckf0f97782011-04-22 04:08:09 +00001905 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1906 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1907 return;
1908
1909 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1910
Joe Perches7ca647b2010-09-07 21:35:40 +00001911 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001912 case IXGBE_DEV_ID_82599_T3_LOM:
1913 /*
1914 * Since the warning interrupt is for both ports
1915 * we don't have to check if:
1916 * - This interrupt wasn't for our port.
1917 * - We may have missed the interrupt so always have to
1918 * check if we got a LSC
1919 */
1920 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1921 !(eicr & IXGBE_EICR_LSC))
1922 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001923
Alexander Duyckf0f97782011-04-22 04:08:09 +00001924 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1925 u32 autoneg;
1926 bool link_up = false;
1927
Joe Perches7ca647b2010-09-07 21:35:40 +00001928 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1929
Alexander Duyckf0f97782011-04-22 04:08:09 +00001930 if (link_up)
1931 return;
1932 }
1933
1934 /* Check if this is not due to overtemp */
1935 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1936 return;
1937
1938 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001939 default:
1940 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1941 return;
1942 break;
1943 }
1944 e_crit(drv,
1945 "Network adapter has been stopped because it has over heated. "
1946 "Restart the computer. If the problem persists, "
1947 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001948
1949 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001950}
1951
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001952static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1953{
1954 struct ixgbe_hw *hw = &adapter->hw;
1955
1956 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1957 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001958 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001959 /* write to clear the interrupt */
1960 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1961 }
1962}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001963
Jacob Keller4f51bf72011-08-20 04:49:45 +00001964static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1965{
1966 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1967 return;
1968
1969 switch (adapter->hw.mac.type) {
1970 case ixgbe_mac_82599EB:
1971 /*
1972 * Need to check link state so complete overtemp check
1973 * on service task
1974 */
1975 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1976 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1977 adapter->interrupt_event = eicr;
1978 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1979 ixgbe_service_event_schedule(adapter);
1980 return;
1981 }
1982 return;
1983 case ixgbe_mac_X540:
1984 if (!(eicr & IXGBE_EICR_TS))
1985 return;
1986 break;
1987 default:
1988 return;
1989 }
1990
1991 e_crit(drv,
1992 "Network adapter has been stopped because it has over heated. "
1993 "Restart the computer. If the problem persists, "
1994 "power off the system and replace the adapter\n");
1995}
1996
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001997static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1998{
1999 struct ixgbe_hw *hw = &adapter->hw;
2000
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002001 if (eicr & IXGBE_EICR_GPI_SDP2) {
2002 /* Clear the interrupt */
2003 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00002004 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2005 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
2006 ixgbe_service_event_schedule(adapter);
2007 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08002008 }
2009
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002010 if (eicr & IXGBE_EICR_GPI_SDP1) {
2011 /* Clear the interrupt */
2012 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002013 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2014 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2015 ixgbe_service_event_schedule(adapter);
2016 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002017 }
2018}
2019
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002020static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2021{
2022 struct ixgbe_hw *hw = &adapter->hw;
2023
2024 adapter->lsc_int++;
2025 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2026 adapter->link_check_timeout = jiffies;
2027 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2028 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002029 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002030 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002031 }
2032}
2033
Alexander Duyckfe49f042009-06-04 16:00:09 +00002034static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2035 u64 qmask)
2036{
2037 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002038 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002039
Alexander Duyckbd508172010-11-16 19:27:03 -08002040 switch (hw->mac.type) {
2041 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002042 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002043 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2044 break;
2045 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002046 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002047 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002048 if (mask)
2049 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002050 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002051 if (mask)
2052 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2053 break;
2054 default:
2055 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002056 }
2057 /* skip the flush */
2058}
2059
2060static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002061 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002062{
2063 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002064 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002065
Alexander Duyckbd508172010-11-16 19:27:03 -08002066 switch (hw->mac.type) {
2067 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002068 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002069 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2070 break;
2071 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002072 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002073 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002074 if (mask)
2075 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002076 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002077 if (mask)
2078 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2079 break;
2080 default:
2081 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002082 }
2083 /* skip the flush */
2084}
2085
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002086/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002087 * ixgbe_irq_enable - Enable default interrupt generation settings
2088 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002089 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002090static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2091 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002092{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002093 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002094
Alexander Duyck2c4af692011-07-15 07:29:55 +00002095 /* don't reenable LSC while waiting for link */
2096 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2097 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002098
Alexander Duyck2c4af692011-07-15 07:29:55 +00002099 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002100 switch (adapter->hw.mac.type) {
2101 case ixgbe_mac_82599EB:
2102 mask |= IXGBE_EIMS_GPI_SDP0;
2103 break;
2104 case ixgbe_mac_X540:
2105 mask |= IXGBE_EIMS_TS;
2106 break;
2107 default:
2108 break;
2109 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002110 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2111 mask |= IXGBE_EIMS_GPI_SDP1;
2112 switch (adapter->hw.mac.type) {
2113 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002114 mask |= IXGBE_EIMS_GPI_SDP1;
2115 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002116 case ixgbe_mac_X540:
2117 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002118 mask |= IXGBE_EIMS_MAILBOX;
2119 break;
2120 default:
2121 break;
2122 }
2123 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2124 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2125 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002126
Alexander Duyck2c4af692011-07-15 07:29:55 +00002127 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2128 if (queues)
2129 ixgbe_irq_enable_queues(adapter, ~0);
2130 if (flush)
2131 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002132}
2133
Alexander Duyck2c4af692011-07-15 07:29:55 +00002134static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002135{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002136 struct ixgbe_adapter *adapter = data;
2137 struct ixgbe_hw *hw = &adapter->hw;
2138 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002139
Alexander Duyck2c4af692011-07-15 07:29:55 +00002140 /*
2141 * Workaround for Silicon errata. Use clear-by-write instead
2142 * of clear-by-read. Reading with EICS will return the
2143 * interrupt causes without clearing, which later be done
2144 * with the write to EICR.
2145 */
2146 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2147 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002148
Alexander Duyck2c4af692011-07-15 07:29:55 +00002149 if (eicr & IXGBE_EICR_LSC)
2150 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002151
Alexander Duyck2c4af692011-07-15 07:29:55 +00002152 if (eicr & IXGBE_EICR_MAILBOX)
2153 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002154
Alexander Duyck2c4af692011-07-15 07:29:55 +00002155 switch (hw->mac.type) {
2156 case ixgbe_mac_82599EB:
2157 case ixgbe_mac_X540:
2158 if (eicr & IXGBE_EICR_ECC)
2159 e_info(link, "Received unrecoverable ECC Err, please "
2160 "reboot\n");
2161 /* Handle Flow Director Full threshold interrupt */
2162 if (eicr & IXGBE_EICR_FLOW_DIR) {
2163 int reinit_count = 0;
2164 int i;
2165 for (i = 0; i < adapter->num_tx_queues; i++) {
2166 struct ixgbe_ring *ring = adapter->tx_ring[i];
2167 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2168 &ring->state))
2169 reinit_count++;
2170 }
2171 if (reinit_count) {
2172 /* no more flow director interrupts until after init */
2173 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2174 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2175 ixgbe_service_event_schedule(adapter);
2176 }
2177 }
2178 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002179 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002180 break;
2181 default:
2182 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002183 }
2184
Alexander Duyck2c4af692011-07-15 07:29:55 +00002185 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002186
Alexander Duyck2c4af692011-07-15 07:29:55 +00002187 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002188 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002189 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002190
Alexander Duyck2c4af692011-07-15 07:29:55 +00002191 return IRQ_HANDLED;
2192}
2193
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002194static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002195{
2196 struct ixgbe_q_vector *q_vector = data;
2197
Auke Kok9a799d72007-09-15 14:07:45 -07002198 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002199
2200 if (q_vector->rx.ring || q_vector->tx.ring)
2201 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002202
2203 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002204}
2205
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002206static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002207 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002208{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002209 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002210 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002211
Alexander Duyck22745432010-11-16 19:27:10 -08002212 rx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002213 rx_ring->next = q_vector->rx.ring;
2214 q_vector->rx.ring = rx_ring;
2215 q_vector->rx.count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002216}
Auke Kok9a799d72007-09-15 14:07:45 -07002217
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002218static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002219 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002220{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002221 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002222 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002223
Alexander Duyck22745432010-11-16 19:27:10 -08002224 tx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002225 tx_ring->next = q_vector->tx.ring;
2226 q_vector->tx.ring = tx_ring;
2227 q_vector->tx.count++;
Alexander Duyckbd198052011-06-11 01:45:08 +00002228 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002229}
Auke Kok9a799d72007-09-15 14:07:45 -07002230
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002231/**
2232 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2233 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002234 *
2235 * This function maps descriptor rings to the queue-specific vectors
2236 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2237 * one vector per ring/queue, but on a constrained vector budget, we
2238 * group the rings as "efficiently" as possible. You would add new
2239 * mapping configurations in here.
2240 **/
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002241static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002242{
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002243 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2244 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2245 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 int v_start = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002247
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002248 /* only one q_vector if MSI-X is disabled. */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002249 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002250 q_vectors = 1;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002251
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002252 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002253 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2254 * group them so there are multiple queues per vector.
2255 *
2256 * Re-adjusting *qpv takes care of the remainder.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002258 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2259 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2260 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261 map_vector_to_rxq(adapter, v_start, rxr_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002262 }
2263
2264 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002265 * If there are not enough q_vectors for each ring to have it's own
2266 * vector then we must pair up Rx/Tx on a each vector
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002268 if ((v_start + txr_remaining) > q_vectors)
2269 v_start = 0;
2270
2271 for (; v_start < q_vectors && txr_remaining; v_start++) {
2272 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2273 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2274 map_vector_to_txq(adapter, v_start, txr_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07002275 }
Auke Kok9a799d72007-09-15 14:07:45 -07002276}
2277
2278/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002279 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2280 * @adapter: board private structure
2281 *
2282 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2283 * interrupts from the kernel.
2284 **/
2285static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2286{
2287 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002288 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2289 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002290 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002293 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002294 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002295
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002296 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002297 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002298 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002299 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002300 } else if (q_vector->rx.ring) {
2301 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2302 "%s-%s-%d", netdev->name, "rx", ri++);
2303 } else if (q_vector->tx.ring) {
2304 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2305 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002306 } else {
2307 /* skip this unused q_vector */
2308 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002309 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002310 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2311 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002313 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002314 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315 goto free_queue_irqs;
2316 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002317 /* If Flow Director is enabled, set interrupt affinity */
2318 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2319 /* assign the mask for this irq */
2320 irq_set_affinity_hint(entry->vector,
2321 q_vector->affinity_mask);
2322 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323 }
2324
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002326 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002328 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329 goto free_queue_irqs;
2330 }
2331
2332 return 0;
2333
2334free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002335 while (vector) {
2336 vector--;
2337 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2338 NULL);
2339 free_irq(adapter->msix_entries[vector].vector,
2340 adapter->q_vector[vector]);
2341 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2343 pci_disable_msix(adapter->pdev);
2344 kfree(adapter->msix_entries);
2345 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 return err;
2347}
2348
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002349/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002350 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002351 * @irq: interrupt number
2352 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002353 **/
2354static irqreturn_t ixgbe_intr(int irq, void *data)
2355{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002356 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002357 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002358 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002359 u32 eicr;
2360
Don Skidmore54037502009-02-21 15:42:56 -08002361 /*
Alexander Duyck24ddd962012-02-10 02:08:32 +00002362 * Workaround for silicon errata #26 on 82598. Mask the interrupt
Don Skidmore54037502009-02-21 15:42:56 -08002363 * before the read of EICR.
2364 */
2365 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2366
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002368 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002370 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002371 /*
2372 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002373 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002374 * have disabled interrupts due to EIAM
2375 * finish the workaround of silicon errata on 82598. Unmask
2376 * the interrupt that we masked before the EICR read.
2377 */
2378 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2379 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002380 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002381 }
Auke Kok9a799d72007-09-15 14:07:45 -07002382
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002383 if (eicr & IXGBE_EICR_LSC)
2384 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002385
Alexander Duyckbd508172010-11-16 19:27:03 -08002386 switch (hw->mac.type) {
2387 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002388 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002389 /* Fall through */
2390 case ixgbe_mac_X540:
2391 if (eicr & IXGBE_EICR_ECC)
2392 e_info(link, "Received unrecoverable ECC err, please "
2393 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002394 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002395 break;
2396 default:
2397 break;
2398 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002399
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002400 ixgbe_check_fan_failure(adapter, eicr);
2401
Alexander Duyck7a921c92009-05-06 10:43:28 +00002402 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002403 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002404 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002405 }
2406
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002407 /*
2408 * re-enable link(maybe) and non-queue interrupts, no flush.
2409 * ixgbe_poll will re-enable the queue interrupts
2410 */
2411
2412 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2413 ixgbe_irq_enable(adapter, false, false);
2414
Auke Kok9a799d72007-09-15 14:07:45 -07002415 return IRQ_HANDLED;
2416}
2417
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002418static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2419{
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002420 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2421 int i;
2422
2423 /* legacy and MSI only use one vector */
2424 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2425 q_vectors = 1;
2426
2427 for (i = 0; i < adapter->num_rx_queues; i++) {
2428 adapter->rx_ring[i]->q_vector = NULL;
2429 adapter->rx_ring[i]->next = NULL;
2430 }
2431 for (i = 0; i < adapter->num_tx_queues; i++) {
2432 adapter->tx_ring[i]->q_vector = NULL;
2433 adapter->tx_ring[i]->next = NULL;
2434 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435
2436 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002437 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002438 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2439 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002440 }
2441}
2442
Auke Kok9a799d72007-09-15 14:07:45 -07002443/**
2444 * ixgbe_request_irq - initialize interrupts
2445 * @adapter: board private structure
2446 *
2447 * Attempts to configure interrupts using the best available
2448 * capabilities of the hardware and kernel.
2449 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002451{
2452 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002453 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002454
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002455 /* map all of the rings to the q_vectors */
2456 ixgbe_map_rings_to_vectors(adapter);
2457
2458 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002459 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002460 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002461 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002462 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002463 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002464 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002465 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002466
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002467 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002468 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002469
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002470 /* place q_vectors and rings back into a known good state */
2471 ixgbe_reset_q_vectors(adapter);
2472 }
2473
Auke Kok9a799d72007-09-15 14:07:45 -07002474 return err;
2475}
2476
2477static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2478{
Auke Kok9a799d72007-09-15 14:07:45 -07002479 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002480 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002481
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002482 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002483 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002484 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002486
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002487 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002488 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002489 if (!adapter->q_vector[i]->rx.ring &&
2490 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002491 continue;
2492
Alexander Duyck207867f2011-07-15 03:05:37 +00002493 /* clear the affinity_mask in the IRQ descriptor */
2494 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2495 NULL);
2496
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002497 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002498 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002499 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002500 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002501 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002502 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002503
2504 /* clear q_vector state information */
2505 ixgbe_reset_q_vectors(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002506}
2507
2508/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002509 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2510 * @adapter: board private structure
2511 **/
2512static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2513{
Alexander Duyckbd508172010-11-16 19:27:03 -08002514 switch (adapter->hw.mac.type) {
2515 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002516 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002517 break;
2518 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002519 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002520 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2521 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002522 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002523 break;
2524 default:
2525 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002526 }
2527 IXGBE_WRITE_FLUSH(&adapter->hw);
2528 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2529 int i;
2530 for (i = 0; i < adapter->num_msix_vectors; i++)
2531 synchronize_irq(adapter->msix_entries[i].vector);
2532 } else {
2533 synchronize_irq(adapter->pdev->irq);
2534 }
2535}
2536
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002537/**
Auke Kok9a799d72007-09-15 14:07:45 -07002538 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2539 *
2540 **/
2541static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2542{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002543 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002544
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002545 /* rx/tx vector */
2546 if (adapter->rx_itr_setting == 1)
2547 q_vector->itr = IXGBE_20K_ITR;
2548 else
2549 q_vector->itr = adapter->rx_itr_setting;
2550
2551 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002552
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002553 ixgbe_set_ivar(adapter, 0, 0, 0);
2554 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002555
Emil Tantilov396e7992010-07-01 20:05:12 +00002556 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002557}
2558
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002559/**
2560 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2561 * @adapter: board private structure
2562 * @ring: structure containing ring specific data
2563 *
2564 * Configure the Tx descriptor ring after a reset.
2565 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002566void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2567 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002568{
2569 struct ixgbe_hw *hw = &adapter->hw;
2570 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002571 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002572 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002573 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002574
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002575 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002576 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002577 IXGBE_WRITE_FLUSH(hw);
2578
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002579 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002580 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002581 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2582 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2583 ring->count * sizeof(union ixgbe_adv_tx_desc));
2584 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2585 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002586 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002587
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002588 /*
2589 * set WTHRESH to encourage burst writeback, it should not be set
2590 * higher than 1 when ITR is 0 as it could cause false TX hangs
2591 *
2592 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2593 * to or less than the number of on chip descriptors, which is
2594 * currently 40.
2595 */
2596 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2597 txdctl |= (1 << 16); /* WTHRESH = 1 */
2598 else
2599 txdctl |= (8 << 16); /* WTHRESH = 8 */
2600
2601 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2602 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2603 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002604
2605 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002606 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2607 adapter->atr_sample_rate) {
2608 ring->atr_sample_rate = adapter->atr_sample_rate;
2609 ring->atr_count = 0;
2610 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2611 } else {
2612 ring->atr_sample_rate = 0;
2613 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002614
John Fastabendc84d3242010-11-16 19:27:12 -08002615 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2616
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002617 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002618 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2619
2620 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2621 if (hw->mac.type == ixgbe_mac_82598EB &&
2622 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2623 return;
2624
2625 /* poll to verify queue is enabled */
2626 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002627 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002628 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2629 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2630 if (!wait_loop)
2631 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002632}
2633
Alexander Duyck120ff942010-08-19 13:34:50 +00002634static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2635{
2636 struct ixgbe_hw *hw = &adapter->hw;
2637 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002638 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002639 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002640
2641 if (hw->mac.type == ixgbe_mac_82598EB)
2642 return;
2643
2644 /* disable the arbiter while setting MTQC */
2645 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2646 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2647 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2648
2649 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002650 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002651 case (IXGBE_FLAG_SRIOV_ENABLED):
2652 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2653 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2654 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002655 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002656 if (!tcs)
2657 reg = IXGBE_MTQC_64Q_1PB;
2658 else if (tcs <= 4)
2659 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2660 else
2661 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2662
2663 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2664
2665 /* Enable Security TX Buffer IFG for multiple pb */
2666 if (tcs) {
2667 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2668 reg |= IXGBE_SECTX_DCB;
2669 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2670 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002671 break;
2672 }
2673
2674 /* re-enable the arbiter */
2675 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2676 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2677}
2678
Auke Kok9a799d72007-09-15 14:07:45 -07002679/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002680 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002681 * @adapter: board private structure
2682 *
2683 * Configure the Tx unit of the MAC after a reset.
2684 **/
2685static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2686{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002687 struct ixgbe_hw *hw = &adapter->hw;
2688 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002689 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002690
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002691 ixgbe_setup_mtqc(adapter);
2692
2693 if (hw->mac.type != ixgbe_mac_82598EB) {
2694 /* DMATXCTL.EN must be before Tx queues are enabled */
2695 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2696 dmatxctl |= IXGBE_DMATXCTL_TE;
2697 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2698 }
2699
Auke Kok9a799d72007-09-15 14:07:45 -07002700 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002701 for (i = 0; i < adapter->num_tx_queues; i++)
2702 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002703}
2704
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002705#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002706
Yi Zoua6616b42009-08-06 13:05:23 +00002707static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002708 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002709{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002710 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002711 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002712
Alexander Duyckbd508172010-11-16 19:27:03 -08002713 switch (adapter->hw.mac.type) {
2714 case ixgbe_mac_82598EB: {
2715 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2716 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002717 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002718 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002719 break;
2720 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002721 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002722 default:
2723 break;
2724 }
2725
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002726 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002727
2728 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2729 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002730 if (adapter->num_vfs)
2731 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002732
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002733 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2734 IXGBE_SRRCTL_BSIZEHDR_MASK;
2735
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002736 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002737#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2738 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2739#else
2740 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2741#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002742 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002743 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002744 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2745 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002746 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002747 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002748
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002749 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002750}
2751
Alexander Duyck05abb122010-08-19 13:35:41 +00002752static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002753{
Alexander Duyck05abb122010-08-19 13:35:41 +00002754 struct ixgbe_hw *hw = &adapter->hw;
2755 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002756 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2757 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002758 u32 mrqc = 0, reta = 0;
2759 u32 rxcsum;
2760 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002761 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002762 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2763
2764 if (tcs)
2765 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002766
Alexander Duyck05abb122010-08-19 13:35:41 +00002767 /* Fill out hash function seeds */
2768 for (i = 0; i < 10; i++)
2769 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002770
Alexander Duyck05abb122010-08-19 13:35:41 +00002771 /* Fill out redirection table */
2772 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002773 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002774 j = 0;
2775 /* reta = 4-byte sliding window of
2776 * 0x00..(indices-1)(indices-1)00..etc. */
2777 reta = (reta << 8) | (j * 0x11);
2778 if ((i & 3) == 3)
2779 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2780 }
2781
2782 /* Disable indicating checksum in descriptor, enables RSS hash */
2783 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2784 rxcsum |= IXGBE_RXCSUM_PCSD;
2785 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2786
John Fastabend8b1c0b22011-05-03 02:26:48 +00002787 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2788 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002789 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002790 } else {
2791 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2792 | IXGBE_FLAG_SRIOV_ENABLED);
2793
2794 switch (mask) {
2795 case (IXGBE_FLAG_RSS_ENABLED):
2796 if (!tcs)
2797 mrqc = IXGBE_MRQC_RSSEN;
2798 else if (tcs <= 4)
2799 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2800 else
2801 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2802 break;
2803 case (IXGBE_FLAG_SRIOV_ENABLED):
2804 mrqc = IXGBE_MRQC_VMDQEN;
2805 break;
2806 default:
2807 break;
2808 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002809 }
2810
Alexander Duyck05abb122010-08-19 13:35:41 +00002811 /* Perform hash on these packet types */
2812 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2813 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2814 | IXGBE_MRQC_RSS_FIELD_IPV6
2815 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2816
2817 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002818}
2819
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002820/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002821 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2822 * @adapter: address of board private structure
2823 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002824 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002825static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002826 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002827{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002828 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002829 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002830 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002831 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002832
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002833 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002834 return;
2835
2836 rx_buf_len = ring->rx_buf_len;
2837 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002838 rscctrl |= IXGBE_RSCCTL_RSCEN;
2839 /*
2840 * we must limit the number of descriptors so that the
2841 * total size of max desc * buf_len is not greater
Alexander Duyck642c6802011-11-10 09:09:17 +00002842 * than 65536
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002843 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002844 if (ring_is_ps_enabled(ring)) {
Alexander Duyck642c6802011-11-10 09:09:17 +00002845#if (PAGE_SIZE < 8192)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002846 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002847#elif (PAGE_SIZE < 16384)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002848 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
Alexander Duyck642c6802011-11-10 09:09:17 +00002849#elif (PAGE_SIZE < 32768)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002850 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2851#else
2852 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2853#endif
2854 } else {
Alexander Duyck642c6802011-11-10 09:09:17 +00002855 if (rx_buf_len <= IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002856 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck642c6802011-11-10 09:09:17 +00002857 else if (rx_buf_len <= IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002858 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2859 else
2860 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2861 }
Alexander Duyck73670962010-08-19 13:38:34 +00002862 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002863}
2864
Alexander Duyck9e10e042010-08-19 13:40:06 +00002865/**
2866 * ixgbe_set_uta - Set unicast filter table address
2867 * @adapter: board private structure
2868 *
2869 * The unicast table address is a register array of 32-bit registers.
2870 * The table is meant to be used in a way similar to how the MTA is used
2871 * however due to certain limitations in the hardware it is necessary to
2872 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2873 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2874 **/
2875static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2876{
2877 struct ixgbe_hw *hw = &adapter->hw;
2878 int i;
2879
2880 /* The UTA table only exists on 82599 hardware and newer */
2881 if (hw->mac.type < ixgbe_mac_82599EB)
2882 return;
2883
2884 /* we only need to do this if VMDq is enabled */
2885 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2886 return;
2887
2888 for (i = 0; i < 128; i++)
2889 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2890}
2891
2892#define IXGBE_MAX_RX_DESC_POLL 10
2893static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2894 struct ixgbe_ring *ring)
2895{
2896 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002897 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2898 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002899 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002900
2901 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2902 if (hw->mac.type == ixgbe_mac_82598EB &&
2903 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2904 return;
2905
2906 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002907 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002908 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2909 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2910
2911 if (!wait_loop) {
2912 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2913 "the polling period\n", reg_idx);
2914 }
2915}
2916
Yi Zou2d39d572011-01-06 14:29:56 +00002917void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2918 struct ixgbe_ring *ring)
2919{
2920 struct ixgbe_hw *hw = &adapter->hw;
2921 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2922 u32 rxdctl;
2923 u8 reg_idx = ring->reg_idx;
2924
2925 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2926 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2927
2928 /* write value back with RXDCTL.ENABLE bit cleared */
2929 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2930
2931 if (hw->mac.type == ixgbe_mac_82598EB &&
2932 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2933 return;
2934
2935 /* the hardware may take up to 100us to really disable the rx queue */
2936 do {
2937 udelay(10);
2938 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2939 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2940
2941 if (!wait_loop) {
2942 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2943 "the polling period\n", reg_idx);
2944 }
2945}
2946
Alexander Duyck84418e32010-08-19 13:40:54 +00002947void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2948 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002949{
2950 struct ixgbe_hw *hw = &adapter->hw;
2951 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002952 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002953 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002954
Alexander Duyck9e10e042010-08-19 13:40:06 +00002955 /* disable queue to avoid issues while updating state */
2956 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002957 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002958
Alexander Duyckacd37172010-08-19 13:36:05 +00002959 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2960 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2961 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2962 ring->count * sizeof(union ixgbe_adv_rx_desc));
2963 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2964 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002965 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002966
2967 ixgbe_configure_srrctl(adapter, ring);
2968 ixgbe_configure_rscctl(adapter, ring);
2969
Greg Rosee9f98072011-01-26 01:06:07 +00002970 /* If operating in IOV mode set RLPML for X540 */
2971 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2972 hw->mac.type == ixgbe_mac_X540) {
2973 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2974 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2975 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2976 }
2977
Alexander Duyck9e10e042010-08-19 13:40:06 +00002978 if (hw->mac.type == ixgbe_mac_82598EB) {
2979 /*
2980 * enable cache line friendly hardware writes:
2981 * PTHRESH=32 descriptors (half the internal cache),
2982 * this also removes ugly rx_no_buffer_count increment
2983 * HTHRESH=4 descriptors (to minimize latency on fetch)
2984 * WTHRESH=8 burst writeback up to two cache lines
2985 */
2986 rxdctl &= ~0x3FFFFF;
2987 rxdctl |= 0x080420;
2988 }
2989
2990 /* enable receive descriptor ring */
2991 rxdctl |= IXGBE_RXDCTL_ENABLE;
2992 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2993
2994 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002995 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002996}
2997
Alexander Duyck48654522010-08-19 13:36:27 +00002998static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2999{
3000 struct ixgbe_hw *hw = &adapter->hw;
3001 int p;
3002
3003 /* PSRTYPE must be initialized in non 82598 adapters */
3004 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003005 IXGBE_PSRTYPE_UDPHDR |
3006 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003007 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003008 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003009
3010 if (hw->mac.type == ixgbe_mac_82598EB)
3011 return;
3012
3013 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3014 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3015
3016 for (p = 0; p < adapter->num_rx_pools; p++)
3017 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3018 psrtype);
3019}
3020
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003021static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3022{
3023 struct ixgbe_hw *hw = &adapter->hw;
3024 u32 gcr_ext;
3025 u32 vt_reg_bits;
3026 u32 reg_offset, vf_shift;
3027 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003028 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003029
3030 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3031 return;
3032
3033 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3034 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3035 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3036 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3037
3038 vf_shift = adapter->num_vfs % 32;
Greg Rose4cd69232012-01-25 07:59:37 +00003039 reg_offset = (adapter->num_vfs >= 32) ? 1 : 0;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003040
3041 /* Enable only the PF's pool for Tx/Rx */
3042 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3043 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3044 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3045 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3046 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3047
3048 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3049 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3050
3051 /*
3052 * Set up VF register offsets for selected VT Mode,
3053 * i.e. 32 or 64 VFs for SR-IOV
3054 */
3055 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3056 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3057 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3058 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3059
3060 /* enable Tx loopback for VF/PF communication */
3061 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003062 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003063 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003064 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003065 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003066 /* For VFs that have spoof checking turned off */
3067 for (i = 0; i < adapter->num_vfs; i++) {
3068 if (!adapter->vfinfo[i].spoofchk_enabled)
3069 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3070 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003071}
3072
Alexander Duyck477de6e2010-08-19 13:38:11 +00003073static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003074{
Auke Kok9a799d72007-09-15 14:07:45 -07003075 struct ixgbe_hw *hw = &adapter->hw;
3076 struct net_device *netdev = adapter->netdev;
3077 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003078 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003079 struct ixgbe_ring *rx_ring;
3080 int i;
3081 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003082
Auke Kok9a799d72007-09-15 14:07:45 -07003083 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003084 /* On by default */
3085 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3086
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003087 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003088 if (adapter->num_vfs)
3089 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3090
3091 /* Disable packet split due to 82599 erratum #45 */
3092 if (hw->mac.type == ixgbe_mac_82599EB)
3093 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003094
Alexander Duyck477de6e2010-08-19 13:38:11 +00003095#ifdef IXGBE_FCOE
3096 /* adjust max frame to be able to do baby jumbo for FCoE */
3097 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3098 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3099 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3100
3101#endif /* IXGBE_FCOE */
3102 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3103 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3104 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3105 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3106
3107 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003108 }
3109
Alexander Duyck919e78a2011-08-26 09:52:38 +00003110 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3111 max_frame += VLAN_HLEN;
3112
3113 /* Set the RX buffer length according to the mode */
3114 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3115 rx_buf_len = IXGBE_RX_HDR_SIZE;
3116 } else {
3117 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3118 (netdev->mtu <= ETH_DATA_LEN))
3119 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3120 /*
3121 * Make best use of allocation by using all but 1K of a
3122 * power of 2 allocation that will be used for skb->head.
3123 */
3124 else if (max_frame <= IXGBE_RXBUFFER_3K)
3125 rx_buf_len = IXGBE_RXBUFFER_3K;
3126 else if (max_frame <= IXGBE_RXBUFFER_7K)
3127 rx_buf_len = IXGBE_RXBUFFER_7K;
3128 else if (max_frame <= IXGBE_RXBUFFER_15K)
3129 rx_buf_len = IXGBE_RXBUFFER_15K;
3130 else
3131 rx_buf_len = IXGBE_MAX_RXBUFFER;
3132 }
3133
Auke Kok9a799d72007-09-15 14:07:45 -07003134 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003135 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3136 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003137 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3138
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003139 /*
3140 * Setup the HW Rx Head and Tail Descriptor Pointers and
3141 * the Base and Length of the Rx Descriptor Ring
3142 */
Auke Kok9a799d72007-09-15 14:07:45 -07003143 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003144 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003145 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003146
Yi Zou6e455b892009-08-06 13:05:44 +00003147 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003148 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003149 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003150 clear_ring_ps_enabled(rx_ring);
3151
3152 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3153 set_ring_rsc_enabled(rx_ring);
3154 else
3155 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003156
Yi Zou63f39bd2009-05-17 12:34:35 +00003157#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003158 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003159 struct ixgbe_ring_feature *f;
3160 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003161 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003162 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003163 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3164 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003165 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003166 } else if (!ring_is_rsc_enabled(rx_ring) &&
3167 !ring_is_ps_enabled(rx_ring)) {
3168 rx_ring->rx_buf_len =
3169 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003170 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003171 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003172#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003173 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003174}
3175
Alexander Duyck73670962010-08-19 13:38:34 +00003176static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3177{
3178 struct ixgbe_hw *hw = &adapter->hw;
3179 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3180
3181 switch (hw->mac.type) {
3182 case ixgbe_mac_82598EB:
3183 /*
3184 * For VMDq support of different descriptor types or
3185 * buffer sizes through the use of multiple SRRCTL
3186 * registers, RDRXCTL.MVMEN must be set to 1
3187 *
3188 * also, the manual doesn't mention it clearly but DCA hints
3189 * will only use queue 0's tags unless this bit is set. Side
3190 * effects of setting this bit are only that SRRCTL must be
3191 * fully programmed [0..15]
3192 */
3193 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3194 break;
3195 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003196 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003197 /* Disable RSC for ACK packets */
3198 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3199 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3200 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3201 /* hardware requires some bits to be set by default */
3202 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3203 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3204 break;
3205 default:
3206 /* We should do nothing since we don't know this hardware */
3207 return;
3208 }
3209
3210 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3211}
3212
Alexander Duyck477de6e2010-08-19 13:38:11 +00003213/**
3214 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3215 * @adapter: board private structure
3216 *
3217 * Configure the Rx unit of the MAC after a reset.
3218 **/
3219static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3220{
3221 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003222 int i;
3223 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003224
3225 /* disable receives while setting up the descriptors */
3226 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3227 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3228
3229 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003230 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003231
Alexander Duyck9e10e042010-08-19 13:40:06 +00003232 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003233 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003234
Alexander Duyck9e10e042010-08-19 13:40:06 +00003235 ixgbe_set_uta(adapter);
3236
Alexander Duyck477de6e2010-08-19 13:38:11 +00003237 /* set_rx_buffer_len must be called before ring initialization */
3238 ixgbe_set_rx_buffer_len(adapter);
3239
3240 /*
3241 * Setup the HW Rx Head and Tail Descriptor Pointers and
3242 * the Base and Length of the Rx Descriptor Ring
3243 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003244 for (i = 0; i < adapter->num_rx_queues; i++)
3245 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003246
Alexander Duyck9e10e042010-08-19 13:40:06 +00003247 /* disable drop enable for 82598 parts */
3248 if (hw->mac.type == ixgbe_mac_82598EB)
3249 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3250
3251 /* enable all receives */
3252 rxctrl |= IXGBE_RXCTRL_RXEN;
3253 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003254}
3255
Jiri Pirko8e586132011-12-08 19:52:37 -05003256static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003257{
3258 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003259 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003260 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003261
3262 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003263 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003264 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003265
3266 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003267}
3268
Jiri Pirko8e586132011-12-08 19:52:37 -05003269static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003270{
3271 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003272 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003273 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003274
Auke Kok9a799d72007-09-15 14:07:45 -07003275 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003276 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003277 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003278
3279 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003280}
3281
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003282/**
3283 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3284 * @adapter: driver data
3285 */
3286static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3287{
3288 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003289 u32 vlnctrl;
3290
3291 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3292 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3293 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3294}
3295
3296/**
3297 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3298 * @adapter: driver data
3299 */
3300static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3301{
3302 struct ixgbe_hw *hw = &adapter->hw;
3303 u32 vlnctrl;
3304
3305 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3306 vlnctrl |= IXGBE_VLNCTRL_VFE;
3307 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3308 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3309}
3310
3311/**
3312 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3313 * @adapter: driver data
3314 */
3315static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3316{
3317 struct ixgbe_hw *hw = &adapter->hw;
3318 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003319 int i, j;
3320
3321 switch (hw->mac.type) {
3322 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003323 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3324 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003325 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3326 break;
3327 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003328 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003329 for (i = 0; i < adapter->num_rx_queues; i++) {
3330 j = adapter->rx_ring[i]->reg_idx;
3331 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3332 vlnctrl &= ~IXGBE_RXDCTL_VME;
3333 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3334 }
3335 break;
3336 default:
3337 break;
3338 }
3339}
3340
3341/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003342 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003343 * @adapter: driver data
3344 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003345static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003346{
3347 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003348 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003349 int i, j;
3350
3351 switch (hw->mac.type) {
3352 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003353 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3354 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003355 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3356 break;
3357 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003358 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003359 for (i = 0; i < adapter->num_rx_queues; i++) {
3360 j = adapter->rx_ring[i]->reg_idx;
3361 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3362 vlnctrl |= IXGBE_RXDCTL_VME;
3363 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3364 }
3365 break;
3366 default:
3367 break;
3368 }
3369}
3370
Auke Kok9a799d72007-09-15 14:07:45 -07003371static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3372{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003373 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003374
Jesse Grossf62bbb52010-10-20 13:56:10 +00003375 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3376
3377 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3378 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003379}
3380
3381/**
Alexander Duyck28500622010-06-15 09:25:48 +00003382 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3383 * @netdev: network interface device structure
3384 *
3385 * Writes unicast address list to the RAR table.
3386 * Returns: -ENOMEM on failure/insufficient address space
3387 * 0 on no addresses written
3388 * X on writing X addresses to the RAR table
3389 **/
3390static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3391{
3392 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3393 struct ixgbe_hw *hw = &adapter->hw;
3394 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003395 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003396 int count = 0;
3397
3398 /* return ENOMEM indicating insufficient memory for addresses */
3399 if (netdev_uc_count(netdev) > rar_entries)
3400 return -ENOMEM;
3401
3402 if (!netdev_uc_empty(netdev) && rar_entries) {
3403 struct netdev_hw_addr *ha;
3404 /* return error if we do not support writing to RAR table */
3405 if (!hw->mac.ops.set_rar)
3406 return -ENOMEM;
3407
3408 netdev_for_each_uc_addr(ha, netdev) {
3409 if (!rar_entries)
3410 break;
3411 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3412 vfn, IXGBE_RAH_AV);
3413 count++;
3414 }
3415 }
3416 /* write the addresses in reverse order to avoid write combining */
3417 for (; rar_entries > 0 ; rar_entries--)
3418 hw->mac.ops.clear_rar(hw, rar_entries);
3419
3420 return count;
3421}
3422
3423/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003424 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003425 * @netdev: network interface device structure
3426 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003427 * The set_rx_method entry point is called whenever the unicast/multicast
3428 * address list or the network interface flags are updated. This routine is
3429 * responsible for configuring the hardware for proper unicast, multicast and
3430 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003431 **/
Greg Rose7f870472010-01-09 02:25:29 +00003432void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003433{
3434 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3435 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003436 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3437 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003438
3439 /* Check for Promiscuous and All Multicast modes */
3440
3441 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3442
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003443 /* set all bits that we expect to always be set */
3444 fctrl |= IXGBE_FCTRL_BAM;
3445 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3446 fctrl |= IXGBE_FCTRL_PMCF;
3447
Alexander Duyck28500622010-06-15 09:25:48 +00003448 /* clear the bits we are changing the status of */
3449 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3450
Auke Kok9a799d72007-09-15 14:07:45 -07003451 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003452 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003453 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003454 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003455 /* don't hardware filter vlans in promisc mode */
3456 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003457 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003458 if (netdev->flags & IFF_ALLMULTI) {
3459 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003460 vmolr |= IXGBE_VMOLR_MPE;
3461 } else {
3462 /*
3463 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003464 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003465 * that we can at least receive multicast traffic
3466 */
3467 hw->mac.ops.update_mc_addr_list(hw, netdev);
3468 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003469 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003470 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003471 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003472 /*
3473 * Write addresses to available RAR registers, if there is not
3474 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003475 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003476 */
3477 count = ixgbe_write_uc_addr_list(netdev);
3478 if (count < 0) {
3479 fctrl |= IXGBE_FCTRL_UPE;
3480 vmolr |= IXGBE_VMOLR_ROPE;
3481 }
3482 }
3483
3484 if (adapter->num_vfs) {
3485 ixgbe_restore_vf_multicasts(adapter);
3486 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3487 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3488 IXGBE_VMOLR_ROPE);
3489 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003490 }
3491
3492 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003493
3494 if (netdev->features & NETIF_F_HW_VLAN_RX)
3495 ixgbe_vlan_strip_enable(adapter);
3496 else
3497 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003498}
3499
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003500static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3501{
3502 int q_idx;
3503 struct ixgbe_q_vector *q_vector;
3504 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3505
3506 /* legacy and MSI only use one vector */
3507 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3508 q_vectors = 1;
3509
3510 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003511 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003512 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003513 }
3514}
3515
3516static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3517{
3518 int q_idx;
3519 struct ixgbe_q_vector *q_vector;
3520 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3521
3522 /* legacy and MSI only use one vector */
3523 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3524 q_vectors = 1;
3525
3526 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003527 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003528 napi_disable(&q_vector->napi);
3529 }
3530}
3531
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003532#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003533/*
3534 * ixgbe_configure_dcb - Configure DCB hardware
3535 * @adapter: ixgbe adapter struct
3536 *
3537 * This is called by the driver on open to configure the DCB hardware.
3538 * This is also called by the gennetlink interface when reconfiguring
3539 * the DCB state.
3540 */
3541static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3542{
3543 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003544 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003545
Alexander Duyck67ebd792010-08-19 13:34:04 +00003546 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3547 if (hw->mac.type == ixgbe_mac_82598EB)
3548 netif_set_gso_max_size(adapter->netdev, 65536);
3549 return;
3550 }
3551
3552 if (hw->mac.type == ixgbe_mac_82598EB)
3553 netif_set_gso_max_size(adapter->netdev, 32768);
3554
Alexander Duyck2f90b862008-11-20 20:52:10 -08003555
Alexander Duyck2f90b862008-11-20 20:52:10 -08003556 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003557 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003558
Alexander Duyck2f90b862008-11-20 20:52:10 -08003559 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003560
John Fastabendb1208182011-10-15 05:00:10 +00003561#ifdef IXGBE_FCOE
3562 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3563 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3564#endif
3565
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003566 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003567 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003568 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3569 DCB_TX_CONFIG);
3570 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3571 DCB_RX_CONFIG);
3572 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003573 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3574 ixgbe_dcb_hw_ets(&adapter->hw,
3575 adapter->ixgbe_ieee_ets,
3576 max_frame);
3577 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3578 adapter->ixgbe_ieee_pfc->pfc_en,
3579 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003580 }
John Fastabend8187cd42011-02-23 05:58:08 +00003581
3582 /* Enable RSS Hash per TC */
3583 if (hw->mac.type != ixgbe_mac_82598EB) {
3584 int i;
3585 u32 reg = 0;
3586
3587 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3588 u8 msb = 0;
3589 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3590
3591 while (cnt >>= 1)
3592 msb++;
3593
3594 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3595 }
3596 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3597 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003598}
John Fastabend9da712d2011-08-23 03:14:22 +00003599#endif
3600
3601/* Additional bittime to account for IXGBE framing */
3602#define IXGBE_ETH_FRAMING 20
3603
3604/*
3605 * ixgbe_hpbthresh - calculate high water mark for flow control
3606 *
3607 * @adapter: board private structure to calculate for
3608 * @pb - packet buffer to calculate
3609 */
3610static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3611{
3612 struct ixgbe_hw *hw = &adapter->hw;
3613 struct net_device *dev = adapter->netdev;
3614 int link, tc, kb, marker;
3615 u32 dv_id, rx_pba;
3616
3617 /* Calculate max LAN frame size */
3618 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3619
3620#ifdef IXGBE_FCOE
3621 /* FCoE traffic class uses FCOE jumbo frames */
3622 if (dev->features & NETIF_F_FCOE_MTU) {
3623 int fcoe_pb = 0;
3624
3625#ifdef CONFIG_IXGBE_DCB
3626 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003627
3628#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003629 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3630 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3631 }
3632#endif
3633
3634 /* Calculate delay value for device */
3635 switch (hw->mac.type) {
3636 case ixgbe_mac_X540:
3637 dv_id = IXGBE_DV_X540(link, tc);
3638 break;
3639 default:
3640 dv_id = IXGBE_DV(link, tc);
3641 break;
3642 }
3643
3644 /* Loopback switch introduces additional latency */
3645 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3646 dv_id += IXGBE_B2BT(tc);
3647
3648 /* Delay value is calculated in bit times convert to KB */
3649 kb = IXGBE_BT2KB(dv_id);
3650 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3651
3652 marker = rx_pba - kb;
3653
3654 /* It is possible that the packet buffer is not large enough
3655 * to provide required headroom. In this case throw an error
3656 * to user and a do the best we can.
3657 */
3658 if (marker < 0) {
3659 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3660 "headroom to support flow control."
3661 "Decrease MTU or number of traffic classes\n", pb);
3662 marker = tc + 1;
3663 }
3664
3665 return marker;
3666}
3667
3668/*
3669 * ixgbe_lpbthresh - calculate low water mark for for flow control
3670 *
3671 * @adapter: board private structure to calculate for
3672 * @pb - packet buffer to calculate
3673 */
3674static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3675{
3676 struct ixgbe_hw *hw = &adapter->hw;
3677 struct net_device *dev = adapter->netdev;
3678 int tc;
3679 u32 dv_id;
3680
3681 /* Calculate max LAN frame size */
3682 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3683
3684 /* Calculate delay value for device */
3685 switch (hw->mac.type) {
3686 case ixgbe_mac_X540:
3687 dv_id = IXGBE_LOW_DV_X540(tc);
3688 break;
3689 default:
3690 dv_id = IXGBE_LOW_DV(tc);
3691 break;
3692 }
3693
3694 /* Delay value is calculated in bit times convert to KB */
3695 return IXGBE_BT2KB(dv_id);
3696}
3697
3698/*
3699 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3700 */
3701static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3702{
3703 struct ixgbe_hw *hw = &adapter->hw;
3704 int num_tc = netdev_get_num_tc(adapter->netdev);
3705 int i;
3706
3707 if (!num_tc)
3708 num_tc = 1;
3709
3710 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3711
3712 for (i = 0; i < num_tc; i++) {
3713 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3714
3715 /* Low water marks must not be larger than high water marks */
3716 if (hw->fc.low_water > hw->fc.high_water[i])
3717 hw->fc.low_water = 0;
3718 }
3719}
John Fastabend80605c652011-05-02 12:34:10 +00003720
3721static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3722{
John Fastabend80605c652011-05-02 12:34:10 +00003723 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003724 int hdrm;
3725 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003726
3727 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3728 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003729 hdrm = 32 << adapter->fdir_pballoc;
3730 else
3731 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003732
Alexander Duyckf7e10272011-07-21 00:40:35 +00003733 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003734 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003735}
3736
Alexander Duycke4911d52011-05-11 07:18:52 +00003737static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3738{
3739 struct ixgbe_hw *hw = &adapter->hw;
3740 struct hlist_node *node, *node2;
3741 struct ixgbe_fdir_filter *filter;
3742
3743 spin_lock(&adapter->fdir_perfect_lock);
3744
3745 if (!hlist_empty(&adapter->fdir_filter_list))
3746 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3747
3748 hlist_for_each_entry_safe(filter, node, node2,
3749 &adapter->fdir_filter_list, fdir_node) {
3750 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003751 &filter->filter,
3752 filter->sw_idx,
3753 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3754 IXGBE_FDIR_DROP_QUEUE :
3755 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003756 }
3757
3758 spin_unlock(&adapter->fdir_perfect_lock);
3759}
3760
Auke Kok9a799d72007-09-15 14:07:45 -07003761static void ixgbe_configure(struct ixgbe_adapter *adapter)
3762{
John Fastabend80605c652011-05-02 12:34:10 +00003763 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003764#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003765 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003766#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003767
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003768 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003769 ixgbe_restore_vlan(adapter);
3770
Yi Zoueacd73f2009-05-13 13:11:06 +00003771#ifdef IXGBE_FCOE
3772 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3773 ixgbe_configure_fcoe(adapter);
3774
3775#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003776 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003777 ixgbe_init_fdir_signature_82599(&adapter->hw,
3778 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003779 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3780 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3781 adapter->fdir_pballoc);
3782 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003783 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003784
Alexander Duyck933d41f2010-09-07 21:34:29 +00003785 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003786
Auke Kok9a799d72007-09-15 14:07:45 -07003787 ixgbe_configure_tx(adapter);
3788 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003789}
3790
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003791static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3792{
3793 switch (hw->phy.type) {
3794 case ixgbe_phy_sfp_avago:
3795 case ixgbe_phy_sfp_ftl:
3796 case ixgbe_phy_sfp_intel:
3797 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003798 case ixgbe_phy_sfp_passive_tyco:
3799 case ixgbe_phy_sfp_passive_unknown:
3800 case ixgbe_phy_sfp_active_unknown:
3801 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003802 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003803 case ixgbe_phy_nl:
3804 if (hw->mac.type == ixgbe_mac_82598EB)
3805 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003806 default:
3807 return false;
3808 }
3809}
3810
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003811/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003812 * ixgbe_sfp_link_config - set up SFP+ link
3813 * @adapter: pointer to private adapter struct
3814 **/
3815static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3816{
Alexander Duyck70864002011-04-27 09:13:56 +00003817 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003818 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003819 * is that an SFP was inserted/removed after the reset
3820 * but before SFP detection was enabled. As such the best
3821 * solution is to just start searching as soon as we start
3822 */
3823 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3824 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003825
Alexander Duyck70864002011-04-27 09:13:56 +00003826 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003827}
3828
3829/**
3830 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003831 * @hw: pointer to private hardware struct
3832 *
3833 * Returns 0 on success, negative on failure
3834 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003835static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003836{
3837 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003838 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003839 u32 ret = IXGBE_ERR_LINK_SETUP;
3840
3841 if (hw->mac.ops.check_link)
3842 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3843
3844 if (ret)
3845 goto link_cfg_out;
3846
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003847 autoneg = hw->phy.autoneg_advertised;
3848 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003849 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3850 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003851 if (ret)
3852 goto link_cfg_out;
3853
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003854 if (hw->mac.ops.setup_link)
3855 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003856link_cfg_out:
3857 return ret;
3858}
3859
Alexander Duycka34bcff2010-08-19 13:39:20 +00003860static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003861{
Auke Kok9a799d72007-09-15 14:07:45 -07003862 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003863 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003864
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003865 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003866 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3867 IXGBE_GPIE_OCD;
3868 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003869 /*
3870 * use EIAM to auto-mask when MSI-X interrupt is asserted
3871 * this saves a register write for every interrupt
3872 */
3873 switch (hw->mac.type) {
3874 case ixgbe_mac_82598EB:
3875 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3876 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003877 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003878 case ixgbe_mac_X540:
3879 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003880 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3881 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3882 break;
3883 }
3884 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003885 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3886 * specifically only auto mask tx and rx interrupts */
3887 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003888 }
3889
Alexander Duycka34bcff2010-08-19 13:39:20 +00003890 /* XXX: to interrupt immediately for EICS writes, enable this */
3891 /* gpie |= IXGBE_GPIE_EIMEN; */
3892
3893 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3894 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3895 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003896 }
3897
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003898 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003899 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3900 switch (adapter->hw.mac.type) {
3901 case ixgbe_mac_82599EB:
3902 gpie |= IXGBE_SDP0_GPIEN;
3903 break;
3904 case ixgbe_mac_X540:
3905 gpie |= IXGBE_EIMS_TS;
3906 break;
3907 default:
3908 break;
3909 }
3910 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003911
Alexander Duycka34bcff2010-08-19 13:39:20 +00003912 /* Enable fan failure interrupt */
3913 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003914 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003915
Don Skidmore2698b202011-04-13 07:01:52 +00003916 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003917 gpie |= IXGBE_SDP1_GPIEN;
3918 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003919 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003920
3921 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3922}
3923
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003924static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003925{
3926 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003927 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003928 u32 ctrl_ext;
3929
3930 ixgbe_get_hw_control(adapter);
3931 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003932
Auke Kok9a799d72007-09-15 14:07:45 -07003933 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3934 ixgbe_configure_msix(adapter);
3935 else
3936 ixgbe_configure_msi_and_legacy(adapter);
3937
Don Skidmorec6ecf392010-12-03 03:31:51 +00003938 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3939 if (hw->mac.ops.enable_tx_laser &&
3940 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003941 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003942 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003943 hw->mac.ops.enable_tx_laser(hw);
3944
Auke Kok9a799d72007-09-15 14:07:45 -07003945 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003946 ixgbe_napi_enable_all(adapter);
3947
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003948 if (ixgbe_is_sfp(hw)) {
3949 ixgbe_sfp_link_config(adapter);
3950 } else {
3951 err = ixgbe_non_sfp_link_config(hw);
3952 if (err)
3953 e_err(probe, "link_config FAILED %d\n", err);
3954 }
3955
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003956 /* clear any pending interrupts, may auto mask */
3957 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003958 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003959
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003960 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003961 * If this adapter has a fan, check to see if we had a failure
3962 * before we enabled the interrupt.
3963 */
3964 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3965 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3966 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003967 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003968 }
3969
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003970 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003971 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003972
Auke Kok9a799d72007-09-15 14:07:45 -07003973 /* bring the link up in the watchdog, this could race with our first
3974 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003975 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3976 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003977 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003978
3979 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3980 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3981 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3982 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003983}
3984
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003985void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3986{
3987 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003988 /* put off any impending NetWatchDogTimeout */
3989 adapter->netdev->trans_start = jiffies;
3990
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003991 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003992 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003993 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003994 /*
3995 * If SR-IOV enabled then wait a bit before bringing the adapter
3996 * back up to give the VFs time to respond to the reset. The
3997 * two second wait is based upon the watchdog timer cycle in
3998 * the VF driver.
3999 */
4000 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4001 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004002 ixgbe_up(adapter);
4003 clear_bit(__IXGBE_RESETTING, &adapter->state);
4004}
4005
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004006void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004007{
4008 /* hardware has been reset, we need to reload some things */
4009 ixgbe_configure(adapter);
4010
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004011 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004012}
4013
4014void ixgbe_reset(struct ixgbe_adapter *adapter)
4015{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004016 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004017 int err;
4018
Alexander Duyck70864002011-04-27 09:13:56 +00004019 /* lock SFP init bit to prevent race conditions with the watchdog */
4020 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4021 usleep_range(1000, 2000);
4022
4023 /* clear all SFP and link config related flags while holding SFP_INIT */
4024 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4025 IXGBE_FLAG2_SFP_NEEDS_RESET);
4026 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4027
Don Skidmore8ca783a2009-05-26 20:40:47 -07004028 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004029 switch (err) {
4030 case 0:
4031 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004032 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004033 break;
4034 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004035 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004036 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004037 case IXGBE_ERR_EEPROM_VERSION:
4038 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004039 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004040 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004041 "your hardware. If you are experiencing problems "
4042 "please contact your Intel or hardware "
4043 "representative who provided you with this "
4044 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004045 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004046 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004047 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004048 }
Auke Kok9a799d72007-09-15 14:07:45 -07004049
Alexander Duyck70864002011-04-27 09:13:56 +00004050 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4051
Auke Kok9a799d72007-09-15 14:07:45 -07004052 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004053 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4054 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004055}
4056
Auke Kok9a799d72007-09-15 14:07:45 -07004057/**
4058 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004059 * @rx_ring: ring to free buffers from
4060 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004061static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004062{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004063 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004064 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004065 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004066
Alexander Duyck84418e32010-08-19 13:40:54 +00004067 /* ring already cleared, nothing to do */
4068 if (!rx_ring->rx_buffer_info)
4069 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004070
Alexander Duyck84418e32010-08-19 13:40:54 +00004071 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004072 for (i = 0; i < rx_ring->count; i++) {
4073 struct ixgbe_rx_buffer *rx_buffer_info;
4074
4075 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4076 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004077 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004078 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004079 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004080 rx_buffer_info->dma = 0;
4081 }
4082 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004083 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004084 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004085 /* We need to clean up RSC frag lists */
4086 skb = ixgbe_merge_active_tail(skb);
4087 ixgbe_close_active_frag_list(skb);
4088 if (IXGBE_CB(skb)->delay_unmap) {
4089 dma_unmap_single(dev,
4090 IXGBE_CB(skb)->dma,
4091 rx_ring->rx_buf_len,
4092 DMA_FROM_DEVICE);
4093 IXGBE_CB(skb)->dma = 0;
4094 IXGBE_CB(skb)->delay_unmap = false;
4095 }
4096 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004097 }
4098 if (!rx_buffer_info->page)
4099 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004100 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004101 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004102 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004103 rx_buffer_info->page_dma = 0;
4104 }
Auke Kok9a799d72007-09-15 14:07:45 -07004105 put_page(rx_buffer_info->page);
4106 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004107 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004108 }
4109
4110 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4111 memset(rx_ring->rx_buffer_info, 0, size);
4112
4113 /* Zero out the descriptor ring */
4114 memset(rx_ring->desc, 0, rx_ring->size);
4115
4116 rx_ring->next_to_clean = 0;
4117 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004118}
4119
4120/**
4121 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004122 * @tx_ring: ring to be cleaned
4123 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004124static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004125{
4126 struct ixgbe_tx_buffer *tx_buffer_info;
4127 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004128 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004129
Alexander Duyck84418e32010-08-19 13:40:54 +00004130 /* ring already cleared, nothing to do */
4131 if (!tx_ring->tx_buffer_info)
4132 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004133
Alexander Duyck84418e32010-08-19 13:40:54 +00004134 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004135 for (i = 0; i < tx_ring->count; i++) {
4136 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004137 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004138 }
4139
4140 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4141 memset(tx_ring->tx_buffer_info, 0, size);
4142
4143 /* Zero out the descriptor ring */
4144 memset(tx_ring->desc, 0, tx_ring->size);
4145
4146 tx_ring->next_to_use = 0;
4147 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004148}
4149
4150/**
Auke Kok9a799d72007-09-15 14:07:45 -07004151 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4152 * @adapter: board private structure
4153 **/
4154static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4155{
4156 int i;
4157
4158 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004159 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004160}
4161
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004162/**
4163 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4164 * @adapter: board private structure
4165 **/
4166static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4167{
4168 int i;
4169
4170 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004171 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004172}
4173
Alexander Duycke4911d52011-05-11 07:18:52 +00004174static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4175{
4176 struct hlist_node *node, *node2;
4177 struct ixgbe_fdir_filter *filter;
4178
4179 spin_lock(&adapter->fdir_perfect_lock);
4180
4181 hlist_for_each_entry_safe(filter, node, node2,
4182 &adapter->fdir_filter_list, fdir_node) {
4183 hlist_del(&filter->fdir_node);
4184 kfree(filter);
4185 }
4186 adapter->fdir_filter_count = 0;
4187
4188 spin_unlock(&adapter->fdir_perfect_lock);
4189}
4190
Auke Kok9a799d72007-09-15 14:07:45 -07004191void ixgbe_down(struct ixgbe_adapter *adapter)
4192{
4193 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004194 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004195 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004196 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004197
4198 /* signal that we are down to the interrupt handler */
4199 set_bit(__IXGBE_DOWN, &adapter->state);
4200
4201 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004202 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4203 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004204
Yi Zou2d39d572011-01-06 14:29:56 +00004205 /* disable all enabled rx queues */
4206 for (i = 0; i < adapter->num_rx_queues; i++)
4207 /* this call also flushes the previous write */
4208 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4209
Don Skidmore032b4322011-03-18 09:32:53 +00004210 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004211
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004212 netif_tx_stop_all_queues(netdev);
4213
Alexander Duyck70864002011-04-27 09:13:56 +00004214 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004215 netif_carrier_off(netdev);
4216 netif_tx_disable(netdev);
4217
4218 ixgbe_irq_disable(adapter);
4219
4220 ixgbe_napi_disable_all(adapter);
4221
Alexander Duyckd034acf2011-04-27 09:25:34 +00004222 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4223 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004224 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4225
4226 del_timer_sync(&adapter->service_timer);
4227
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004228 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004229 /* Clear EITR Select mapping */
4230 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4231
4232 /* Mark all the VFs as inactive */
4233 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004234 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004235
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004236 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004237 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004238
Auke Kok9a799d72007-09-15 14:07:45 -07004239 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004240 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004241 }
4242
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004243 /* disable transmits in the hardware now that interrupts are off */
4244 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004245 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004246 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004247 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004248
4249 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004250 switch (hw->mac.type) {
4251 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004252 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004253 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004254 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4255 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004256 break;
4257 default:
4258 break;
4259 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004260
Paul Larson6f4a0e42008-06-24 17:00:56 -07004261 if (!pci_channel_offline(adapter->pdev))
4262 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004263
4264 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4265 if (hw->mac.ops.disable_tx_laser &&
4266 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004267 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004268 (hw->mac.type == ixgbe_mac_82599EB))))
4269 hw->mac.ops.disable_tx_laser(hw);
4270
Auke Kok9a799d72007-09-15 14:07:45 -07004271 ixgbe_clean_all_tx_rings(adapter);
4272 ixgbe_clean_all_rx_rings(adapter);
4273
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004274#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004275 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004276 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004277#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004278}
4279
Auke Kok9a799d72007-09-15 14:07:45 -07004280/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004281 * ixgbe_poll - NAPI Rx polling callback
4282 * @napi: structure for representing this polling device
4283 * @budget: how many packets driver is allowed to clean
4284 *
4285 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004286 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004287static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004288{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004289 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004290 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004291 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004292 struct ixgbe_ring *ring;
4293 int per_ring_budget;
4294 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004295
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004296#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004297 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4298 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004299#endif
4300
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004301 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4302 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004303
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004304 /* attempt to distribute budget to each queue fairly, but don't allow
4305 * the budget to go below 1 because we'll exit polling */
4306 if (q_vector->rx.count > 1)
4307 per_ring_budget = max(budget/q_vector->rx.count, 1);
4308 else
4309 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004310
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004311 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4312 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4313 per_ring_budget);
4314
4315 /* If all work not completed, return budget and keep polling */
4316 if (!clean_complete)
4317 return budget;
4318
4319 /* all work done, exit the polling mode */
4320 napi_complete(napi);
4321 if (adapter->rx_itr_setting & 1)
4322 ixgbe_set_itr(q_vector);
4323 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4324 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4325
4326 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004327}
4328
4329/**
4330 * ixgbe_tx_timeout - Respond to a Tx Hang
4331 * @netdev: network interface device structure
4332 **/
4333static void ixgbe_tx_timeout(struct net_device *netdev)
4334{
4335 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4336
4337 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004338 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004339}
4340
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004341/**
4342 * ixgbe_set_rss_queues: Allocate queues for RSS
4343 * @adapter: board private structure to initialize
4344 *
4345 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4346 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4347 *
4348 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004349static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4350{
4351 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004352 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004353
4354 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004355 f->mask = 0xF;
4356 adapter->num_rx_queues = f->indices;
4357 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004358 ret = true;
4359 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004360 ret = false;
4361 }
4362
4363 return ret;
4364}
4365
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004366/**
4367 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4368 * @adapter: board private structure to initialize
4369 *
4370 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4371 * to the original CPU that initiated the Tx session. This runs in addition
4372 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4373 * Rx load across CPUs using RSS.
4374 *
4375 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004376static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004377{
4378 bool ret = false;
4379 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4380
4381 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4382 f_fdir->mask = 0;
4383
Alexander Duyck24ddd962012-02-10 02:08:32 +00004384 /*
4385 * Use RSS in addition to Flow Director to ensure the best
4386 * distribution of flows across cores, even when an FDIR flow
4387 * isn't matched.
4388 */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004389 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4390 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004391 adapter->num_tx_queues = f_fdir->indices;
4392 adapter->num_rx_queues = f_fdir->indices;
4393 ret = true;
4394 } else {
4395 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004396 }
4397 return ret;
4398}
4399
Yi Zou0331a832009-05-17 12:33:52 +00004400#ifdef IXGBE_FCOE
4401/**
4402 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4403 * @adapter: board private structure to initialize
4404 *
4405 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4406 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4407 * rx queues out of the max number of rx queues, instead, it is used as the
4408 * index of the first rx queue used by FCoE.
4409 *
4410 **/
4411static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4412{
Yi Zou0331a832009-05-17 12:33:52 +00004413 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4414
John Fastabende5b64632011-03-08 03:44:52 +00004415 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4416 return false;
4417
John Fastabende901acd2011-04-26 07:26:08 +00004418 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004419
John Fastabende901acd2011-04-26 07:26:08 +00004420 adapter->num_rx_queues = 1;
4421 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004422
John Fastabende901acd2011-04-26 07:26:08 +00004423 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4424 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004425 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004426 ixgbe_set_fdir_queues(adapter);
4427 else
4428 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004429 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004430
John Fastabende901acd2011-04-26 07:26:08 +00004431 /* adding FCoE rx rings to the end */
4432 f->mask = adapter->num_rx_queues;
4433 adapter->num_rx_queues += f->indices;
4434 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004435
John Fastabende5b64632011-03-08 03:44:52 +00004436 return true;
4437}
4438#endif /* IXGBE_FCOE */
4439
John Fastabende901acd2011-04-26 07:26:08 +00004440/* Artificial max queue cap per traffic class in DCB mode */
4441#define DCB_QUEUE_CAP 8
4442
John Fastabende5b64632011-03-08 03:44:52 +00004443#ifdef CONFIG_IXGBE_DCB
4444static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4445{
John Fastabende901acd2011-04-26 07:26:08 +00004446 int per_tc_q, q, i, offset = 0;
4447 struct net_device *dev = adapter->netdev;
4448 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004449
John Fastabende901acd2011-04-26 07:26:08 +00004450 if (!tcs)
4451 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004452
John Fastabende901acd2011-04-26 07:26:08 +00004453 /* Map queue offset and counts onto allocated tx queues */
4454 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4455 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004456
John Fastabend8b1c0b22011-05-03 02:26:48 +00004457 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004458 netdev_set_tc_queue(dev, i, q, offset);
4459 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004460 }
4461
John Fastabende901acd2011-04-26 07:26:08 +00004462 adapter->num_tx_queues = q * tcs;
4463 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004464
4465#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004466 /* FCoE enabled queues require special configuration indexed
4467 * by feature specific indices and mask. Here we map FCoE
4468 * indices onto the DCB queue pairs allowing FCoE to own
4469 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004470 */
John Fastabende901acd2011-04-26 07:26:08 +00004471 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4472 int tc;
4473 struct ixgbe_ring_feature *f =
4474 &adapter->ring_feature[RING_F_FCOE];
4475
4476 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4477 f->indices = dev->tc_to_txq[tc].count;
4478 f->mask = dev->tc_to_txq[tc].offset;
4479 }
John Fastabende5b64632011-03-08 03:44:52 +00004480#endif
4481
John Fastabende901acd2011-04-26 07:26:08 +00004482 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004483}
John Fastabende5b64632011-03-08 03:44:52 +00004484#endif
Yi Zou0331a832009-05-17 12:33:52 +00004485
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004486/**
4487 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4488 * @adapter: board private structure to initialize
4489 *
4490 * IOV doesn't actually use anything, so just NAK the
4491 * request for now and let the other queue routines
4492 * figure out what to do.
4493 */
4494static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4495{
4496 return false;
4497}
4498
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004499/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004500 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004501 * @adapter: board private structure to initialize
4502 *
4503 * This is the top level queue allocation routine. The order here is very
4504 * important, starting with the "most" number of features turned on at once,
4505 * and ending with the smallest set of features. This way large combinations
4506 * can be allocated if they're turned on, and smaller combinations are the
4507 * fallthrough conditions.
4508 *
4509 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004510static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004511{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004512 /* Start with base case */
4513 adapter->num_rx_queues = 1;
4514 adapter->num_tx_queues = 1;
4515 adapter->num_rx_pools = adapter->num_rx_queues;
4516 adapter->num_rx_queues_per_pool = 1;
4517
4518 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004519 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004520
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004521#ifdef CONFIG_IXGBE_DCB
4522 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004523 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004524
4525#endif
John Fastabende5b64632011-03-08 03:44:52 +00004526#ifdef IXGBE_FCOE
4527 if (ixgbe_set_fcoe_queues(adapter))
4528 goto done;
4529
4530#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004531 if (ixgbe_set_fdir_queues(adapter))
4532 goto done;
4533
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004534 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004535 goto done;
4536
4537 /* fallback to base case */
4538 adapter->num_rx_queues = 1;
4539 adapter->num_tx_queues = 1;
4540
4541done:
Yi Zou9d837ea2012-01-07 08:39:50 +00004542 if ((adapter->netdev->reg_state == NETREG_UNREGISTERED) ||
4543 (adapter->netdev->reg_state == NETREG_UNREGISTERING))
4544 return 0;
4545
Ben Hutchings847f53f2010-09-27 08:28:56 +00004546 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004547 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004548 return netif_set_real_num_rx_queues(adapter->netdev,
4549 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004550}
4551
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004552static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004553 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554{
4555 int err, vector_threshold;
4556
4557 /* We'll want at least 3 (vector_threshold):
4558 * 1) TxQ[0] Cleanup
4559 * 2) RxQ[0] Cleanup
4560 * 3) Other (Link Status Change, etc.)
4561 * 4) TCP Timer (optional)
4562 */
4563 vector_threshold = MIN_MSIX_COUNT;
4564
Alexander Duyck24ddd962012-02-10 02:08:32 +00004565 /*
4566 * The more we get, the more we will assign to Tx/Rx Cleanup
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004567 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4568 * Right now, we simply care about how many we'll get; we'll
4569 * set them up later while requesting irq's.
4570 */
4571 while (vectors >= vector_threshold) {
4572 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004573 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004574 if (!err) /* Success in acquiring all requested vectors. */
4575 break;
4576 else if (err < 0)
4577 vectors = 0; /* Nasty failure, quit now */
4578 else /* err == number of vectors we should try again with */
4579 vectors = err;
4580 }
4581
4582 if (vectors < vector_threshold) {
4583 /* Can't allocate enough MSI-X interrupts? Oh well.
4584 * This just means we'll go with either a single MSI
4585 * vector or fall back to legacy interrupts.
4586 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004587 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4588 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004589 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4590 kfree(adapter->msix_entries);
4591 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004592 } else {
4593 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004594 /*
4595 * Adjust for only the vectors we'll use, which is minimum
4596 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4597 * vectors we were allocated.
4598 */
4599 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004600 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004601 }
4602}
4603
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004604/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004605 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004606 * @adapter: board private structure to initialize
4607 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004608 * Cache the descriptor ring offsets for RSS to the assigned rings.
4609 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004610 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004611static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004612{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004613 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004614
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004615 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4616 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004617
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004618 for (i = 0; i < adapter->num_rx_queues; i++)
4619 adapter->rx_ring[i]->reg_idx = i;
4620 for (i = 0; i < adapter->num_tx_queues; i++)
4621 adapter->tx_ring[i]->reg_idx = i;
4622
4623 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004624}
4625
4626#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004627
4628/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004629static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4630 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004631{
4632 struct net_device *dev = adapter->netdev;
4633 struct ixgbe_hw *hw = &adapter->hw;
4634 u8 num_tcs = netdev_get_num_tc(dev);
4635
4636 *tx = 0;
4637 *rx = 0;
4638
4639 switch (hw->mac.type) {
4640 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004641 *tx = tc << 2;
4642 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004643 break;
4644 case ixgbe_mac_82599EB:
4645 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004646 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004647 if (tc < 3) {
4648 *tx = tc << 5;
4649 *rx = tc << 4;
4650 } else if (tc < 5) {
4651 *tx = ((tc + 2) << 4);
4652 *rx = tc << 4;
4653 } else if (tc < num_tcs) {
4654 *tx = ((tc + 8) << 3);
4655 *rx = tc << 4;
4656 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004657 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004658 *rx = tc << 5;
4659 switch (tc) {
4660 case 0:
4661 *tx = 0;
4662 break;
4663 case 1:
4664 *tx = 64;
4665 break;
4666 case 2:
4667 *tx = 96;
4668 break;
4669 case 3:
4670 *tx = 112;
4671 break;
4672 default:
4673 break;
4674 }
4675 }
4676 break;
4677 default:
4678 break;
4679 }
4680}
4681
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004682/**
4683 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4684 * @adapter: board private structure to initialize
4685 *
4686 * Cache the descriptor ring offsets for DCB to the assigned rings.
4687 *
4688 **/
4689static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4690{
John Fastabende5b64632011-03-08 03:44:52 +00004691 struct net_device *dev = adapter->netdev;
4692 int i, j, k;
4693 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004694
John Fastabend8b1c0b22011-05-03 02:26:48 +00004695 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004696 return false;
4697
John Fastabende5b64632011-03-08 03:44:52 +00004698 for (i = 0, k = 0; i < num_tcs; i++) {
4699 unsigned int tx_s, rx_s;
4700 u16 count = dev->tc_to_txq[i].count;
4701
4702 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4703 for (j = 0; j < count; j++, k++) {
4704 adapter->tx_ring[k]->reg_idx = tx_s + j;
4705 adapter->rx_ring[k]->reg_idx = rx_s + j;
4706 adapter->tx_ring[k]->dcb_tc = i;
4707 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004708 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004709 }
John Fastabende5b64632011-03-08 03:44:52 +00004710
4711 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004712}
4713#endif
4714
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004715/**
4716 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4717 * @adapter: board private structure to initialize
4718 *
4719 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4720 *
4721 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004722static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004723{
4724 int i;
4725 bool ret = false;
4726
Alexander Duyck03ecf912011-05-20 07:36:17 +00004727 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4728 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004729 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004730 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004731 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004732 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004733 ret = true;
4734 }
4735
4736 return ret;
4737}
4738
Yi Zou0331a832009-05-17 12:33:52 +00004739#ifdef IXGBE_FCOE
4740/**
4741 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4742 * @adapter: board private structure to initialize
4743 *
4744 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4745 *
4746 */
4747static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4748{
Yi Zou0331a832009-05-17 12:33:52 +00004749 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004750 int i;
4751 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004752
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004753 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4754 return false;
4755
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004756 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004757 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004758 ixgbe_cache_ring_fdir(adapter);
4759 else
4760 ixgbe_cache_ring_rss(adapter);
4761
4762 fcoe_rx_i = f->mask;
4763 fcoe_tx_i = f->mask;
4764 }
4765 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4766 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4767 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4768 }
4769 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004770}
4771
4772#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004773/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004774 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4775 * @adapter: board private structure to initialize
4776 *
4777 * SR-IOV doesn't use any descriptor rings but changes the default if
4778 * no other mapping is used.
4779 *
4780 */
4781static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4782{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004783 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4784 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004785 if (adapter->num_vfs)
4786 return true;
4787 else
4788 return false;
4789}
4790
4791/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004792 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4793 * @adapter: board private structure to initialize
4794 *
4795 * Once we know the feature-set enabled for the device, we'll cache
4796 * the register offset the descriptor ring is assigned to.
4797 *
4798 * Note, the order the various feature calls is important. It must start with
4799 * the "most" features enabled at the same time, then trickle down to the
4800 * least amount of features turned on at once.
4801 **/
4802static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4803{
4804 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004805 adapter->rx_ring[0]->reg_idx = 0;
4806 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004807
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004808 if (ixgbe_cache_ring_sriov(adapter))
4809 return;
4810
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004811#ifdef CONFIG_IXGBE_DCB
4812 if (ixgbe_cache_ring_dcb(adapter))
4813 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004814#endif
John Fastabende5b64632011-03-08 03:44:52 +00004815
4816#ifdef IXGBE_FCOE
4817 if (ixgbe_cache_ring_fcoe(adapter))
4818 return;
4819#endif /* IXGBE_FCOE */
4820
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004821 if (ixgbe_cache_ring_fdir(adapter))
4822 return;
4823
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004824 if (ixgbe_cache_ring_rss(adapter))
4825 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826}
4827
Auke Kok9a799d72007-09-15 14:07:45 -07004828/**
4829 * ixgbe_alloc_queues - Allocate memory for all rings
4830 * @adapter: board private structure to initialize
4831 *
4832 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004833 * number of queues at compile-time. The polling_netdev array is
4834 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004835 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004836static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004837{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004838 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 if (nid < 0 || !node_online(nid))
4841 nid = first_online_node;
4842
4843 for (; tx < adapter->num_tx_queues; tx++) {
4844 struct ixgbe_ring *ring;
4845
4846 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004847 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004848 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004849 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004850 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004851 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004852 ring->queue_index = tx;
4853 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004854 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004855 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004856
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004857 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004858 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004859
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004860 for (; rx < adapter->num_rx_queues; rx++) {
4861 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004862
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004863 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004864 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004865 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004866 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004867 goto err_allocation;
4868 ring->count = adapter->rx_ring_count;
4869 ring->queue_index = rx;
4870 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004871 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004872 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004873
Alexander Duyck8a0da212012-01-31 02:59:49 +00004874 /*
4875 * 82599 errata, UDP frames with a 0 checksum can be marked as
4876 * checksum errors.
4877 */
4878 if (adapter->hw.mac.type == ixgbe_mac_82599EB)
4879 set_bit(__IXGBE_RX_CSUM_UDP_ZERO_ERR, &ring->state);
4880
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004881 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004882 }
4883
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004884 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004885
4886 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004887
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004888err_allocation:
4889 while (tx)
4890 kfree(adapter->tx_ring[--tx]);
4891
4892 while (rx)
4893 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004894 return -ENOMEM;
4895}
4896
4897/**
4898 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4899 * @adapter: board private structure to initialize
4900 *
4901 * Attempt to configure the interrupts using the best available
4902 * capabilities of the hardware and the kernel.
4903 **/
Al Virofeea6a52008-11-27 15:34:07 -08004904static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004905{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004906 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004907 int err = 0;
4908 int vector, v_budget;
4909
4910 /*
4911 * It's easy to be greedy for MSI-X vectors, but it really
4912 * doesn't do us much good if we have a lot more vectors
4913 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004914 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004915 */
4916 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004917 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004918
4919 /*
4920 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004921 * hw.mac->max_msix_vectors vectors. With features
4922 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4923 * descriptor queues supported by our device. Thus, we cap it off in
4924 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004925 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004926 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004927
4928 /* A failure in MSI-X entry allocation isn't fatal, but it does
4929 * mean we disable MSI-X capabilities of the adapter. */
4930 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004931 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004932 if (adapter->msix_entries) {
4933 for (vector = 0; vector < v_budget; vector++)
4934 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004935
Alexander Duyck7a921c92009-05-06 10:43:28 +00004936 ixgbe_acquire_msix_vectors(adapter, v_budget);
4937
4938 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4939 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004940 }
David S. Miller26d27842010-05-03 15:18:22 -07004941
Alexander Duyck7a921c92009-05-06 10:43:28 +00004942 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4943 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004944 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004945 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004946 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004947 "queues are disabled. Disabling Flow Director\n");
4948 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004949 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004950 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004951 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4952 ixgbe_disable_sriov(adapter);
4953
Ben Hutchings847f53f2010-09-27 08:28:56 +00004954 err = ixgbe_set_num_queues(adapter);
4955 if (err)
4956 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004957
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004958 err = pci_enable_msi(adapter->pdev);
4959 if (!err) {
4960 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4961 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004962 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4963 "Unable to allocate MSI interrupt, "
4964 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965 /* reset err */
4966 err = 0;
4967 }
4968
4969out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004970 return err;
4971}
4972
Alexander Duyck7a921c92009-05-06 10:43:28 +00004973/**
4974 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4975 * @adapter: board private structure to initialize
4976 *
4977 * We allocate one q_vector per queue interrupt. If allocation fails we
4978 * return -ENOMEM.
4979 **/
4980static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4981{
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004982 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004983 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004984
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004985 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004986 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004987 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004988 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004989
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004990 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004991 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004992 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004993 if (!q_vector)
4994 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004995 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004996 if (!q_vector)
4997 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004998
Alexander Duyck7a921c92009-05-06 10:43:28 +00004999 q_vector->adapter = adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005000 q_vector->v_idx = v_idx;
5001
Alexander Duyck207867f2011-07-15 03:05:37 +00005002 /* Allocate the affinity_hint cpumask, configure the mask */
5003 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
5004 goto err_out;
5005 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005006 netif_napi_add(adapter->netdev, &q_vector->napi,
5007 ixgbe_poll, 64);
5008 adapter->q_vector[v_idx] = q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005009 }
5010
5011 return 0;
5012
5013err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005014 while (v_idx) {
5015 v_idx--;
5016 q_vector = adapter->q_vector[v_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005017 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00005018 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005019 kfree(q_vector);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00005020 adapter->q_vector[v_idx] = NULL;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005021 }
5022 return -ENOMEM;
5023}
5024
5025/**
5026 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5027 * @adapter: board private structure to initialize
5028 *
5029 * This function frees the memory allocated to the q_vectors. In addition if
5030 * NAPI is enabled it will delete any references to the NAPI struct prior
5031 * to freeing the q_vector.
5032 **/
5033static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5034{
Alexander Duyck207867f2011-07-15 03:05:37 +00005035 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005036
Alexander Duyck91281fd2009-06-04 16:00:27 +00005037 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005038 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005039 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005040 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041
Alexander Duyck207867f2011-07-15 03:05:37 +00005042 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
5043 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
5044 adapter->q_vector[v_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005045 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00005046 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005047 kfree(q_vector);
5048 }
5049}
5050
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005051static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005052{
5053 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5054 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5055 pci_disable_msix(adapter->pdev);
5056 kfree(adapter->msix_entries);
5057 adapter->msix_entries = NULL;
5058 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5059 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5060 pci_disable_msi(adapter->pdev);
5061 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005062}
5063
5064/**
5065 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5066 * @adapter: board private structure to initialize
5067 *
5068 * We determine which interrupt scheme to use based on...
5069 * - Kernel support (MSI, MSI-X)
5070 * - which can be user-defined (via MODULE_PARAM)
5071 * - Hardware queue count (num_*_queues)
5072 * - defined by miscellaneous hardware support/features (RSS, etc.)
5073 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005074int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005075{
5076 int err;
5077
5078 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005079 err = ixgbe_set_num_queues(adapter);
5080 if (err)
5081 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005082
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005083 err = ixgbe_set_interrupt_capability(adapter);
5084 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005085 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005086 goto err_set_interrupt;
5087 }
5088
Alexander Duyck7a921c92009-05-06 10:43:28 +00005089 err = ixgbe_alloc_q_vectors(adapter);
5090 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005091 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005092 goto err_alloc_q_vectors;
5093 }
5094
5095 err = ixgbe_alloc_queues(adapter);
5096 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005097 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005098 goto err_alloc_queues;
5099 }
5100
Emil Tantilov849c4542010-06-03 16:53:41 +00005101 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005102 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5103 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005104
5105 set_bit(__IXGBE_DOWN, &adapter->state);
5106
5107 return 0;
5108
Alexander Duyck7a921c92009-05-06 10:43:28 +00005109err_alloc_queues:
5110 ixgbe_free_q_vectors(adapter);
5111err_alloc_q_vectors:
5112 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005113err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005114 return err;
5115}
5116
5117/**
5118 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5119 * @adapter: board private structure to clear interrupt scheme on
5120 *
5121 * We go through and clear interrupt specific resources and reset the structure
5122 * to pre-load conditions
5123 **/
5124void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5125{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005126 int i;
5127
5128 for (i = 0; i < adapter->num_tx_queues; i++) {
5129 kfree(adapter->tx_ring[i]);
5130 adapter->tx_ring[i] = NULL;
5131 }
5132 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005133 struct ixgbe_ring *ring = adapter->rx_ring[i];
5134
5135 /* ixgbe_get_stats64() might access this ring, we must wait
5136 * a grace period before freeing it.
5137 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005138 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005139 adapter->rx_ring[i] = NULL;
5140 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005141
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005142 adapter->num_tx_queues = 0;
5143 adapter->num_rx_queues = 0;
5144
Alexander Duyck7a921c92009-05-06 10:43:28 +00005145 ixgbe_free_q_vectors(adapter);
5146 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005147}
5148
5149/**
5150 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5151 * @adapter: board private structure to initialize
5152 *
5153 * ixgbe_sw_init initializes the Adapter private data structure.
5154 * Fields are initialized based on PCI device information and
5155 * OS network device settings (MTU size).
5156 **/
5157static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5158{
5159 struct ixgbe_hw *hw = &adapter->hw;
5160 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005161 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005162#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005163 int j;
5164 struct tc_configuration *tc;
5165#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005166
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005167 /* PCI config space info */
5168
5169 hw->vendor_id = pdev->vendor;
5170 hw->device_id = pdev->device;
5171 hw->revision_id = pdev->revision;
5172 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5173 hw->subsystem_device_id = pdev->subsystem_device;
5174
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005175 /* Set capability flags */
5176 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5177 adapter->ring_feature[RING_F_RSS].indices = rss;
5178 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005179 switch (hw->mac.type) {
5180 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005181 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5182 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005183 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005184 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005185 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005186 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5187 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005188 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005189 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5190 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005191 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5192 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005193 /* Flow Director hash filters enabled */
5194 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5195 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005196 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005197 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005198 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005199#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005200 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5201 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5202 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005203#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005204 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005205 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005206#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005207#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005208 break;
5209 default:
5210 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005211 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005212
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005213 /* n-tuple support exists, always init our spinlock */
5214 spin_lock_init(&adapter->fdir_perfect_lock);
5215
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005216#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005217 switch (hw->mac.type) {
5218 case ixgbe_mac_X540:
5219 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5220 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5221 break;
5222 default:
5223 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5224 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5225 break;
5226 }
5227
Alexander Duyck2f90b862008-11-20 20:52:10 -08005228 /* Configure DCB traffic classes */
5229 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5230 tc = &adapter->dcb_cfg.tc_config[j];
5231 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5232 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5233 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5234 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5235 tc->dcb_pfc = pfc_disabled;
5236 }
John Fastabend4de2a022011-09-27 03:52:01 +00005237
5238 /* Initialize default user to priority mapping, UPx->TC0 */
5239 tc = &adapter->dcb_cfg.tc_config[0];
5240 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5241 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5242
Alexander Duyck2f90b862008-11-20 20:52:10 -08005243 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5244 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005245 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005246 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005247 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005248 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005249 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005250
5251#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005252
5253 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005254 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005255 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005256#ifdef CONFIG_DCB
5257 adapter->last_lfc_mode = hw->fc.current_mode;
5258#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005259 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005260 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5261 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005262 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005263
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005264 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005265 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005266 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005267
5268 /* set defaults for eitr in MegaBytes */
5269 adapter->eitr_low = 10;
5270 adapter->eitr_high = 20;
5271
5272 /* set default ring sizes */
5273 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5274 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5275
Alexander Duyckbd198052011-06-11 01:45:08 +00005276 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005277 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005278
Auke Kok9a799d72007-09-15 14:07:45 -07005279 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005280 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005281 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005282 return -EIO;
5283 }
5284
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005285 /* get assigned NUMA node */
5286 adapter->node = dev_to_node(&pdev->dev);
5287
Auke Kok9a799d72007-09-15 14:07:45 -07005288 set_bit(__IXGBE_DOWN, &adapter->state);
5289
5290 return 0;
5291}
5292
5293/**
5294 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005295 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005296 *
5297 * Return 0 on success, negative on failure
5298 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005299int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005300{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005301 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005302 int size;
5303
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005304 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005305 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005306 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005307 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005308 if (!tx_ring->tx_buffer_info)
5309 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005310
5311 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005312 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005313 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005314
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005315 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005316 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005317 if (!tx_ring->desc)
5318 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005319
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005320 tx_ring->next_to_use = 0;
5321 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005322 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005323
5324err:
5325 vfree(tx_ring->tx_buffer_info);
5326 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005327 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005328 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005329}
5330
5331/**
Alexander Duyck69888672008-09-11 20:05:39 -07005332 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5333 * @adapter: board private structure
5334 *
5335 * If this function returns with an error, then it's possible one or
5336 * more of the rings is populated (while the rest are not). It is the
5337 * callers duty to clean those orphaned rings.
5338 *
5339 * Return 0 on success, negative on failure
5340 **/
5341static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5342{
5343 int i, err = 0;
5344
5345 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005346 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005347 if (!err)
5348 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005349 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005350 break;
5351 }
5352
5353 return err;
5354}
5355
5356/**
Auke Kok9a799d72007-09-15 14:07:45 -07005357 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005358 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005359 *
5360 * Returns 0 on success, negative on failure
5361 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005362int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005363{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005364 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005365 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005366
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005367 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005368 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005369 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005370 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005371 if (!rx_ring->rx_buffer_info)
5372 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005373
Auke Kok9a799d72007-09-15 14:07:45 -07005374 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005375 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5376 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005377
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005378 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005379 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005380
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005381 if (!rx_ring->desc)
5382 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005383
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005384 rx_ring->next_to_clean = 0;
5385 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005386
5387 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388err:
5389 vfree(rx_ring->rx_buffer_info);
5390 rx_ring->rx_buffer_info = NULL;
5391 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005392 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005393}
5394
5395/**
Alexander Duyck69888672008-09-11 20:05:39 -07005396 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5397 * @adapter: board private structure
5398 *
5399 * If this function returns with an error, then it's possible one or
5400 * more of the rings is populated (while the rest are not). It is the
5401 * callers duty to clean those orphaned rings.
5402 *
5403 * Return 0 on success, negative on failure
5404 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005405static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5406{
5407 int i, err = 0;
5408
5409 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005410 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005411 if (!err)
5412 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005413 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005414 break;
5415 }
5416
5417 return err;
5418}
5419
5420/**
Auke Kok9a799d72007-09-15 14:07:45 -07005421 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005422 * @tx_ring: Tx descriptor ring for a specific queue
5423 *
5424 * Free all transmit software resources
5425 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005426void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005427{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005428 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005429
5430 vfree(tx_ring->tx_buffer_info);
5431 tx_ring->tx_buffer_info = NULL;
5432
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005433 /* if not set, then don't free */
5434 if (!tx_ring->desc)
5435 return;
5436
5437 dma_free_coherent(tx_ring->dev, tx_ring->size,
5438 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005439
5440 tx_ring->desc = NULL;
5441}
5442
5443/**
5444 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5445 * @adapter: board private structure
5446 *
5447 * Free all transmit software resources
5448 **/
5449static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5450{
5451 int i;
5452
5453 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005454 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005455 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005456}
5457
5458/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005459 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005460 * @rx_ring: ring to clean the resources from
5461 *
5462 * Free all receive software resources
5463 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005464void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005465{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005466 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005467
5468 vfree(rx_ring->rx_buffer_info);
5469 rx_ring->rx_buffer_info = NULL;
5470
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005471 /* if not set, then don't free */
5472 if (!rx_ring->desc)
5473 return;
5474
5475 dma_free_coherent(rx_ring->dev, rx_ring->size,
5476 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005477
5478 rx_ring->desc = NULL;
5479}
5480
5481/**
5482 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5483 * @adapter: board private structure
5484 *
5485 * Free all receive software resources
5486 **/
5487static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5488{
5489 int i;
5490
5491 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005492 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005493 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005494}
5495
5496/**
Auke Kok9a799d72007-09-15 14:07:45 -07005497 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5498 * @netdev: network interface device structure
5499 * @new_mtu: new value for maximum frame size
5500 *
5501 * Returns 0 on success, negative on failure
5502 **/
5503static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5504{
5505 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005506 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005507 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5508
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005509 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005510 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5511 hw->mac.type != ixgbe_mac_X540) {
5512 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5513 return -EINVAL;
5514 } else {
5515 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5516 return -EINVAL;
5517 }
Auke Kok9a799d72007-09-15 14:07:45 -07005518
Emil Tantilov396e7992010-07-01 20:05:12 +00005519 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005520 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005521 netdev->mtu = new_mtu;
5522
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005523 if (netif_running(netdev))
5524 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005525
5526 return 0;
5527}
5528
5529/**
5530 * ixgbe_open - Called when a network interface is made active
5531 * @netdev: network interface device structure
5532 *
5533 * Returns 0 on success, negative value on failure
5534 *
5535 * The open entry point is called when a network interface is made
5536 * active by the system (IFF_UP). At this point all resources needed
5537 * for transmit and receive operations are allocated, the interrupt
5538 * handler is registered with the OS, the watchdog timer is started,
5539 * and the stack is notified that the interface is ready.
5540 **/
5541static int ixgbe_open(struct net_device *netdev)
5542{
5543 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5544 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005545
Auke Kok4bebfaa2008-02-11 09:26:01 -08005546 /* disallow open during test */
5547 if (test_bit(__IXGBE_TESTING, &adapter->state))
5548 return -EBUSY;
5549
Jesse Brandeburg54386462009-04-17 20:44:27 +00005550 netif_carrier_off(netdev);
5551
Auke Kok9a799d72007-09-15 14:07:45 -07005552 /* allocate transmit descriptors */
5553 err = ixgbe_setup_all_tx_resources(adapter);
5554 if (err)
5555 goto err_setup_tx;
5556
Auke Kok9a799d72007-09-15 14:07:45 -07005557 /* allocate receive descriptors */
5558 err = ixgbe_setup_all_rx_resources(adapter);
5559 if (err)
5560 goto err_setup_rx;
5561
5562 ixgbe_configure(adapter);
5563
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005564 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005565 if (err)
5566 goto err_req_irq;
5567
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005568 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005569
5570 return 0;
5571
Auke Kok9a799d72007-09-15 14:07:45 -07005572err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005573err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005574 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005575err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005576 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005577 ixgbe_reset(adapter);
5578
5579 return err;
5580}
5581
5582/**
5583 * ixgbe_close - Disables a network interface
5584 * @netdev: network interface device structure
5585 *
5586 * Returns 0, this is not allowed to fail
5587 *
5588 * The close entry point is called when an interface is de-activated
5589 * by the OS. The hardware is still under the drivers control, but
5590 * needs to be disabled. A global MAC reset is issued to stop the
5591 * hardware, and all transmit and receive resources are freed.
5592 **/
5593static int ixgbe_close(struct net_device *netdev)
5594{
5595 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005596
5597 ixgbe_down(adapter);
5598 ixgbe_free_irq(adapter);
5599
Alexander Duycke4911d52011-05-11 07:18:52 +00005600 ixgbe_fdir_filter_exit(adapter);
5601
Auke Kok9a799d72007-09-15 14:07:45 -07005602 ixgbe_free_all_tx_resources(adapter);
5603 ixgbe_free_all_rx_resources(adapter);
5604
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005605 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005606
5607 return 0;
5608}
5609
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005610#ifdef CONFIG_PM
5611static int ixgbe_resume(struct pci_dev *pdev)
5612{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005613 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5614 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005615 u32 err;
5616
5617 pci_set_power_state(pdev, PCI_D0);
5618 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005619 /*
5620 * pci_restore_state clears dev->state_saved so call
5621 * pci_save_state to restore it.
5622 */
5623 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005624
5625 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005626 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005627 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628 return err;
5629 }
5630 pci_set_master(pdev);
5631
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005632 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633
5634 err = ixgbe_init_interrupt_scheme(adapter);
5635 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005636 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005637 return err;
5638 }
5639
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005640 ixgbe_reset(adapter);
5641
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005642 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5643
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005644 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005645 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005646 if (err)
5647 return err;
5648 }
5649
5650 netif_device_attach(netdev);
5651
5652 return 0;
5653}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005654#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005655
5656static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005657{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005658 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5659 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005660 struct ixgbe_hw *hw = &adapter->hw;
5661 u32 ctrl, fctrl;
5662 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005663#ifdef CONFIG_PM
5664 int retval = 0;
5665#endif
5666
5667 netif_device_detach(netdev);
5668
5669 if (netif_running(netdev)) {
5670 ixgbe_down(adapter);
5671 ixgbe_free_irq(adapter);
5672 ixgbe_free_all_tx_resources(adapter);
5673 ixgbe_free_all_rx_resources(adapter);
5674 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005675
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005676 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005677#ifdef CONFIG_DCB
5678 kfree(adapter->ixgbe_ieee_pfc);
5679 kfree(adapter->ixgbe_ieee_ets);
5680#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005681
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682#ifdef CONFIG_PM
5683 retval = pci_save_state(pdev);
5684 if (retval)
5685 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005686
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005687#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005688 if (wufc) {
5689 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005690
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005691 /* turn on all-multi mode if wake on multicast is enabled */
5692 if (wufc & IXGBE_WUFC_MC) {
5693 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5694 fctrl |= IXGBE_FCTRL_MPE;
5695 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5696 }
5697
5698 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5699 ctrl |= IXGBE_CTRL_GIO_DIS;
5700 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5701
5702 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5703 } else {
5704 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5705 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5706 }
5707
Alexander Duyckbd508172010-11-16 19:27:03 -08005708 switch (hw->mac.type) {
5709 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005710 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005711 break;
5712 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005713 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005714 pci_wake_from_d3(pdev, !!wufc);
5715 break;
5716 default:
5717 break;
5718 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005719
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005720 *enable_wake = !!wufc;
5721
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005722 ixgbe_release_hw_control(adapter);
5723
5724 pci_disable_device(pdev);
5725
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005726 return 0;
5727}
5728
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005729#ifdef CONFIG_PM
5730static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5731{
5732 int retval;
5733 bool wake;
5734
5735 retval = __ixgbe_shutdown(pdev, &wake);
5736 if (retval)
5737 return retval;
5738
5739 if (wake) {
5740 pci_prepare_to_sleep(pdev);
5741 } else {
5742 pci_wake_from_d3(pdev, false);
5743 pci_set_power_state(pdev, PCI_D3hot);
5744 }
5745
5746 return 0;
5747}
5748#endif /* CONFIG_PM */
5749
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005750static void ixgbe_shutdown(struct pci_dev *pdev)
5751{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005752 bool wake;
5753
5754 __ixgbe_shutdown(pdev, &wake);
5755
5756 if (system_state == SYSTEM_POWER_OFF) {
5757 pci_wake_from_d3(pdev, wake);
5758 pci_set_power_state(pdev, PCI_D3hot);
5759 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005760}
5761
5762/**
Auke Kok9a799d72007-09-15 14:07:45 -07005763 * ixgbe_update_stats - Update the board statistics counters.
5764 * @adapter: board private structure
5765 **/
5766void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5767{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005768 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005769 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005770 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005771 u64 total_mpc = 0;
5772 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005773 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5774 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005775 u64 bytes = 0, packets = 0, hw_csum_rx_error = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005776#ifdef IXGBE_FCOE
5777 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5778 unsigned int cpu;
5779 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5780#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005781
Don Skidmored08935c2010-06-11 13:20:29 +00005782 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5783 test_bit(__IXGBE_RESETTING, &adapter->state))
5784 return;
5785
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005786 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005787 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005788 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005789 for (i = 0; i < 16; i++)
5790 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005791 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005792 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005793 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5794 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005795 }
5796 adapter->rsc_total_count = rsc_count;
5797 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005798 }
5799
Alexander Duyck5b7da512010-11-16 19:26:50 -08005800 for (i = 0; i < adapter->num_rx_queues; i++) {
5801 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5802 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5803 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5804 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005805 hw_csum_rx_error += rx_ring->rx_stats.csum_err;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005806 bytes += rx_ring->stats.bytes;
5807 packets += rx_ring->stats.packets;
5808 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005809 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005810 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5811 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
Alexander Duyck8a0da212012-01-31 02:59:49 +00005812 adapter->hw_csum_rx_error = hw_csum_rx_error;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005813 netdev->stats.rx_bytes = bytes;
5814 netdev->stats.rx_packets = packets;
5815
5816 bytes = 0;
5817 packets = 0;
5818 /* gather some stats to the adapter struct that are per queue */
5819 for (i = 0; i < adapter->num_tx_queues; i++) {
5820 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5821 restart_queue += tx_ring->tx_stats.restart_queue;
5822 tx_busy += tx_ring->tx_stats.tx_busy;
5823 bytes += tx_ring->stats.bytes;
5824 packets += tx_ring->stats.packets;
5825 }
5826 adapter->restart_queue = restart_queue;
5827 adapter->tx_busy = tx_busy;
5828 netdev->stats.tx_bytes = bytes;
5829 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005830
Joe Perches7ca647b2010-09-07 21:35:40 +00005831 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005832
5833 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005834 for (i = 0; i < 8; i++) {
5835 /* for packet buffers not used, the register should read 0 */
5836 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5837 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005838 hwstats->mpc[i] += mpc;
5839 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005840 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5841 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005842 switch (hw->mac.type) {
5843 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005844 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5845 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5846 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 hwstats->pxonrxc[i] +=
5848 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005849 break;
5850 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005851 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005852 hwstats->pxonrxc[i] +=
5853 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005854 break;
5855 default:
5856 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005857 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005858 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005859
5860 /*16 register reads */
5861 for (i = 0; i < 16; i++) {
5862 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5863 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5864 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5865 (hw->mac.type == ixgbe_mac_X540)) {
5866 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5867 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5868 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5869 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5870 }
5871 }
5872
Joe Perches7ca647b2010-09-07 21:35:40 +00005873 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005874 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005875 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005876
John Fastabendc84d3242010-11-16 19:27:12 -08005877 ixgbe_update_xoff_received(adapter);
5878
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005879 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005880 switch (hw->mac.type) {
5881 case ixgbe_mac_82598EB:
5882 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005883 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5884 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5885 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5886 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005887 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005888 /* OS2BMC stats are X540 only*/
5889 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5890 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5891 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5892 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5893 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005894 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005895 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005896 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005897 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005898 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005899 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005900 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5902 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005903#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005904 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5905 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5906 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5907 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5908 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5909 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005910 /* Add up per cpu counters for total ddp aloc fail */
5911 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5912 for_each_possible_cpu(cpu) {
5913 fcoe_noddp_counts_sum +=
5914 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5915 fcoe_noddp_ext_buff_counts_sum +=
5916 *per_cpu_ptr(fcoe->
5917 pcpu_noddp_ext_buff, cpu);
5918 }
5919 }
5920 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5921 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005922#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005923 break;
5924 default:
5925 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005926 }
Auke Kok9a799d72007-09-15 14:07:45 -07005927 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005928 hwstats->bprc += bprc;
5929 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005930 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005931 hwstats->mprc -= bprc;
5932 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5933 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5934 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5935 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5936 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5937 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5938 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5939 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005940 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005941 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005942 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005943 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005944 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5945 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005946 /*
5947 * 82598 errata - tx of flow control packets is included in tx counters
5948 */
5949 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005950 hwstats->gptc -= xon_off_tot;
5951 hwstats->mptc -= xon_off_tot;
5952 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5953 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5954 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5955 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5956 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5957 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5958 hwstats->ptc64 -= xon_off_tot;
5959 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5960 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5961 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5962 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5963 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5964 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005965
5966 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005967 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005968
5969 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005970 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005971 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005972 netdev->stats.rx_length_errors = hwstats->rlec;
5973 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005974 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005975}
5976
5977/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005978 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5979 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005980 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005981static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005982{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005983 struct ixgbe_hw *hw = &adapter->hw;
5984 int i;
5985
Alexander Duyckd034acf2011-04-27 09:25:34 +00005986 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5987 return;
5988
5989 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5990
5991 /* if interface is down do nothing */
5992 if (test_bit(__IXGBE_DOWN, &adapter->state))
5993 return;
5994
5995 /* do nothing if we are not using signature filters */
5996 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5997 return;
5998
5999 adapter->fdir_overflow++;
6000
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006001 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6002 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006003 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00006004 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00006005 /* re-enable flow director interrupts */
6006 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006007 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006008 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006009 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006010 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006011}
6012
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006013/**
6014 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6015 * @adapter - pointer to the device adapter structure
6016 *
6017 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006018 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006019 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00006020 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006021 */
6022static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6023{
Auke Kok9a799d72007-09-15 14:07:45 -07006024 struct ixgbe_hw *hw = &adapter->hw;
6025 u64 eics = 0;
6026 int i;
6027
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006028 /* If we're down or resetting, just bail */
6029 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6030 test_bit(__IXGBE_RESETTING, &adapter->state))
6031 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006032
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006033 /* Force detection of hung controller */
6034 if (netif_carrier_ok(adapter->netdev)) {
6035 for (i = 0; i < adapter->num_tx_queues; i++)
6036 set_check_for_tx_hang(adapter->tx_ring[i]);
6037 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006038
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006039 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006040 /*
6041 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006042 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006043 * would set *both* EIMS and EICS for any bit in EIAM
6044 */
6045 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6046 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006047 } else {
6048 /* get one bit for every active tx/rx interrupt vector */
6049 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6050 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006051 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006052 eics |= ((u64)1 << i);
6053 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006054 }
6055
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006056 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006057 ixgbe_irq_rearm_queues(adapter, eics);
6058
Alexander Duyckfe49f042009-06-04 16:00:09 +00006059}
6060
6061/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006062 * ixgbe_watchdog_update_link - update the link status
6063 * @adapter - pointer to the device adapter structure
6064 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006065 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006066static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006067{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006068 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006069 u32 link_speed = adapter->link_speed;
6070 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006071 int i;
6072
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006073 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6074 return;
6075
6076 if (hw->mac.ops.check_link) {
6077 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006078 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006079 /* always assume link is up, if no check link function */
6080 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6081 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006082 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006083 if (link_up) {
6084 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6085 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6086 hw->mac.ops.fc_enable(hw, i);
6087 } else {
6088 hw->mac.ops.fc_enable(hw, 0);
6089 }
6090 }
6091
6092 if (link_up ||
6093 time_after(jiffies, (adapter->link_check_timeout +
6094 IXGBE_TRY_LINK_TIMEOUT))) {
6095 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6096 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6097 IXGBE_WRITE_FLUSH(hw);
6098 }
6099
6100 adapter->link_up = link_up;
6101 adapter->link_speed = link_speed;
6102}
6103
6104/**
6105 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6106 * print link up message
6107 * @adapter - pointer to the device adapter structure
6108 **/
6109static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6110{
6111 struct net_device *netdev = adapter->netdev;
6112 struct ixgbe_hw *hw = &adapter->hw;
6113 u32 link_speed = adapter->link_speed;
6114 bool flow_rx, flow_tx;
6115
6116 /* only continue if link was previously down */
6117 if (netif_carrier_ok(netdev))
6118 return;
6119
6120 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6121
6122 switch (hw->mac.type) {
6123 case ixgbe_mac_82598EB: {
6124 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6125 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6126 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6127 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6128 }
6129 break;
6130 case ixgbe_mac_X540:
6131 case ixgbe_mac_82599EB: {
6132 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6133 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6134 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6135 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6136 }
6137 break;
6138 default:
6139 flow_tx = false;
6140 flow_rx = false;
6141 break;
6142 }
6143 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6144 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6145 "10 Gbps" :
6146 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6147 "1 Gbps" :
6148 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6149 "100 Mbps" :
6150 "unknown speed"))),
6151 ((flow_rx && flow_tx) ? "RX/TX" :
6152 (flow_rx ? "RX" :
6153 (flow_tx ? "TX" : "None"))));
6154
6155 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006156 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006157}
6158
6159/**
6160 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6161 * print link down message
6162 * @adapter - pointer to the adapter structure
6163 **/
6164static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6165{
6166 struct net_device *netdev = adapter->netdev;
6167 struct ixgbe_hw *hw = &adapter->hw;
6168
6169 adapter->link_up = false;
6170 adapter->link_speed = 0;
6171
6172 /* only continue if link was up previously */
6173 if (!netif_carrier_ok(netdev))
6174 return;
6175
6176 /* poll for SFP+ cable when link is down */
6177 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6178 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6179
6180 e_info(drv, "NIC Link is Down\n");
6181 netif_carrier_off(netdev);
6182}
6183
6184/**
6185 * ixgbe_watchdog_flush_tx - flush queues on link down
6186 * @adapter - pointer to the device adapter structure
6187 **/
6188static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6189{
6190 int i;
6191 int some_tx_pending = 0;
6192
6193 if (!netif_carrier_ok(adapter->netdev)) {
6194 for (i = 0; i < adapter->num_tx_queues; i++) {
6195 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6196 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6197 some_tx_pending = 1;
6198 break;
6199 }
6200 }
6201
6202 if (some_tx_pending) {
6203 /* We've lost link, so the controller stops DMA,
6204 * but we've got queued Tx work that's never going
6205 * to get done, so reset controller to flush Tx.
6206 * (Do the reset outside of interrupt context).
6207 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006208 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006209 }
6210 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006211}
6212
Greg Rosea985b6c32010-11-18 03:02:52 +00006213static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6214{
6215 u32 ssvpc;
6216
6217 /* Do not perform spoof check for 82598 */
6218 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6219 return;
6220
6221 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6222
6223 /*
6224 * ssvpc register is cleared on read, if zero then no
6225 * spoofed packets in the last interval.
6226 */
6227 if (!ssvpc)
6228 return;
6229
6230 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6231}
6232
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006233/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006234 * ixgbe_watchdog_subtask - check and bring link up
6235 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006236 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006237static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006238{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006239 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006240 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6241 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006242 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006243
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006244 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006245
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006246 if (adapter->link_up)
6247 ixgbe_watchdog_link_is_up(adapter);
6248 else
6249 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006250
Greg Rosea985b6c32010-11-18 03:02:52 +00006251 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006252 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006253
6254 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006255}
6256
Alexander Duyck70864002011-04-27 09:13:56 +00006257/**
6258 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6259 * @adapter - the ixgbe adapter structure
6260 **/
6261static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6262{
6263 struct ixgbe_hw *hw = &adapter->hw;
6264 s32 err;
6265
6266 /* not searching for SFP so there is nothing to do here */
6267 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6268 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6269 return;
6270
6271 /* someone else is in init, wait until next service event */
6272 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6273 return;
6274
6275 err = hw->phy.ops.identify_sfp(hw);
6276 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6277 goto sfp_out;
6278
6279 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6280 /* If no cable is present, then we need to reset
6281 * the next time we find a good cable. */
6282 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6283 }
6284
6285 /* exit on error */
6286 if (err)
6287 goto sfp_out;
6288
6289 /* exit if reset not needed */
6290 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6291 goto sfp_out;
6292
6293 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6294
6295 /*
6296 * A module may be identified correctly, but the EEPROM may not have
6297 * support for that module. setup_sfp() will fail in that case, so
6298 * we should not allow that module to load.
6299 */
6300 if (hw->mac.type == ixgbe_mac_82598EB)
6301 err = hw->phy.ops.reset(hw);
6302 else
6303 err = hw->mac.ops.setup_sfp(hw);
6304
6305 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6306 goto sfp_out;
6307
6308 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6309 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6310
6311sfp_out:
6312 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6313
6314 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6315 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6316 e_dev_err("failed to initialize because an unsupported "
6317 "SFP+ module type was detected.\n");
6318 e_dev_err("Reload the driver after installing a "
6319 "supported module.\n");
6320 unregister_netdev(adapter->netdev);
6321 }
6322}
6323
6324/**
6325 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6326 * @adapter - the ixgbe adapter structure
6327 **/
6328static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6329{
6330 struct ixgbe_hw *hw = &adapter->hw;
6331 u32 autoneg;
6332 bool negotiation;
6333
6334 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6335 return;
6336
6337 /* someone else is in init, wait until next service event */
6338 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6339 return;
6340
6341 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6342
6343 autoneg = hw->phy.autoneg_advertised;
6344 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6345 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006346 if (hw->mac.ops.setup_link)
6347 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6348
6349 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6350 adapter->link_check_timeout = jiffies;
6351 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6352}
6353
Greg Rose83c61fa2011-09-07 05:59:35 +00006354#ifdef CONFIG_PCI_IOV
6355static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6356{
6357 int vf;
6358 struct ixgbe_hw *hw = &adapter->hw;
6359 struct net_device *netdev = adapter->netdev;
6360 u32 gpc;
6361 u32 ciaa, ciad;
6362
6363 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6364 if (gpc) /* If incrementing then no need for the check below */
6365 return;
6366 /*
6367 * Check to see if a bad DMA write target from an errant or
6368 * malicious VF has caused a PCIe error. If so then we can
6369 * issue a VFLR to the offending VF(s) and then resume without
6370 * requesting a full slot reset.
6371 */
6372
6373 for (vf = 0; vf < adapter->num_vfs; vf++) {
6374 ciaa = (vf << 16) | 0x80000000;
6375 /* 32 bit read so align, we really want status at offset 6 */
6376 ciaa |= PCI_COMMAND;
6377 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6378 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6379 ciaa &= 0x7FFFFFFF;
6380 /* disable debug mode asap after reading data */
6381 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6382 /* Get the upper 16 bits which will be the PCI status reg */
6383 ciad >>= 16;
6384 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6385 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6386 /* Issue VFLR */
6387 ciaa = (vf << 16) | 0x80000000;
6388 ciaa |= 0xA8;
6389 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6390 ciad = 0x00008000; /* VFLR */
6391 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6392 ciaa &= 0x7FFFFFFF;
6393 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6394 }
6395 }
6396}
6397
6398#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006399/**
6400 * ixgbe_service_timer - Timer Call-back
6401 * @data: pointer to adapter cast into an unsigned long
6402 **/
6403static void ixgbe_service_timer(unsigned long data)
6404{
6405 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6406 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006407 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006408
Greg Rose83c61fa2011-09-07 05:59:35 +00006409#ifdef CONFIG_PCI_IOV
6410 ready = false;
6411
6412 /*
6413 * don't bother with SR-IOV VF DMA hang check if there are
6414 * no VFs or the link is down
6415 */
6416 if (!adapter->num_vfs ||
6417 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6418 ready = true;
6419 goto normal_timer_service;
6420 }
6421
6422 /* If we have VFs allocated then we must check for DMA hangs */
6423 ixgbe_check_for_bad_vf(adapter);
6424 next_event_offset = HZ / 50;
6425 adapter->timer_event_accumulator++;
6426
6427 if (adapter->timer_event_accumulator >= 100) {
6428 ready = true;
6429 adapter->timer_event_accumulator = 0;
6430 }
6431
6432 goto schedule_event;
6433
6434normal_timer_service:
6435#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006436 /* poll faster when waiting for link */
6437 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6438 next_event_offset = HZ / 10;
6439 else
6440 next_event_offset = HZ * 2;
6441
Greg Rose83c61fa2011-09-07 05:59:35 +00006442#ifdef CONFIG_PCI_IOV
6443schedule_event:
6444#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006445 /* Reset the timer */
6446 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6447
Greg Rose83c61fa2011-09-07 05:59:35 +00006448 if (ready)
6449 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006450}
6451
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006452static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6453{
6454 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6455 return;
6456
6457 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6458
6459 /* If we're already down or resetting, just bail */
6460 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6461 test_bit(__IXGBE_RESETTING, &adapter->state))
6462 return;
6463
6464 ixgbe_dump(adapter);
6465 netdev_err(adapter->netdev, "Reset adapter\n");
6466 adapter->tx_timeout_count++;
6467
6468 ixgbe_reinit_locked(adapter);
6469}
6470
Alexander Duyck70864002011-04-27 09:13:56 +00006471/**
6472 * ixgbe_service_task - manages and runs subtasks
6473 * @work: pointer to work_struct containing our data
6474 **/
6475static void ixgbe_service_task(struct work_struct *work)
6476{
6477 struct ixgbe_adapter *adapter = container_of(work,
6478 struct ixgbe_adapter,
6479 service_task);
6480
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006481 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006482 ixgbe_sfp_detection_subtask(adapter);
6483 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006484 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006485 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006486 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006487 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006488
6489 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006490}
6491
Alexander Duyck897ab152011-05-27 05:31:47 +00006492void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6493 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006494{
6495 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006496 u16 i = tx_ring->next_to_use;
6497
Alexander Duycke4f74022012-01-31 02:59:44 +00006498 context_desc = IXGBE_TX_CTXTDESC(tx_ring, i);
Alexander Duyck897ab152011-05-27 05:31:47 +00006499
6500 i++;
6501 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6502
6503 /* set bits to identify this as an advanced context descriptor */
6504 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6505
6506 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6507 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6508 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6509 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6510}
6511
6512static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6513 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6514{
Auke Kok9a799d72007-09-15 14:07:45 -07006515 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006516 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006517 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006518
Alexander Duyck897ab152011-05-27 05:31:47 +00006519 if (!skb_is_gso(skb))
6520 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006521
Alexander Duyck897ab152011-05-27 05:31:47 +00006522 if (skb_header_cloned(skb)) {
6523 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6524 if (err)
6525 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006526 }
6527
Alexander Duyck897ab152011-05-27 05:31:47 +00006528 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6529 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6530
6531 if (protocol == __constant_htons(ETH_P_IP)) {
6532 struct iphdr *iph = ip_hdr(skb);
6533 iph->tot_len = 0;
6534 iph->check = 0;
6535 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6536 iph->daddr, 0,
6537 IPPROTO_TCP,
6538 0);
6539 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6540 } else if (skb_is_gso_v6(skb)) {
6541 ipv6_hdr(skb)->payload_len = 0;
6542 tcp_hdr(skb)->check =
6543 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6544 &ipv6_hdr(skb)->daddr,
6545 0, IPPROTO_TCP, 0);
6546 }
6547
6548 l4len = tcp_hdrlen(skb);
6549 *hdr_len = skb_transport_offset(skb) + l4len;
6550
6551 /* mss_l4len_id: use 1 as index for TSO */
6552 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6553 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6554 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6555
6556 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6557 vlan_macip_lens = skb_network_header_len(skb);
6558 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6559 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6560
6561 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6562 mss_l4len_idx);
6563
6564 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006565}
6566
Alexander Duyck897ab152011-05-27 05:31:47 +00006567static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006568 struct sk_buff *skb, u32 tx_flags,
6569 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006570{
Alexander Duyck897ab152011-05-27 05:31:47 +00006571 u32 vlan_macip_lens = 0;
6572 u32 mss_l4len_idx = 0;
6573 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006574
Alexander Duyck897ab152011-05-27 05:31:47 +00006575 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006576 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6577 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006578 return false;
6579 } else {
6580 u8 l4_hdr = 0;
6581 switch (protocol) {
6582 case __constant_htons(ETH_P_IP):
6583 vlan_macip_lens |= skb_network_header_len(skb);
6584 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6585 l4_hdr = ip_hdr(skb)->protocol;
6586 break;
6587 case __constant_htons(ETH_P_IPV6):
6588 vlan_macip_lens |= skb_network_header_len(skb);
6589 l4_hdr = ipv6_hdr(skb)->nexthdr;
6590 break;
6591 default:
6592 if (unlikely(net_ratelimit())) {
6593 dev_warn(tx_ring->dev,
6594 "partial checksum but proto=%x!\n",
6595 skb->protocol);
6596 }
6597 break;
6598 }
Auke Kok9a799d72007-09-15 14:07:45 -07006599
Alexander Duyck897ab152011-05-27 05:31:47 +00006600 switch (l4_hdr) {
6601 case IPPROTO_TCP:
6602 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6603 mss_l4len_idx = tcp_hdrlen(skb) <<
6604 IXGBE_ADVTXD_L4LEN_SHIFT;
6605 break;
6606 case IPPROTO_SCTP:
6607 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6608 mss_l4len_idx = sizeof(struct sctphdr) <<
6609 IXGBE_ADVTXD_L4LEN_SHIFT;
6610 break;
6611 case IPPROTO_UDP:
6612 mss_l4len_idx = sizeof(struct udphdr) <<
6613 IXGBE_ADVTXD_L4LEN_SHIFT;
6614 break;
6615 default:
6616 if (unlikely(net_ratelimit())) {
6617 dev_warn(tx_ring->dev,
6618 "partial checksum but l4 proto=%x!\n",
6619 skb->protocol);
6620 }
6621 break;
6622 }
Auke Kok9a799d72007-09-15 14:07:45 -07006623 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006624
Alexander Duyck897ab152011-05-27 05:31:47 +00006625 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6626 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6627
6628 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6629 type_tucmd, mss_l4len_idx);
6630
6631 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006632}
6633
Alexander Duyckd3d00232011-07-15 02:31:25 +00006634static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6635{
6636 /* set type for advanced descriptor with frame checksum insertion */
6637 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6638 IXGBE_ADVTXD_DCMD_IFCS |
6639 IXGBE_ADVTXD_DCMD_DEXT);
6640
6641 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006642 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006643 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6644
6645 /* set segmentation enable bits for TSO/FSO */
6646#ifdef IXGBE_FCOE
6647 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6648#else
6649 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6650#endif
6651 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6652
6653 return cmd_type;
6654}
6655
6656static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6657{
6658 __le32 olinfo_status =
6659 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6660
6661 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6662 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6663 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6664 /* enble IPv4 checksum for TSO */
6665 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6666 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6667 }
6668
6669 /* enable L4 checksum for TSO and TX checksum offload */
6670 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6671 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6672
6673#ifdef IXGBE_FCOE
6674 /* use index 1 context for FCOE/FSO */
6675 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6676 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6677 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6678
6679#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006680 /*
6681 * Check Context must be set if Tx switch is enabled, which it
6682 * always is for case where virtual functions are running
6683 */
6684 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6685 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6686
Alexander Duyckd3d00232011-07-15 02:31:25 +00006687 return olinfo_status;
6688}
6689
6690#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6691 IXGBE_TXD_CMD_RS)
6692
6693static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6694 struct sk_buff *skb,
6695 struct ixgbe_tx_buffer *first,
6696 u32 tx_flags,
6697 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006698{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006699 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006700 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006701 union ixgbe_adv_tx_desc *tx_desc;
6702 dma_addr_t dma;
6703 __le32 cmd_type, olinfo_status;
6704 struct skb_frag_struct *frag;
6705 unsigned int f = 0;
6706 unsigned int data_len = skb->data_len;
6707 unsigned int size = skb_headlen(skb);
6708 u32 offset = 0;
6709 u32 paylen = skb->len - hdr_len;
6710 u16 i = tx_ring->next_to_use;
6711 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006712
Alexander Duyckd3d00232011-07-15 02:31:25 +00006713#ifdef IXGBE_FCOE
6714 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6715 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6716 data_len -= sizeof(struct fcoe_crc_eof);
6717 } else {
6718 size -= sizeof(struct fcoe_crc_eof) - data_len;
6719 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006720 }
Auke Kok9a799d72007-09-15 14:07:45 -07006721 }
6722
Alexander Duyckd3d00232011-07-15 02:31:25 +00006723#endif
6724 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6725 if (dma_mapping_error(dev, dma))
6726 goto dma_error;
6727
6728 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6729 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6730
Alexander Duycke4f74022012-01-31 02:59:44 +00006731 tx_desc = IXGBE_TX_DESC(tx_ring, i);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006732
6733 for (;;) {
6734 while (size > IXGBE_MAX_DATA_PER_TXD) {
6735 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6736 tx_desc->read.cmd_type_len =
6737 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6738 tx_desc->read.olinfo_status = olinfo_status;
6739
6740 offset += IXGBE_MAX_DATA_PER_TXD;
6741 size -= IXGBE_MAX_DATA_PER_TXD;
6742
6743 tx_desc++;
6744 i++;
6745 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006746 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006747 i = 0;
6748 }
6749 }
6750
6751 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6752 tx_buffer_info->length = offset + size;
6753 tx_buffer_info->tx_flags = tx_flags;
6754 tx_buffer_info->dma = dma;
6755
6756 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6757 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6758 tx_desc->read.olinfo_status = olinfo_status;
6759
6760 if (!data_len)
6761 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006762
6763 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006764#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006765 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006766#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006767 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006768#endif
6769 data_len -= size;
6770 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006771
Alexander Duyckd3d00232011-07-15 02:31:25 +00006772 offset = 0;
6773 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006774
Ian Campbell877749b2011-08-29 23:18:26 +00006775 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006776 if (dma_mapping_error(dev, dma))
6777 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006778
Alexander Duyckd3d00232011-07-15 02:31:25 +00006779 tx_desc++;
6780 i++;
6781 if (i == tx_ring->count) {
Alexander Duycke4f74022012-01-31 02:59:44 +00006782 tx_desc = IXGBE_TX_DESC(tx_ring, 0);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006783 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006784 }
6785 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006786
Alexander Duyckd3d00232011-07-15 02:31:25 +00006787 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6788
6789 i++;
6790 if (i == tx_ring->count)
6791 i = 0;
6792
6793 tx_ring->next_to_use = i;
6794
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006795 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6796 gso_segs = skb_shinfo(skb)->gso_segs;
6797#ifdef IXGBE_FCOE
6798 /* adjust for FCoE Sequence Offload */
6799 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6800 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6801 skb_shinfo(skb)->gso_size);
6802#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006803 else
6804 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006805
6806 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006807 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6808 tx_buffer_info->gso_segs = gso_segs;
6809 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006810
Alexander Duyckd3d00232011-07-15 02:31:25 +00006811 /* set the timestamp */
6812 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006813
6814 /*
6815 * Force memory writes to complete before letting h/w
6816 * know there are new descriptors to fetch. (Only
6817 * applicable for weak-ordered memory model archs,
6818 * such as IA-64).
6819 */
6820 wmb();
6821
Alexander Duyckd3d00232011-07-15 02:31:25 +00006822 /* set next_to_watch value indicating a packet is present */
6823 first->next_to_watch = tx_desc;
6824
6825 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006826 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006827
6828 return;
6829dma_error:
6830 dev_err(dev, "TX DMA map failed\n");
6831
6832 /* clear dma mappings for failed tx_buffer_info map */
6833 for (;;) {
6834 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6835 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6836 if (tx_buffer_info == first)
6837 break;
6838 if (i == 0)
6839 i = tx_ring->count;
6840 i--;
6841 }
6842
6843 dev_kfree_skb_any(skb);
6844
6845 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006846}
6847
Alexander Duyck69830522011-01-06 14:29:58 +00006848static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6849 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006850{
Alexander Duyck69830522011-01-06 14:29:58 +00006851 struct ixgbe_q_vector *q_vector = ring->q_vector;
6852 union ixgbe_atr_hash_dword input = { .dword = 0 };
6853 union ixgbe_atr_hash_dword common = { .dword = 0 };
6854 union {
6855 unsigned char *network;
6856 struct iphdr *ipv4;
6857 struct ipv6hdr *ipv6;
6858 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006859 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006860 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006861
Alexander Duyck69830522011-01-06 14:29:58 +00006862 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6863 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006864 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006865
Alexander Duyck69830522011-01-06 14:29:58 +00006866 /* do nothing if sampling is disabled */
6867 if (!ring->atr_sample_rate)
6868 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006869
Alexander Duyck69830522011-01-06 14:29:58 +00006870 ring->atr_count++;
6871
6872 /* snag network header to get L4 type and address */
6873 hdr.network = skb_network_header(skb);
6874
6875 /* Currently only IPv4/IPv6 with TCP is supported */
6876 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6877 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6878 (protocol != __constant_htons(ETH_P_IP) ||
6879 hdr.ipv4->protocol != IPPROTO_TCP))
6880 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006881
6882 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006883
Alexander Duyck66f32a82011-06-29 05:43:22 +00006884 /* skip this packet since it is invalid or the socket is closing */
6885 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006886 return;
6887
6888 /* sample on all syn packets or once every atr sample count */
6889 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6890 return;
6891
6892 /* reset sample count */
6893 ring->atr_count = 0;
6894
6895 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6896
6897 /*
6898 * src and dst are inverted, think how the receiver sees them
6899 *
6900 * The input is broken into two sections, a non-compressed section
6901 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6902 * is XORed together and stored in the compressed dword.
6903 */
6904 input.formatted.vlan_id = vlan_id;
6905
6906 /*
6907 * since src port and flex bytes occupy the same word XOR them together
6908 * and write the value to source port portion of compressed dword
6909 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006910 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006911 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6912 else
6913 common.port.src ^= th->dest ^ protocol;
6914 common.port.dst ^= th->source;
6915
6916 if (protocol == __constant_htons(ETH_P_IP)) {
6917 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6918 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6919 } else {
6920 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6921 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6922 hdr.ipv6->saddr.s6_addr32[1] ^
6923 hdr.ipv6->saddr.s6_addr32[2] ^
6924 hdr.ipv6->saddr.s6_addr32[3] ^
6925 hdr.ipv6->daddr.s6_addr32[0] ^
6926 hdr.ipv6->daddr.s6_addr32[1] ^
6927 hdr.ipv6->daddr.s6_addr32[2] ^
6928 hdr.ipv6->daddr.s6_addr32[3];
6929 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006930
6931 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006932 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6933 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006934}
6935
Alexander Duyck63544e92011-05-27 05:31:42 +00006936static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006937{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006938 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006939 /* Herbert's original patch had:
6940 * smp_mb__after_netif_stop_queue();
6941 * but since that doesn't exist yet, just open code it. */
6942 smp_mb();
6943
6944 /* We need to check again in a case another CPU has just
6945 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006946 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006947 return -EBUSY;
6948
6949 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006950 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006951 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006952 return 0;
6953}
6954
Alexander Duyck82d4e462011-06-11 01:44:58 +00006955static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006956{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006957 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006958 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006959 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006960}
6961
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006962static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6963{
6964 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006965 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6966 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006967#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006968 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006969
John Fastabende5b64632011-03-08 03:44:52 +00006970 if (((protocol == htons(ETH_P_FCOE)) ||
6971 (protocol == htons(ETH_P_FIP))) &&
6972 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6973 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6974 txq += adapter->ring_feature[RING_F_FCOE].mask;
6975 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006976 }
6977#endif
6978
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006979 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6980 while (unlikely(txq >= dev->real_num_tx_queues))
6981 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006982 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006983 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006984
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006985 return skb_tx_hash(dev, skb);
6986}
6987
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006988netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006989 struct ixgbe_adapter *adapter,
6990 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006991{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006992 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006993 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006994 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006995#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6996 unsigned short f;
6997#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006998 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006999 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00007000 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00007001
Alexander Duycka535c302011-05-27 05:31:52 +00007002 /*
7003 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
Alexander Duyck24ddd962012-02-10 02:08:32 +00007004 * + 1 desc for skb_headlen/IXGBE_MAX_DATA_PER_TXD,
Alexander Duycka535c302011-05-27 05:31:52 +00007005 * + 2 desc gap to keep tail from touching head,
7006 * + 1 desc for context descriptor,
7007 * otherwise try next time
7008 */
7009#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
7010 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
7011 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
7012#else
7013 count += skb_shinfo(skb)->nr_frags;
7014#endif
7015 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
7016 tx_ring->tx_stats.tx_busy++;
7017 return NETDEV_TX_BUSY;
7018 }
7019
Alexander Duyck66f32a82011-06-29 05:43:22 +00007020 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007021 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007022 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7023 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7024 /* else if it is a SW VLAN check the next protocol and store the tag */
7025 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7026 struct vlan_hdr *vhdr, _vhdr;
7027 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7028 if (!vhdr)
7029 goto out_drop;
7030
7031 protocol = vhdr->h_vlan_encapsulated_proto;
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007032 tx_flags |= ntohs(vhdr->h_vlan_TCI) <<
7033 IXGBE_TX_FLAGS_VLAN_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007034 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007035 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007036
Alexander Duyck9e0c5642012-02-08 07:49:33 +00007037#ifdef CONFIG_PCI_IOV
7038 /*
7039 * Use the l2switch_enable flag - would be false if the DMA
7040 * Tx switch had been disabled.
7041 */
7042 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7043 tx_flags |= IXGBE_TX_FLAGS_TXSW;
7044
7045#endif
John Fastabend32701dc2011-09-27 03:51:56 +00007046 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007047 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007048 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7049 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007050 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007051 tx_flags |= (skb->priority & 0x7) <<
7052 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007053 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7054 struct vlan_ethhdr *vhdr;
7055 if (skb_header_cloned(skb) &&
7056 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7057 goto out_drop;
7058 vhdr = (struct vlan_ethhdr *)skb->data;
7059 vhdr->h_vlan_TCI = htons(tx_flags >>
7060 IXGBE_TX_FLAGS_VLAN_SHIFT);
7061 } else {
7062 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7063 }
7064 }
Alexander Duycka535c302011-05-27 05:31:52 +00007065
Alexander Duycka535c302011-05-27 05:31:52 +00007066 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007067 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007068
Yi Zoueacd73f2009-05-13 13:11:06 +00007069#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007070 /* setup tx offload for FCoE */
7071 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7072 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007073 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7074 if (tso < 0)
7075 goto out_drop;
7076 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007077 tx_flags |= IXGBE_TX_FLAGS_FSO |
7078 IXGBE_TX_FLAGS_FCOE;
7079 else
7080 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007081
Alexander Duyck66f32a82011-06-29 05:43:22 +00007082 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007083 }
Auke Kok9a799d72007-09-15 14:07:45 -07007084
Auke Kok9a799d72007-09-15 14:07:45 -07007085#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007086 /* setup IPv4/IPv6 offloads */
7087 if (protocol == __constant_htons(ETH_P_IP))
7088 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007089
Alexander Duyck66f32a82011-06-29 05:43:22 +00007090 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7091 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007092 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007093 else if (tso)
7094 tx_flags |= IXGBE_TX_FLAGS_TSO;
7095 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7096 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7097
7098 /* add the ATR filter if ATR is on */
7099 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7100 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7101
7102#ifdef IXGBE_FCOE
7103xmit_fcoe:
7104#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007105 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7106
7107 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007108
7109 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007110
7111out_drop:
7112 dev_kfree_skb_any(skb);
7113 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007114}
7115
7116static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7117{
7118 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7119 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007120
Auke Kok9a799d72007-09-15 14:07:45 -07007121 tx_ring = adapter->tx_ring[skb->queue_mapping];
7122 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7123}
7124
7125/**
7126 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007127 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007128 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007129 *
Auke Kok9a799d72007-09-15 14:07:45 -07007130 * Returns 0 on success, negative on failure
7131 **/
7132static int ixgbe_set_mac(struct net_device *netdev, void *p)
7133{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007134 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7135 struct ixgbe_hw *hw = &adapter->hw;
7136 struct sockaddr *addr = p;
7137
7138 if (!is_valid_ether_addr(addr->sa_data))
7139 return -EADDRNOTAVAIL;
7140
7141 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7142 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7143
7144 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7145 IXGBE_RAH_AV);
7146
7147 return 0;
7148}
7149
7150static int
7151ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7152{
7153 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7154 struct ixgbe_hw *hw = &adapter->hw;
7155 u16 value;
7156 int rc;
7157
7158 if (prtad != hw->phy.mdio.prtad)
7159 return -EINVAL;
7160 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7161 if (!rc)
7162 rc = value;
7163 return rc;
7164}
7165
7166static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7167 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007168{
7169 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007170 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007171
7172 if (prtad != hw->phy.mdio.prtad)
7173 return -EINVAL;
7174 return hw->phy.ops.write_reg(hw, addr, devad, value);
7175}
7176
7177static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7178{
7179 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7180
7181 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7182}
7183
7184/**
7185 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7186 * netdev->dev_addrs
7187 * @netdev: network interface device structure
7188 *
7189 * Returns non-zero on failure
7190 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007191static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007192{
7193 int err = 0;
7194 struct ixgbe_adapter *adapter = netdev_priv(dev);
7195 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7196
7197 if (is_valid_ether_addr(mac->san_addr)) {
7198 rtnl_lock();
7199 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7200 rtnl_unlock();
7201 }
7202 return err;
7203}
7204
7205/**
7206 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7207 * netdev->dev_addrs
7208 * @netdev: network interface device structure
7209 *
Auke Kok9a799d72007-09-15 14:07:45 -07007210 * Returns non-zero on failure
7211 **/
7212static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7213{
7214 int err = 0;
7215 struct ixgbe_adapter *adapter = netdev_priv(dev);
7216 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7217
7218 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007219 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007220 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007221 rtnl_unlock();
7222 }
7223 return err;
7224}
Auke Kok9a799d72007-09-15 14:07:45 -07007225
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007226#ifdef CONFIG_NET_POLL_CONTROLLER
7227/*
7228 * Polling 'interrupt' - used by things like netconsole to send skbs
7229 * without having to re-enable interrupts. It's not called while
7230 * the interrupt routine is executing.
7231 */
7232static void ixgbe_netpoll(struct net_device *netdev)
7233{
7234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007235 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007236
7237 /* if interface is down do nothing */
7238 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007239 return;
7240
7241 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007242 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007243 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007244 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007245 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007246 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007247 }
7248 } else {
7249 ixgbe_intr(adapter->pdev->irq, netdev);
7250 }
7251 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7252}
7253#endif
7254
Eric Dumazetde1036b2010-10-20 23:00:04 +00007255static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7256 struct rtnl_link_stats64 *stats)
7257{
7258 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7259 int i;
7260
Eric Dumazet1a515022010-11-16 19:26:42 -08007261 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007262 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007263 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007264 u64 bytes, packets;
7265 unsigned int start;
7266
Eric Dumazet1a515022010-11-16 19:26:42 -08007267 if (ring) {
7268 do {
7269 start = u64_stats_fetch_begin_bh(&ring->syncp);
7270 packets = ring->stats.packets;
7271 bytes = ring->stats.bytes;
7272 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7273 stats->rx_packets += packets;
7274 stats->rx_bytes += bytes;
7275 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007276 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007277
7278 for (i = 0; i < adapter->num_tx_queues; i++) {
7279 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7280 u64 bytes, packets;
7281 unsigned int start;
7282
7283 if (ring) {
7284 do {
7285 start = u64_stats_fetch_begin_bh(&ring->syncp);
7286 packets = ring->stats.packets;
7287 bytes = ring->stats.bytes;
7288 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7289 stats->tx_packets += packets;
7290 stats->tx_bytes += bytes;
7291 }
7292 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007293 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007294 /* following stats updated by ixgbe_watchdog_task() */
7295 stats->multicast = netdev->stats.multicast;
7296 stats->rx_errors = netdev->stats.rx_errors;
7297 stats->rx_length_errors = netdev->stats.rx_length_errors;
7298 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7299 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7300 return stats;
7301}
7302
John Fastabend8b1c0b22011-05-03 02:26:48 +00007303/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7304 * #adapter: pointer to ixgbe_adapter
7305 * @tc: number of traffic classes currently enabled
7306 *
7307 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7308 * 802.1Q priority maps to a packet buffer that exists.
7309 */
7310static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7311{
7312 struct ixgbe_hw *hw = &adapter->hw;
7313 u32 reg, rsave;
7314 int i;
7315
7316 /* 82598 have a static priority to TC mapping that can not
7317 * be changed so no validation is needed.
7318 */
7319 if (hw->mac.type == ixgbe_mac_82598EB)
7320 return;
7321
7322 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7323 rsave = reg;
7324
7325 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7326 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7327
7328 /* If up2tc is out of bounds default to zero */
7329 if (up2tc > tc)
7330 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7331 }
7332
7333 if (reg != rsave)
7334 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7335
7336 return;
7337}
7338
7339
7340/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7341 * classes.
7342 *
7343 * @netdev: net device to configure
7344 * @tc: number of traffic classes to enable
7345 */
7346int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7347{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007348 struct ixgbe_adapter *adapter = netdev_priv(dev);
7349 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007350
John Fastabende7589ea2011-07-18 22:38:36 +00007351 /* Multiple traffic classes requires multiple queues */
7352 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7353 e_err(drv, "Enable failed, needs MSI-X\n");
7354 return -EINVAL;
7355 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007356
7357 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007358 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007359 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7360 return -EINVAL;
7361
7362 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007363 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007364 * hardware is not flexible enough to do this dynamically.
7365 */
7366 if (netif_running(dev))
7367 ixgbe_close(dev);
7368 ixgbe_clear_interrupt_scheme(adapter);
7369
John Fastabende7589ea2011-07-18 22:38:36 +00007370 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007371 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007372 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7373
7374 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7375 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7376
7377 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7378 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7379 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007380 netdev_reset_tc(dev);
7381
John Fastabende7589ea2011-07-18 22:38:36 +00007382 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7383
7384 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7385 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7386
7387 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7388 adapter->dcb_cfg.pfc_mode_enable = false;
7389 }
7390
John Fastabend8b1c0b22011-05-03 02:26:48 +00007391 ixgbe_init_interrupt_scheme(adapter);
7392 ixgbe_validate_rtr(adapter, tc);
7393 if (netif_running(dev))
7394 ixgbe_open(dev);
7395
7396 return 0;
7397}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007398
Don Skidmore082757a2011-07-21 05:55:00 +00007399void ixgbe_do_reset(struct net_device *netdev)
7400{
7401 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7402
7403 if (netif_running(netdev))
7404 ixgbe_reinit_locked(adapter);
7405 else
7406 ixgbe_reset(adapter);
7407}
7408
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007409static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7410 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007411{
7412 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7413
7414#ifdef CONFIG_DCB
7415 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7416 data &= ~NETIF_F_HW_VLAN_RX;
7417#endif
7418
7419 /* return error if RXHASH is being enabled when RSS is not supported */
7420 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7421 data &= ~NETIF_F_RXHASH;
7422
7423 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7424 if (!(data & NETIF_F_RXCSUM))
7425 data &= ~NETIF_F_LRO;
7426
7427 /* Turn off LRO if not RSC capable or invalid ITR settings */
7428 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7429 data &= ~NETIF_F_LRO;
7430 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7431 (adapter->rx_itr_setting != 1 &&
7432 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7433 data &= ~NETIF_F_LRO;
7434 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7435 }
7436
7437 return data;
7438}
7439
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007440static int ixgbe_set_features(struct net_device *netdev,
7441 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007442{
7443 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7444 bool need_reset = false;
7445
Don Skidmore082757a2011-07-21 05:55:00 +00007446 /* Make sure RSC matches LRO, reset if change */
7447 if (!!(data & NETIF_F_LRO) !=
7448 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7449 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7450 switch (adapter->hw.mac.type) {
7451 case ixgbe_mac_X540:
7452 case ixgbe_mac_82599EB:
7453 need_reset = true;
7454 break;
7455 default:
7456 break;
7457 }
7458 }
7459
7460 /*
7461 * Check if Flow Director n-tuple support was enabled or disabled. If
7462 * the state changed, we need to reset.
7463 */
7464 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7465 /* turn off ATR, enable perfect filters and reset */
7466 if (data & NETIF_F_NTUPLE) {
7467 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7468 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7469 need_reset = true;
7470 }
7471 } else if (!(data & NETIF_F_NTUPLE)) {
7472 /* turn off Flow Director, set ATR and reset */
7473 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7474 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7475 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7476 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7477 need_reset = true;
7478 }
7479
7480 if (need_reset)
7481 ixgbe_do_reset(netdev);
7482
7483 return 0;
7484
7485}
7486
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007487static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007488 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007489 .ndo_stop = ixgbe_close,
7490 .ndo_start_xmit = ixgbe_xmit_frame,
7491 .ndo_select_queue = ixgbe_select_queue,
7492 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007493 .ndo_validate_addr = eth_validate_addr,
7494 .ndo_set_mac_address = ixgbe_set_mac,
7495 .ndo_change_mtu = ixgbe_change_mtu,
7496 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007497 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7498 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007499 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007500 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7501 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7502 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007503 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007504 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007505 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007506 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007507#ifdef CONFIG_NET_POLL_CONTROLLER
7508 .ndo_poll_controller = ixgbe_netpoll,
7509#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007510#ifdef IXGBE_FCOE
7511 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007512 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007513 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007514 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7515 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007516 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007517 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007518#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007519 .ndo_set_features = ixgbe_set_features,
7520 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007521};
7522
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007523static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7524 const struct ixgbe_info *ii)
7525{
7526#ifdef CONFIG_PCI_IOV
7527 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007528
Greg Rosec6bda302011-08-24 02:37:55 +00007529 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007530 return;
7531
7532 /* The 82599 supports up to 64 VFs per physical function
7533 * but this implementation limits allocation to 63 so that
7534 * basic networking resources are still available to the
7535 * physical function
7536 */
7537 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007538 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007539#endif /* CONFIG_PCI_IOV */
7540}
7541
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007542/**
Auke Kok9a799d72007-09-15 14:07:45 -07007543 * ixgbe_probe - Device Initialization Routine
7544 * @pdev: PCI device information struct
7545 * @ent: entry in ixgbe_pci_tbl
7546 *
7547 * Returns 0 on success, negative on failure
7548 *
7549 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7550 * The OS initialization, configuring of the adapter private structure,
7551 * and a hardware reset occur.
7552 **/
7553static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007554 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007555{
7556 struct net_device *netdev;
7557 struct ixgbe_adapter *adapter = NULL;
7558 struct ixgbe_hw *hw;
7559 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007560 static int cards_found;
7561 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007562 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007563 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007564#ifdef IXGBE_FCOE
7565 u16 device_caps;
7566#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007567 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007568 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007569
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007570 /* Catch broken hardware that put the wrong VF device ID in
7571 * the PCIe SR-IOV capability.
7572 */
7573 if (pdev->is_virtfn) {
7574 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7575 pci_name(pdev), pdev->vendor, pdev->device);
7576 return -EINVAL;
7577 }
7578
gouji-new9ce77662009-05-06 10:44:45 +00007579 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007580 if (err)
7581 return err;
7582
Nick Nunley1b507732010-04-27 13:10:27 +00007583 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7584 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007585 pci_using_dac = 1;
7586 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007587 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007588 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007589 err = dma_set_coherent_mask(&pdev->dev,
7590 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007591 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007592 dev_err(&pdev->dev,
7593 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007594 goto err_dma;
7595 }
7596 }
7597 pci_using_dac = 0;
7598 }
7599
gouji-new9ce77662009-05-06 10:44:45 +00007600 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007601 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007602 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007603 dev_err(&pdev->dev,
7604 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007605 goto err_pci_reg;
7606 }
7607
Frans Pop19d5afd2009-10-02 10:04:12 -07007608 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007609
Auke Kok9a799d72007-09-15 14:07:45 -07007610 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007611 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007612
John Fastabende901acd2011-04-26 07:26:08 +00007613#ifdef CONFIG_IXGBE_DCB
7614 indices *= MAX_TRAFFIC_CLASS;
7615#endif
7616
John Fastabendc85a2612010-02-25 23:15:21 +00007617 if (ii->mac == ixgbe_mac_82598EB)
7618 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7619 else
7620 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7621
John Fastabende901acd2011-04-26 07:26:08 +00007622#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007623 indices += min_t(unsigned int, num_possible_cpus(),
7624 IXGBE_MAX_FCOE_INDICES);
7625#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007626 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007627 if (!netdev) {
7628 err = -ENOMEM;
7629 goto err_alloc_etherdev;
7630 }
7631
Auke Kok9a799d72007-09-15 14:07:45 -07007632 SET_NETDEV_DEV(netdev, &pdev->dev);
7633
Auke Kok9a799d72007-09-15 14:07:45 -07007634 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007635 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007636
7637 adapter->netdev = netdev;
7638 adapter->pdev = pdev;
7639 hw = &adapter->hw;
7640 hw->back = adapter;
7641 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7642
Jeff Kirsher05857982008-09-11 19:57:00 -07007643 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007644 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007645 if (!hw->hw_addr) {
7646 err = -EIO;
7647 goto err_ioremap;
7648 }
7649
7650 for (i = 1; i <= 5; i++) {
7651 if (pci_resource_len(pdev, i) == 0)
7652 continue;
7653 }
7654
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007655 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007656 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007657 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007658 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007659
Auke Kok9a799d72007-09-15 14:07:45 -07007660 adapter->bd_number = cards_found;
7661
Auke Kok9a799d72007-09-15 14:07:45 -07007662 /* Setup hw api */
7663 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007664 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007665
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007666 /* EEPROM */
7667 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7668 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7669 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7670 if (!(eec & (1 << 8)))
7671 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7672
7673 /* PHY */
7674 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007675 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007676 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7677 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7678 hw->phy.mdio.mmds = 0;
7679 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7680 hw->phy.mdio.dev = netdev;
7681 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7682 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007683
Don Skidmore8ca783a2009-05-26 20:40:47 -07007684 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007685
7686 /* setup the private structure */
7687 err = ixgbe_sw_init(adapter);
7688 if (err)
7689 goto err_sw_init;
7690
Don Skidmoree86bff02010-02-11 04:14:08 +00007691 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007692 switch (adapter->hw.mac.type) {
7693 case ixgbe_mac_82599EB:
7694 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007695 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007696 break;
7697 default:
7698 break;
7699 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007700
Don Skidmorebf069c92009-05-07 10:39:54 +00007701 /*
7702 * If there is a fan on this device and it has failed log the
7703 * failure.
7704 */
7705 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7706 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7707 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007708 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007709 }
7710
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007711 if (allow_unsupported_sfp)
7712 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7713
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007714 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007715 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007716 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007717 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007718 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7719 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007720 err = 0;
7721 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007722 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007723 "module type was detected.\n");
7724 e_dev_err("Reload the driver after installing a supported "
7725 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007726 goto err_sw_init;
7727 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007728 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007729 goto err_sw_init;
7730 }
7731
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007732 ixgbe_probe_vf(adapter, ii);
7733
Emil Tantilov396e7992010-07-01 20:05:12 +00007734 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007735 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007736 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007737 NETIF_F_HW_VLAN_TX |
7738 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007739 NETIF_F_HW_VLAN_FILTER |
7740 NETIF_F_TSO |
7741 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007742 NETIF_F_RXHASH |
7743 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007744
Don Skidmore082757a2011-07-21 05:55:00 +00007745 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007746
Don Skidmore58be7662011-04-12 09:42:11 +00007747 switch (adapter->hw.mac.type) {
7748 case ixgbe_mac_82599EB:
7749 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007750 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007751 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7752 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007753 break;
7754 default:
7755 break;
7756 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007757
Jeff Kirsherad31c402008-06-05 04:05:30 -07007758 netdev->vlan_features |= NETIF_F_TSO;
7759 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007760 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007761 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007762 netdev->vlan_features |= NETIF_F_SG;
7763
Jiri Pirko01789342011-08-16 06:29:00 +00007764 netdev->priv_flags |= IFF_UNICAST_FLT;
7765
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007766 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7767 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7768 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007769
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007770#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007771 netdev->dcbnl_ops = &dcbnl_ops;
7772#endif
7773
Yi Zoueacd73f2009-05-13 13:11:06 +00007774#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007775 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007776 if (hw->mac.ops.get_device_caps) {
7777 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007778 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7779 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007780 }
7781 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007782 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7783 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7784 netdev->vlan_features |= NETIF_F_FSO;
7785 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7786 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007787#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007788 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007789 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007790 netdev->vlan_features |= NETIF_F_HIGHDMA;
7791 }
Auke Kok9a799d72007-09-15 14:07:45 -07007792
Don Skidmore082757a2011-07-21 05:55:00 +00007793 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7794 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007795 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007796 netdev->features |= NETIF_F_LRO;
7797
Auke Kok9a799d72007-09-15 14:07:45 -07007798 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007799 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007800 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007801 err = -EIO;
7802 goto err_eeprom;
7803 }
7804
7805 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7806 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7807
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007808 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007809 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007810 err = -EIO;
7811 goto err_eeprom;
7812 }
7813
Alexander Duyck70864002011-04-27 09:13:56 +00007814 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7815 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007816
Alexander Duyck70864002011-04-27 09:13:56 +00007817 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7818 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007819
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007820 err = ixgbe_init_interrupt_scheme(adapter);
7821 if (err)
7822 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007823
Don Skidmore082757a2011-07-21 05:55:00 +00007824 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7825 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007826 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007827 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007828
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007829 /* WOL not supported for all but the following */
7830 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007831 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007832 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007833 /* Only these subdevice supports WOL */
7834 switch (pdev->subsystem_device) {
7835 case IXGBE_SUBDEV_ID_82599_560FLR:
7836 /* only support first port */
7837 if (hw->bus.func != 0)
7838 break;
7839 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007840 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007841 break;
7842 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007843 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007844 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7845 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007846 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007847 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007848 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007849 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007850 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007851 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007852 case IXGBE_DEV_ID_X540T:
7853 /* Check eeprom to see if it is enabled */
7854 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7855 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7856
7857 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7858 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7859 (hw->bus.func == 0)))
7860 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007861 break;
7862 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007863 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7864
Emil Tantilov15e52092011-09-29 05:01:29 +00007865 /* save off EEPROM version number */
7866 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7867 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7868
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007869 /* pick up the PCI bus settings for reporting later */
7870 hw->mac.ops.get_bus_info(hw);
7871
Auke Kok9a799d72007-09-15 14:07:45 -07007872 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007873 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007874 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7875 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007876 "Unknown"),
7877 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7878 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7879 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7880 "Unknown"),
7881 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007882
7883 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7884 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007885 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007886 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007887 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007888 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007889 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007890 else
Don Skidmore289700db2010-12-03 03:32:58 +00007891 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7892 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007893
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007894 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007895 e_dev_warn("PCI-Express bandwidth available for this card is "
7896 "not sufficient for optimal performance.\n");
7897 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7898 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007899 }
7900
Auke Kok9a799d72007-09-15 14:07:45 -07007901 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007902 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007903
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007904 if (err == IXGBE_ERR_EEPROM_VERSION) {
7905 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007906 e_dev_warn("This device is a pre-production adapter/LOM. "
7907 "Please be aware there may be issues associated "
7908 "with your hardware. If you are experiencing "
7909 "problems please contact your Intel or hardware "
7910 "representative who provided you with this "
7911 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007912 }
Auke Kok9a799d72007-09-15 14:07:45 -07007913 strcpy(netdev->name, "eth%d");
7914 err = register_netdev(netdev);
7915 if (err)
7916 goto err_register;
7917
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007918 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7919 if (hw->mac.ops.disable_tx_laser &&
7920 ((hw->phy.multispeed_fiber) ||
7921 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7922 (hw->mac.type == ixgbe_mac_82599EB))))
7923 hw->mac.ops.disable_tx_laser(hw);
7924
Jesse Brandeburg54386462009-04-17 20:44:27 +00007925 /* carrier off reporting is important to ethtool even BEFORE open */
7926 netif_carrier_off(netdev);
7927
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007928#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007929 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007930 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007931 ixgbe_setup_dca(adapter);
7932 }
7933#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007934 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007935 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007936 for (i = 0; i < adapter->num_vfs; i++)
7937 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7938 }
7939
Jacob Keller2466dd92011-09-08 03:50:54 +00007940 /* firmware requires driver version to be 0xFFFFFFFF
7941 * since os does not support feature
7942 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007943 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007944 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7945 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007946
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007947 /* add san mac addr to netdev */
7948 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007949
Neerav Parikhea818752012-01-04 20:23:40 +00007950 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007951 cards_found++;
7952 return 0;
7953
7954err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007955 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007956 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007957err_sw_init:
7958err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007959 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7960 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007961 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007962 iounmap(hw->hw_addr);
7963err_ioremap:
7964 free_netdev(netdev);
7965err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007966 pci_release_selected_regions(pdev,
7967 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007968err_pci_reg:
7969err_dma:
7970 pci_disable_device(pdev);
7971 return err;
7972}
7973
7974/**
7975 * ixgbe_remove - Device Removal Routine
7976 * @pdev: PCI device information struct
7977 *
7978 * ixgbe_remove is called by the PCI subsystem to alert the driver
7979 * that it should release a PCI device. The could be caused by a
7980 * Hot-Plug event, or because the driver is going to be removed from
7981 * memory.
7982 **/
7983static void __devexit ixgbe_remove(struct pci_dev *pdev)
7984{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007985 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7986 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007987
7988 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007989 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007990
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007991#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007992 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7993 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7994 dca_remove_requester(&pdev->dev);
7995 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7996 }
7997
7998#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007999#ifdef IXGBE_FCOE
8000 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
8001 ixgbe_cleanup_fcoe(adapter);
8002
8003#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00008004
8005 /* remove the added san mac */
8006 ixgbe_del_sanmac_netdev(netdev);
8007
Donald Skidmorec4900be2008-11-20 21:11:42 -08008008 if (netdev->reg_state == NETREG_REGISTERED)
8009 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008010
Greg Rosec6bda302011-08-24 02:37:55 +00008011 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
8012 if (!(ixgbe_check_vf_assignment(adapter)))
8013 ixgbe_disable_sriov(adapter);
8014 else
8015 e_dev_warn("Unloading driver while VFs are assigned "
8016 "- VFs will not be deallocated\n");
8017 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00008018
Alexander Duyck7a921c92009-05-06 10:43:28 +00008019 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08008020
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008021 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008022
8023 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00008024 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008025 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008026
Emil Tantilov849c4542010-06-03 16:53:41 +00008027 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008028
Auke Kok9a799d72007-09-15 14:07:45 -07008029 free_netdev(netdev);
8030
Frans Pop19d5afd2009-10-02 10:04:12 -07008031 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008032
Auke Kok9a799d72007-09-15 14:07:45 -07008033 pci_disable_device(pdev);
8034}
8035
8036/**
8037 * ixgbe_io_error_detected - called when PCI error is detected
8038 * @pdev: Pointer to PCI device
8039 * @state: The current pci connection state
8040 *
8041 * This function is called after a PCI bus error affecting
8042 * this device has been detected.
8043 */
8044static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008045 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008046{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008047 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8048 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008049
Greg Rose83c61fa2011-09-07 05:59:35 +00008050#ifdef CONFIG_PCI_IOV
8051 struct pci_dev *bdev, *vfdev;
8052 u32 dw0, dw1, dw2, dw3;
8053 int vf, pos;
8054 u16 req_id, pf_func;
8055
8056 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8057 adapter->num_vfs == 0)
8058 goto skip_bad_vf_detection;
8059
8060 bdev = pdev->bus->self;
8061 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8062 bdev = bdev->bus->self;
8063
8064 if (!bdev)
8065 goto skip_bad_vf_detection;
8066
8067 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8068 if (!pos)
8069 goto skip_bad_vf_detection;
8070
8071 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8072 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8073 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8074 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8075
8076 req_id = dw1 >> 16;
8077 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8078 if (!(req_id & 0x0080))
8079 goto skip_bad_vf_detection;
8080
8081 pf_func = req_id & 0x01;
8082 if ((pf_func & 1) == (pdev->devfn & 1)) {
8083 unsigned int device_id;
8084
8085 vf = (req_id & 0x7F) >> 1;
8086 e_dev_err("VF %d has caused a PCIe error\n", vf);
8087 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8088 "%8.8x\tdw3: %8.8x\n",
8089 dw0, dw1, dw2, dw3);
8090 switch (adapter->hw.mac.type) {
8091 case ixgbe_mac_82599EB:
8092 device_id = IXGBE_82599_VF_DEVICE_ID;
8093 break;
8094 case ixgbe_mac_X540:
8095 device_id = IXGBE_X540_VF_DEVICE_ID;
8096 break;
8097 default:
8098 device_id = 0;
8099 break;
8100 }
8101
8102 /* Find the pci device of the offending VF */
8103 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8104 while (vfdev) {
8105 if (vfdev->devfn == (req_id & 0xFF))
8106 break;
8107 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8108 device_id, vfdev);
8109 }
8110 /*
8111 * There's a slim chance the VF could have been hot plugged,
8112 * so if it is no longer present we don't need to issue the
8113 * VFLR. Just clean up the AER in that case.
8114 */
8115 if (vfdev) {
8116 e_dev_err("Issuing VFLR to VF %d\n", vf);
8117 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8118 }
8119
8120 pci_cleanup_aer_uncorrect_error_status(pdev);
8121 }
8122
8123 /*
8124 * Even though the error may have occurred on the other port
8125 * we still need to increment the vf error reference count for
8126 * both ports because the I/O resume function will be called
8127 * for both of them.
8128 */
8129 adapter->vferr_refcount++;
8130
8131 return PCI_ERS_RESULT_RECOVERED;
8132
8133skip_bad_vf_detection:
8134#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008135 netif_device_detach(netdev);
8136
Breno Leitao3044b8d2009-05-06 10:44:26 +00008137 if (state == pci_channel_io_perm_failure)
8138 return PCI_ERS_RESULT_DISCONNECT;
8139
Auke Kok9a799d72007-09-15 14:07:45 -07008140 if (netif_running(netdev))
8141 ixgbe_down(adapter);
8142 pci_disable_device(pdev);
8143
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008144 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008145 return PCI_ERS_RESULT_NEED_RESET;
8146}
8147
8148/**
8149 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8150 * @pdev: Pointer to PCI device
8151 *
8152 * Restart the card from scratch, as if from a cold-boot.
8153 */
8154static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8155{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008156 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008157 pci_ers_result_t result;
8158 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008159
gouji-new9ce77662009-05-06 10:44:45 +00008160 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008161 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008162 result = PCI_ERS_RESULT_DISCONNECT;
8163 } else {
8164 pci_set_master(pdev);
8165 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008166 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008167
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008168 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008169
8170 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008171 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008172 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008173 }
Auke Kok9a799d72007-09-15 14:07:45 -07008174
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008175 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8176 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008177 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8178 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008179 /* non-fatal, continue */
8180 }
Auke Kok9a799d72007-09-15 14:07:45 -07008181
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008182 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008183}
8184
8185/**
8186 * ixgbe_io_resume - called when traffic can start flowing again.
8187 * @pdev: Pointer to PCI device
8188 *
8189 * This callback is called when the error recovery driver tells us that
8190 * its OK to resume normal operation.
8191 */
8192static void ixgbe_io_resume(struct pci_dev *pdev)
8193{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008194 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8195 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008196
Greg Rose83c61fa2011-09-07 05:59:35 +00008197#ifdef CONFIG_PCI_IOV
8198 if (adapter->vferr_refcount) {
8199 e_info(drv, "Resuming after VF err\n");
8200 adapter->vferr_refcount--;
8201 return;
8202 }
8203
8204#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008205 if (netif_running(netdev))
8206 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008207
8208 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008209}
8210
8211static struct pci_error_handlers ixgbe_err_handler = {
8212 .error_detected = ixgbe_io_error_detected,
8213 .slot_reset = ixgbe_io_slot_reset,
8214 .resume = ixgbe_io_resume,
8215};
8216
8217static struct pci_driver ixgbe_driver = {
8218 .name = ixgbe_driver_name,
8219 .id_table = ixgbe_pci_tbl,
8220 .probe = ixgbe_probe,
8221 .remove = __devexit_p(ixgbe_remove),
8222#ifdef CONFIG_PM
8223 .suspend = ixgbe_suspend,
8224 .resume = ixgbe_resume,
8225#endif
8226 .shutdown = ixgbe_shutdown,
8227 .err_handler = &ixgbe_err_handler
8228};
8229
8230/**
8231 * ixgbe_init_module - Driver Registration Routine
8232 *
8233 * ixgbe_init_module is the first routine called when the driver is
8234 * loaded. All it does is register with the PCI subsystem.
8235 **/
8236static int __init ixgbe_init_module(void)
8237{
8238 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008239 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008240 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008241
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008242#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008243 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008244#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008245
Auke Kok9a799d72007-09-15 14:07:45 -07008246 ret = pci_register_driver(&ixgbe_driver);
8247 return ret;
8248}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008249
Auke Kok9a799d72007-09-15 14:07:45 -07008250module_init(ixgbe_init_module);
8251
8252/**
8253 * ixgbe_exit_module - Driver Exit Cleanup Routine
8254 *
8255 * ixgbe_exit_module is called just before the driver is removed
8256 * from memory.
8257 **/
8258static void __exit ixgbe_exit_module(void)
8259{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008260#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008261 dca_unregister_notify(&dca_notifier);
8262#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008263 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008264 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008265}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008266
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008267#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008268static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008269 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008270{
8271 int ret_val;
8272
8273 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008274 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008275
8276 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8277}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008278
Alexander Duyckb4533682009-03-31 21:32:42 +00008279#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008280
Auke Kok9a799d72007-09-15 14:07:45 -07008281module_exit(ixgbe_exit_module);
8282
8283/* ixgbe_main.c */