blob: b0469ddb158cab55fad154cb079d35ebf97e1381 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmore94971822012-01-06 03:24:16 +00004 Copyright(c) 1999 - 2012 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Neerav Parikhea818752012-01-04 20:23:40 +000058char ixgbe_default_device_descr[] =
59 "Intel(R) 10 Gigabit Network Connection";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define MAJ 3
Don Skidmore19d478b2011-10-07 03:53:51 +000061#define MIN 6
62#define BUILD 7
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000063#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000064 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070065const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000066static const char ixgbe_copyright[] =
Don Skidmore94971822012-01-06 03:24:16 +000067 "Copyright (c) 1999-2012 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070068
69static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070070 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000071 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080072 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070073};
74
75/* ixgbe_pci_tbl - PCI Device ID Table
76 *
77 * Wildcard entries (PCI_ANY_ID) should come last
78 * Last entry must be all 0s
79 *
80 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
81 * Class, Class Mask, private data (not used) }
82 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000083static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Alexander Duyck54239c62011-07-15 03:06:06 +000084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), board_82598 },
85 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), board_82598 },
86 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), board_82598 },
87 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), board_82598 },
88 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), board_82598 },
89 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), board_82598 },
90 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), board_82598 },
91 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), board_82598 },
92 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), board_82598 },
93 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), board_82598 },
94 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), board_82598 },
96 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), board_82599 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), board_82599 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), board_82599 },
99 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), board_82599 },
100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), board_82599 },
101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), board_82599 },
102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), board_82599 },
103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE), board_82599 },
104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE), board_82599 },
105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM), board_82599 },
106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), board_82599 },
107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T), board_X540 },
108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2), board_82599 },
109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS), board_82599 },
Emil Tantilov7d145282011-09-08 08:30:14 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599EN_SFP), board_82599 },
Emil Tantilov9e791e42011-11-04 06:43:29 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF_QP), board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700112 /* required last entry */
113 {0, }
114};
115MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
116
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400117#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800118static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000119 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800120static struct notifier_block dca_notifier = {
121 .notifier_call = ixgbe_notify_dca,
122 .next = NULL,
123 .priority = 0
124};
125#endif
126
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000127#ifdef CONFIG_PCI_IOV
128static unsigned int max_vfs;
129module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000130MODULE_PARM_DESC(max_vfs,
131 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000132#endif /* CONFIG_PCI_IOV */
133
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +0000134static unsigned int allow_unsupported_sfp;
135module_param(allow_unsupported_sfp, uint, 0);
136MODULE_PARM_DESC(allow_unsupported_sfp,
137 "Allow unsupported and untested SFP+ modules on 82599-based adapters");
138
Auke Kok9a799d72007-09-15 14:07:45 -0700139MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
140MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
141MODULE_LICENSE("GPL");
142MODULE_VERSION(DRV_VERSION);
143
144#define DEFAULT_DEBUG_LEVEL_SHIFT 3
145
Alexander Duyck70864002011-04-27 09:13:56 +0000146static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
147{
148 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
149 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
150 schedule_work(&adapter->service_task);
151}
152
153static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
154{
155 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
156
Stephen Hemminger52f33af2011-12-22 16:34:52 +0000157 /* flush memory to make sure state is correct before next watchdog */
Alexander Duyck70864002011-04-27 09:13:56 +0000158 smp_mb__before_clear_bit();
159 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
160}
161
Taku Izumidcd79ae2010-04-27 14:39:53 +0000162struct ixgbe_reg_info {
163 u32 ofs;
164 char *name;
165};
166
167static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
168
169 /* General Registers */
170 {IXGBE_CTRL, "CTRL"},
171 {IXGBE_STATUS, "STATUS"},
172 {IXGBE_CTRL_EXT, "CTRL_EXT"},
173
174 /* Interrupt Registers */
175 {IXGBE_EICR, "EICR"},
176
177 /* RX Registers */
178 {IXGBE_SRRCTL(0), "SRRCTL"},
179 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
180 {IXGBE_RDLEN(0), "RDLEN"},
181 {IXGBE_RDH(0), "RDH"},
182 {IXGBE_RDT(0), "RDT"},
183 {IXGBE_RXDCTL(0), "RXDCTL"},
184 {IXGBE_RDBAL(0), "RDBAL"},
185 {IXGBE_RDBAH(0), "RDBAH"},
186
187 /* TX Registers */
188 {IXGBE_TDBAL(0), "TDBAL"},
189 {IXGBE_TDBAH(0), "TDBAH"},
190 {IXGBE_TDLEN(0), "TDLEN"},
191 {IXGBE_TDH(0), "TDH"},
192 {IXGBE_TDT(0), "TDT"},
193 {IXGBE_TXDCTL(0), "TXDCTL"},
194
195 /* List Terminator */
196 {}
197};
198
199
200/*
201 * ixgbe_regdump - register printout routine
202 */
203static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
204{
205 int i = 0, j = 0;
206 char rname[16];
207 u32 regs[64];
208
209 switch (reginfo->ofs) {
210 case IXGBE_SRRCTL(0):
211 for (i = 0; i < 64; i++)
212 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
213 break;
214 case IXGBE_DCA_RXCTRL(0):
215 for (i = 0; i < 64; i++)
216 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
217 break;
218 case IXGBE_RDLEN(0):
219 for (i = 0; i < 64; i++)
220 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
221 break;
222 case IXGBE_RDH(0):
223 for (i = 0; i < 64; i++)
224 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
225 break;
226 case IXGBE_RDT(0):
227 for (i = 0; i < 64; i++)
228 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
229 break;
230 case IXGBE_RXDCTL(0):
231 for (i = 0; i < 64; i++)
232 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
233 break;
234 case IXGBE_RDBAL(0):
235 for (i = 0; i < 64; i++)
236 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
237 break;
238 case IXGBE_RDBAH(0):
239 for (i = 0; i < 64; i++)
240 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
241 break;
242 case IXGBE_TDBAL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
245 break;
246 case IXGBE_TDBAH(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
249 break;
250 case IXGBE_TDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
253 break;
254 case IXGBE_TDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
257 break;
258 case IXGBE_TDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
261 break;
262 case IXGBE_TXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
265 break;
266 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000267 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000268 IXGBE_READ_REG(hw, reginfo->ofs));
269 return;
270 }
271
272 for (i = 0; i < 8; i++) {
273 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000274 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000275 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000276 pr_cont(" %08x", regs[i*8+j]);
277 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000278 }
279
280}
281
282/*
283 * ixgbe_dump - Print registers, tx-rings and rx-rings
284 */
285static void ixgbe_dump(struct ixgbe_adapter *adapter)
286{
287 struct net_device *netdev = adapter->netdev;
288 struct ixgbe_hw *hw = &adapter->hw;
289 struct ixgbe_reg_info *reginfo;
290 int n = 0;
291 struct ixgbe_ring *tx_ring;
292 struct ixgbe_tx_buffer *tx_buffer_info;
293 union ixgbe_adv_tx_desc *tx_desc;
294 struct my_u0 { u64 a; u64 b; } *u0;
295 struct ixgbe_ring *rx_ring;
296 union ixgbe_adv_rx_desc *rx_desc;
297 struct ixgbe_rx_buffer *rx_buffer_info;
298 u32 staterr;
299 int i = 0;
300
301 if (!netif_msg_hw(adapter))
302 return;
303
304 /* Print netdevice Info */
305 if (netdev) {
306 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000307 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000308 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000309 pr_info("%-15s %016lX %016lX %016lX\n",
310 netdev->name,
311 netdev->state,
312 netdev->trans_start,
313 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000314 }
315
316 /* Print Registers */
317 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000318 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000319 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
320 reginfo->name; reginfo++) {
321 ixgbe_regdump(hw, reginfo);
322 }
323
324 /* Print TX Ring Summary */
325 if (!netdev || !netif_running(netdev))
326 goto exit;
327
328 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 for (n = 0; n < adapter->num_tx_queues; n++) {
331 tx_ring = adapter->tx_ring[n];
332 tx_buffer_info =
333 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000334 pr_info(" %5d %5X %5X %016llX %04X %p %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000335 n, tx_ring->next_to_use, tx_ring->next_to_clean,
336 (u64)tx_buffer_info->dma,
337 tx_buffer_info->length,
338 tx_buffer_info->next_to_watch,
339 (u64)tx_buffer_info->time_stamp);
340 }
341
342 /* Print TX Rings */
343 if (!netif_msg_tx_done(adapter))
344 goto rx_ring_summary;
345
346 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
347
348 /* Transmit Descriptor Formats
349 *
350 * Advanced Transmit Descriptor
351 * +--------------------------------------------------------------+
352 * 0 | Buffer Address [63:0] |
353 * +--------------------------------------------------------------+
354 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
355 * +--------------------------------------------------------------+
356 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
357 */
358
359 for (n = 0; n < adapter->num_tx_queues; n++) {
360 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("------------------------------------\n");
362 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
363 pr_info("------------------------------------\n");
364 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000365 "[PlPOIdStDDt Ln] [bi->dma ] "
366 "leng ntw timestamp bi->skb\n");
367
368 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000369 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000370 tx_buffer_info = &tx_ring->tx_buffer_info[i];
371 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info("T [0x%03X] %016llX %016llX %016llX"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000373 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000374 le64_to_cpu(u0->a),
375 le64_to_cpu(u0->b),
376 (u64)tx_buffer_info->dma,
377 tx_buffer_info->length,
378 tx_buffer_info->next_to_watch,
379 (u64)tx_buffer_info->time_stamp,
380 tx_buffer_info->skb);
381 if (i == tx_ring->next_to_use &&
382 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000385 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000386 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 else
Joe Perchesc7689572010-09-07 21:35:17 +0000389 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000390
391 if (netif_msg_pktdata(adapter) &&
392 tx_buffer_info->dma != 0)
393 print_hex_dump(KERN_INFO, "",
394 DUMP_PREFIX_ADDRESS, 16, 1,
395 phys_to_virt(tx_buffer_info->dma),
396 tx_buffer_info->length, true);
397 }
398 }
399
400 /* Print RX Rings Summary */
401rx_ring_summary:
402 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000403 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000404 for (n = 0; n < adapter->num_rx_queues; n++) {
405 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000406 pr_info("%5d %5X %5X\n",
407 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000408 }
409
410 /* Print RX Rings */
411 if (!netif_msg_rx_status(adapter))
412 goto exit;
413
414 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
415
416 /* Advanced Receive Descriptor (Read) Format
417 * 63 1 0
418 * +-----------------------------------------------------+
419 * 0 | Packet Buffer Address [63:1] |A0/NSE|
420 * +----------------------------------------------+------+
421 * 8 | Header Buffer Address [63:1] | DD |
422 * +-----------------------------------------------------+
423 *
424 *
425 * Advanced Receive Descriptor (Write-Back) Format
426 *
427 * 63 48 47 32 31 30 21 20 16 15 4 3 0
428 * +------------------------------------------------------+
429 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
430 * | Checksum Ident | | | | Type | Type |
431 * +------------------------------------------------------+
432 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
433 * +------------------------------------------------------+
434 * 63 48 47 32 31 20 19 0
435 */
436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("------------------------------------\n");
439 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
440 pr_info("------------------------------------\n");
441 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
443 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000444 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000445 "[vl er S cks ln] ---------------- [bi->skb] "
446 "<-- Adv Rx Write-Back format\n");
447
448 for (i = 0; i < rx_ring->count; i++) {
449 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000450 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000451 u0 = (struct my_u0 *)rx_desc;
452 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
453 if (staterr & IXGBE_RXD_STAT_DD) {
454 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 "%016llX ---------------- %p", i,
457 le64_to_cpu(u0->a),
458 le64_to_cpu(u0->b),
459 rx_buffer_info->skb);
460 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000461 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 "%016llX %016llX %p", i,
463 le64_to_cpu(u0->a),
464 le64_to_cpu(u0->b),
465 (u64)rx_buffer_info->dma,
466 rx_buffer_info->skb);
467
468 if (netif_msg_pktdata(adapter)) {
469 print_hex_dump(KERN_INFO, "",
470 DUMP_PREFIX_ADDRESS, 16, 1,
471 phys_to_virt(rx_buffer_info->dma),
472 rx_ring->rx_buf_len, true);
473
474 if (rx_ring->rx_buf_len
Alexander Duyck919e78a2011-08-26 09:52:38 +0000475 < IXGBE_RXBUFFER_2K)
Taku Izumidcd79ae2010-04-27 14:39:53 +0000476 print_hex_dump(KERN_INFO, "",
477 DUMP_PREFIX_ADDRESS, 16, 1,
478 phys_to_virt(
479 rx_buffer_info->page_dma +
480 rx_buffer_info->page_offset
481 ),
482 PAGE_SIZE/2, true);
483 }
484 }
485
486 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000488 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000489 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 else
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492
493 }
494 }
495
496exit:
497 return;
498}
499
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800500static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
501{
502 u32 ctrl_ext;
503
504 /* Let firmware take over control of h/w */
505 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
506 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000507 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800508}
509
510static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
511{
512 u32 ctrl_ext;
513
514 /* Let firmware know the driver has taken over */
515 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
516 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000517 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800518}
Auke Kok9a799d72007-09-15 14:07:45 -0700519
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000520/*
521 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
522 * @adapter: pointer to adapter struct
523 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
524 * @queue: queue to map the corresponding interrupt to
525 * @msix_vector: the vector to map to the corresponding queue
526 *
527 */
528static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000529 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700530{
531 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000532 struct ixgbe_hw *hw = &adapter->hw;
533 switch (hw->mac.type) {
534 case ixgbe_mac_82598EB:
535 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
536 if (direction == -1)
537 direction = 0;
538 index = (((direction * 64) + queue) >> 2) & 0x1F;
539 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
540 ivar &= ~(0xFF << (8 * (queue & 0x3)));
541 ivar |= (msix_vector << (8 * (queue & 0x3)));
542 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
543 break;
544 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800545 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000546 if (direction == -1) {
547 /* other causes */
548 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
549 index = ((queue & 1) * 8);
550 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
551 ivar &= ~(0xFF << index);
552 ivar |= (msix_vector << index);
553 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
554 break;
555 } else {
556 /* tx or rx causes */
557 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
558 index = ((16 * (queue & 1)) + (8 * direction));
559 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
560 ivar &= ~(0xFF << index);
561 ivar |= (msix_vector << index);
562 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
563 break;
564 }
565 default:
566 break;
567 }
Auke Kok9a799d72007-09-15 14:07:45 -0700568}
569
Alexander Duyckfe49f042009-06-04 16:00:09 +0000570static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000572{
573 u32 mask;
574
Alexander Duyckbd508172010-11-16 19:27:03 -0800575 switch (adapter->hw.mac.type) {
576 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000577 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
578 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800579 break;
580 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800581 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000582 mask = (qmask & 0xFFFFFFFF);
583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
584 mask = (qmask >> 32);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800586 break;
587 default:
588 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000589 }
590}
591
Alexander Duyckd3d00232011-07-15 02:31:25 +0000592static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
593 struct ixgbe_tx_buffer *tx_buffer)
594{
595 if (tx_buffer->dma) {
596 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
597 dma_unmap_page(ring->dev,
598 tx_buffer->dma,
599 tx_buffer->length,
600 DMA_TO_DEVICE);
601 else
602 dma_unmap_single(ring->dev,
603 tx_buffer->dma,
604 tx_buffer->length,
605 DMA_TO_DEVICE);
606 }
607 tx_buffer->dma = 0;
608}
609
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800610void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
611 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700612{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000613 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
614 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700615 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000616 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700617 /* tx_buffer_info must be completely set up in the transmit path */
618}
619
John Fastabendc84d3242010-11-16 19:27:12 -0800620static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700621{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700622 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800623 struct ixgbe_hw_stats *hwstats = &adapter->stats;
624 u32 data = 0;
625 u32 xoff[8] = {0};
626 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700627
John Fastabendc84d3242010-11-16 19:27:12 -0800628 if ((hw->fc.current_mode == ixgbe_fc_full) ||
629 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
630 switch (hw->mac.type) {
631 case ixgbe_mac_82598EB:
632 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
633 break;
634 default:
635 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
636 }
637 hwstats->lxoffrxc += data;
638
639 /* refill credits (no tx hang) if we received xoff */
640 if (!data)
641 return;
642
643 for (i = 0; i < adapter->num_tx_queues; i++)
644 clear_bit(__IXGBE_HANG_CHECK_ARMED,
645 &adapter->tx_ring[i]->state);
646 return;
647 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
648 return;
649
650 /* update stats for each tc, only valid with PFC enabled */
651 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
652 switch (hw->mac.type) {
653 case ixgbe_mac_82598EB:
654 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
655 break;
656 default:
657 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
658 }
659 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700660 }
661
John Fastabendc84d3242010-11-16 19:27:12 -0800662 /* disarm tx queues that have received xoff frames */
663 for (i = 0; i < adapter->num_tx_queues; i++) {
664 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000665 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800666
667 if (xoff[tc])
668 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
669 }
670}
671
672static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
673{
674 return ring->tx_stats.completed;
675}
676
677static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
678{
679 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
680 struct ixgbe_hw *hw = &adapter->hw;
681
682 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
683 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
684
685 if (head != tail)
686 return (head < tail) ?
687 tail - head : (tail + ring->count - head);
688
689 return 0;
690}
691
692static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
693{
694 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
695 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
696 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
697 bool ret = false;
698
699 clear_check_for_tx_hang(tx_ring);
700
701 /*
702 * Check for a hung queue, but be thorough. This verifies
703 * that a transmit has been completed since the previous
704 * check AND there is at least one packet pending. The
705 * ARMED bit is set to indicate a potential hang. The
706 * bit is cleared if a pause frame is received to remove
707 * false hang detection due to PFC or 802.3x frames. By
708 * requiring this to fail twice we avoid races with
709 * pfc clearing the ARMED bit and conditions where we
710 * run the check_tx_hang logic with a transmit completion
711 * pending but without time to complete it yet.
712 */
713 if ((tx_done_old == tx_done) && tx_pending) {
714 /* make sure it is true for two checks in a row */
715 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
716 &tx_ring->state);
717 } else {
718 /* update completed stats and continue */
719 tx_ring->tx_stats.tx_done_old = tx_done;
720 /* reset the countdown */
721 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
722 }
723
724 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700725}
726
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000727/**
728 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
729 * @adapter: driver private struct
730 **/
731static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
732{
733
734 /* Do the reset outside of interrupt context */
735 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
736 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
737 ixgbe_service_event_schedule(adapter);
738 }
739}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700740
Auke Kok9a799d72007-09-15 14:07:45 -0700741/**
742 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000743 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700744 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700745 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000746static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000747 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700748{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000749 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000750 struct ixgbe_tx_buffer *tx_buffer;
751 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700752 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyck59224552011-08-31 00:01:06 +0000753 unsigned int budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000754 u16 i = tx_ring->next_to_clean;
Auke Kok9a799d72007-09-15 14:07:45 -0700755
Alexander Duyckd3d00232011-07-15 02:31:25 +0000756 tx_buffer = &tx_ring->tx_buffer_info[i];
757 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800758
Alexander Duyck30065e62011-07-15 03:05:14 +0000759 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000760 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700761
Alexander Duyckd3d00232011-07-15 02:31:25 +0000762 /* if next_to_watch is not set then there is no work pending */
763 if (!eop_desc)
764 break;
765
766 /* if DD is not set pending work has not been completed */
767 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
768 break;
769
770 /* count the packet as being completed */
771 tx_ring->tx_stats.completed++;
772
773 /* clear next_to_watch to prevent false hangs */
774 tx_buffer->next_to_watch = NULL;
775
776 /* prevent any other reads prior to eop_desc being verified */
777 rmb();
778
779 do {
780 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800781 tx_desc->wb.status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000782 if (likely(tx_desc == eop_desc)) {
783 eop_desc = NULL;
784 dev_kfree_skb_any(tx_buffer->skb);
785 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800786
Alexander Duyckd3d00232011-07-15 02:31:25 +0000787 total_bytes += tx_buffer->bytecount;
788 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800789 }
790
Alexander Duyckd3d00232011-07-15 02:31:25 +0000791 tx_buffer++;
792 tx_desc++;
793 i++;
794 if (unlikely(i == tx_ring->count)) {
795 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700796
Alexander Duyckd3d00232011-07-15 02:31:25 +0000797 tx_buffer = tx_ring->tx_buffer_info;
798 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
799 }
800
801 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800802 }
803
Auke Kok9a799d72007-09-15 14:07:45 -0700804 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000805 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800806 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000807 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000808 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000809 q_vector->tx.total_bytes += total_bytes;
810 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800811
John Fastabendc84d3242010-11-16 19:27:12 -0800812 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800813 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800814 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000815 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800816 e_err(drv, "Detected Tx Unit Hang\n"
817 " Tx Queue <%d>\n"
818 " TDH, TDT <%x>, <%x>\n"
819 " next_to_use <%x>\n"
820 " next_to_clean <%x>\n"
821 "tx_buffer_info[next_to_clean]\n"
822 " time_stamp <%lx>\n"
823 " jiffies <%lx>\n",
824 tx_ring->queue_index,
825 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
826 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000827 tx_ring->next_to_use, i,
828 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800829
830 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
831
832 e_info(probe,
833 "tx hang %d detected on queue %d, resetting adapter\n",
834 adapter->tx_timeout_count + 1, tx_ring->queue_index);
835
836 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000837 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800838
839 /* the adapter is about to reset, no point in enabling stuff */
Alexander Duyck59224552011-08-31 00:01:06 +0000840 return true;
Alexander Duyckb9537992010-11-16 19:26:58 -0800841 }
Auke Kok9a799d72007-09-15 14:07:45 -0700842
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800843#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000844 if (unlikely(total_packets && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000845 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800846 /* Make sure that anybody stopping the queue after this
847 * sees the new next_to_clean.
848 */
849 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800850 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800851 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800852 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800853 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800854 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800855 }
Auke Kok9a799d72007-09-15 14:07:45 -0700856
Alexander Duyck59224552011-08-31 00:01:06 +0000857 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -0700858}
859
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400860#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800861static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800862 struct ixgbe_ring *rx_ring,
863 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800864{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800865 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800866 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800867 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800868
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800869 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
870 switch (hw->mac.type) {
871 case ixgbe_mac_82598EB:
872 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000873 rxctrl |= dca3_get_tag(rx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800874 break;
875 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800876 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800877 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000878 rxctrl |= (dca3_get_tag(rx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800879 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
880 break;
881 default:
882 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800883 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800884 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
885 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
886 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800887 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800888}
889
890static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800891 struct ixgbe_ring *tx_ring,
892 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800893{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000894 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800895 u32 txctrl;
896 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800897
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800898 switch (hw->mac.type) {
899 case ixgbe_mac_82598EB:
900 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
901 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000902 txctrl |= dca3_get_tag(tx_ring->dev, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800903 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800904 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
905 break;
906 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800907 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800908 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
909 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
Alexander Duyck263a84e2011-07-15 03:05:46 +0000910 txctrl |= (dca3_get_tag(tx_ring->dev, cpu) <<
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800911 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
912 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800913 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
914 break;
915 default:
916 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800917 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800918}
919
920static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
921{
922 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000923 struct ixgbe_ring *ring;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800924 int cpu = get_cpu();
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925
926 if (q_vector->cpu == cpu)
927 goto out_no_update;
928
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000929 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
930 ixgbe_update_tx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931
Alexander Duyckefe3d3c2011-07-15 03:05:21 +0000932 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
933 ixgbe_update_rx_dca(adapter, ring, cpu);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800934
935 q_vector->cpu = cpu;
936out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800937 put_cpu();
938}
939
940static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
941{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800942 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800943 int i;
944
945 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
946 return;
947
Alexander Duycke35ec122009-05-21 13:07:12 +0000948 /* always use CB2 mode, difference is masked in the CB driver */
949 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
950
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800951 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
952 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
953 else
954 num_q_vectors = 1;
955
956 for (i = 0; i < num_q_vectors; i++) {
957 adapter->q_vector[i]->cpu = -1;
958 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800959 }
960}
961
962static int __ixgbe_notify_dca(struct device *dev, void *data)
963{
Alexander Duyckc60fbb02010-11-16 19:26:54 -0800964 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800965 unsigned long event = *(unsigned long *)data;
966
Don Skidmore2a72c312011-07-20 02:27:05 +0000967 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 return 0;
969
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800970 switch (event) {
971 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700972 /* if we're already enabled, don't do it again */
973 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
974 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +0300975 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -0700976 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800977 ixgbe_setup_dca(adapter);
978 break;
979 }
980 /* Fall Through since DCA is disabled. */
981 case DCA_PROVIDER_REMOVE:
982 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
983 dca_remove_requester(dev);
984 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
985 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
986 }
987 break;
988 }
989
Denis V. Lunev652f0932008-03-27 14:39:17 +0300990 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800991}
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400992#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +0000993
994static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
995 struct sk_buff *skb)
996{
997 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
998}
999
Auke Kok9a799d72007-09-15 14:07:45 -07001000/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001001 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1002 * @adapter: address of board private structure
1003 * @rx_desc: advanced rx descriptor
1004 *
1005 * Returns : true if it is FCoE pkt
1006 */
1007static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1008 union ixgbe_adv_rx_desc *rx_desc)
1009{
1010 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1011
1012 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1013 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1014 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1015 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1016}
1017
1018/**
Auke Kok9a799d72007-09-15 14:07:45 -07001019 * ixgbe_receive_skb - Send a completed packet up the stack
1020 * @adapter: board private structure
1021 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001022 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1023 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001024 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001025static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001026 struct sk_buff *skb,
Joe Perchese8e9f692010-09-07 21:34:53 +00001027 struct ixgbe_ring *ring,
1028 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001029{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001030 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001031
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001032 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_VP)) {
1033 u16 vid = le16_to_cpu(rx_desc->wb.upper.vlan);
1034 __vlan_hwaccel_put_tag(skb, vid);
1035 }
Jesse Grossf62bbb52010-10-20 13:56:10 +00001036
1037 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001038 napi_gro_receive(&q_vector->napi, skb);
Jesse Grossf62bbb52010-10-20 13:56:10 +00001039 else
1040 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001041}
1042
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001043/**
1044 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1045 * @adapter: address of board private structure
1046 * @status_err: hardware indication of status of receive
1047 * @skb: skb currently being received and modified
1048 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001049static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001050 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001051 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001052{
Alexander Duyckff886df2011-06-11 01:45:13 +00001053 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001054
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001055 /* Rx csum disabled */
1056 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001057 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001058
1059 /* if IP and error */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001060 if (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_IPCS) &&
1061 ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001062 adapter->hw_csum_rx_error++;
1063 return;
1064 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001065
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001066 if (!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_L4CS))
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001067 return;
1068
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001069 if (ixgbe_test_staterr(rx_desc, IXGBE_RXDADV_ERR_TCPE)) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001070 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1071
1072 /*
1073 * 82599 errata, UDP frames with a 0 checksum can be marked as
1074 * checksum errors.
1075 */
1076 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1077 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1078 return;
1079
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001080 adapter->hw_csum_rx_error++;
1081 return;
1082 }
1083
Auke Kok9a799d72007-09-15 14:07:45 -07001084 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001085 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001086}
1087
Alexander Duyck84ea2592010-11-16 19:26:49 -08001088static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001089{
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001090 rx_ring->next_to_use = val;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001091 /*
1092 * Force memory writes to complete before letting h/w
1093 * know there are new descriptors to fetch. (Only
1094 * applicable for weak-ordered memory model archs,
1095 * such as IA-64).
1096 */
1097 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001098 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001099}
1100
Alexander Duyckf990b792012-01-31 02:59:34 +00001101static bool ixgbe_alloc_mapped_skb(struct ixgbe_ring *rx_ring,
1102 struct ixgbe_rx_buffer *bi)
1103{
1104 struct sk_buff *skb = bi->skb;
1105 dma_addr_t dma = bi->dma;
1106
1107 if (dma)
1108 return true;
1109
1110 if (likely(!skb)) {
1111 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
1112 rx_ring->rx_buf_len);
1113 bi->skb = skb;
1114 if (!skb) {
1115 rx_ring->rx_stats.alloc_rx_buff_failed++;
1116 return false;
1117 }
1118
1119 /* initialize skb for ring */
1120 skb_record_rx_queue(skb, rx_ring->queue_index);
1121 }
1122
1123 dma = dma_map_single(rx_ring->dev, skb->data,
1124 rx_ring->rx_buf_len, DMA_FROM_DEVICE);
1125
1126 if (dma_mapping_error(rx_ring->dev, dma)) {
1127 rx_ring->rx_stats.alloc_rx_buff_failed++;
1128 return false;
1129 }
1130
1131 bi->dma = dma;
1132 return true;
1133}
1134
1135static bool ixgbe_alloc_mapped_page(struct ixgbe_ring *rx_ring,
1136 struct ixgbe_rx_buffer *bi)
1137{
1138 struct page *page = bi->page;
1139 dma_addr_t page_dma = bi->page_dma;
1140 unsigned int page_offset = bi->page_offset ^ (PAGE_SIZE / 2);
1141
1142 if (page_dma)
1143 return true;
1144
1145 if (!page) {
1146 page = alloc_page(GFP_ATOMIC | __GFP_COLD);
1147 bi->page = page;
1148 if (unlikely(!page)) {
1149 rx_ring->rx_stats.alloc_rx_page_failed++;
1150 return false;
1151 }
1152 }
1153
1154 page_dma = dma_map_page(rx_ring->dev, page,
1155 page_offset, PAGE_SIZE / 2,
1156 DMA_FROM_DEVICE);
1157
1158 if (dma_mapping_error(rx_ring->dev, page_dma)) {
1159 rx_ring->rx_stats.alloc_rx_page_failed++;
1160 return false;
1161 }
1162
1163 bi->page_dma = page_dma;
1164 bi->page_offset = page_offset;
1165 return true;
1166}
1167
Auke Kok9a799d72007-09-15 14:07:45 -07001168/**
Alexander Duyckf990b792012-01-31 02:59:34 +00001169 * ixgbe_alloc_rx_buffers - Replace used receive buffers
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001170 * @rx_ring: ring to place buffers on
1171 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001172 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001173void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001174{
Auke Kok9a799d72007-09-15 14:07:45 -07001175 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001176 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001177 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001178
Alexander Duyckf990b792012-01-31 02:59:34 +00001179 /* nothing to do or no valid netdev defined */
1180 if (!cleaned_count || !rx_ring->netdev)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001181 return;
1182
Alexander Duyckf990b792012-01-31 02:59:34 +00001183 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
1184 bi = &rx_ring->rx_buffer_info[i];
1185 i -= rx_ring->count;
1186
Auke Kok9a799d72007-09-15 14:07:45 -07001187 while (cleaned_count--) {
Alexander Duyckf990b792012-01-31 02:59:34 +00001188 if (!ixgbe_alloc_mapped_skb(rx_ring, bi))
1189 break;
Auke Kok9a799d72007-09-15 14:07:45 -07001190
Alexander Duyckf990b792012-01-31 02:59:34 +00001191 /* Refresh the desc even if buffer_addrs didn't change
1192 * because each write-back erases this info. */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001193 if (ring_is_ps_enabled(rx_ring)) {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001194 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Alexander Duyckf990b792012-01-31 02:59:34 +00001195
1196 if (!ixgbe_alloc_mapped_page(rx_ring, bi))
1197 break;
1198
1199 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001200 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001201 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001202 }
1203
Alexander Duyckf990b792012-01-31 02:59:34 +00001204 rx_desc++;
1205 bi++;
Auke Kok9a799d72007-09-15 14:07:45 -07001206 i++;
Alexander Duyckf990b792012-01-31 02:59:34 +00001207 if (unlikely(!i)) {
1208 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, 0);
1209 bi = rx_ring->rx_buffer_info;
1210 i -= rx_ring->count;
1211 }
1212
1213 /* clear the hdr_addr for the next_to_use descriptor */
1214 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001215 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001216
Alexander Duyckf990b792012-01-31 02:59:34 +00001217 i += rx_ring->count;
1218
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001219 if (rx_ring->next_to_use != i)
Alexander Duyck84ea2592010-11-16 19:26:49 -08001220 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001221}
1222
Alexander Duyckc267fc12010-11-16 19:27:00 -08001223static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001224{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001225 /* HW will not DMA in data larger than the given buffer, even if it
1226 * parses the (NFS, of course) header to be larger. In that case, it
1227 * fills the header buffer and spills the rest into the page.
1228 */
1229 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1230 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1231 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1232 if (hlen > IXGBE_RX_HDR_SIZE)
1233 hlen = IXGBE_RX_HDR_SIZE;
1234 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001235}
1236
Alexander Duyckf8212f92009-04-27 22:42:37 +00001237/**
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001238 * ixgbe_merge_active_tail - merge active tail into lro skb
1239 * @tail: pointer to active tail in frag_list
Alexander Duyckf8212f92009-04-27 22:42:37 +00001240 *
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001241 * This function merges the length and data of an active tail into the
1242 * skb containing the frag_list. It resets the tail's pointer to the head,
1243 * but it leaves the heads pointer to tail intact.
Alexander Duyckf8212f92009-04-27 22:42:37 +00001244 **/
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001245static inline struct sk_buff *ixgbe_merge_active_tail(struct sk_buff *tail)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001246{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001247 struct sk_buff *head = IXGBE_CB(tail)->head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001248
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001249 if (!head)
1250 return tail;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001251
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001252 head->len += tail->len;
1253 head->data_len += tail->len;
1254 head->truesize += tail->len;
Alexander Duyckaa801752010-11-16 19:27:02 -08001255
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001256 IXGBE_CB(tail)->head = NULL;
1257
1258 return head;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001259}
1260
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001261/**
1262 * ixgbe_add_active_tail - adds an active tail into the skb frag_list
1263 * @head: pointer to the start of the skb
1264 * @tail: pointer to active tail to add to frag_list
1265 *
1266 * This function adds an active tail to the end of the frag list. This tail
1267 * will still be receiving data so we cannot yet ad it's stats to the main
1268 * skb. That is done via ixgbe_merge_active_tail.
1269 **/
1270static inline void ixgbe_add_active_tail(struct sk_buff *head,
1271 struct sk_buff *tail)
Alexander Duyckaa801752010-11-16 19:27:02 -08001272{
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001273 struct sk_buff *old_tail = IXGBE_CB(head)->tail;
1274
1275 if (old_tail) {
1276 ixgbe_merge_active_tail(old_tail);
1277 old_tail->next = tail;
1278 } else {
1279 skb_shinfo(head)->frag_list = tail;
1280 }
1281
1282 IXGBE_CB(tail)->head = head;
1283 IXGBE_CB(head)->tail = tail;
1284}
1285
1286/**
1287 * ixgbe_close_active_frag_list - cleanup pointers on a frag_list skb
1288 * @head: pointer to head of an active frag list
1289 *
1290 * This function will clear the frag_tail_tracker pointer on an active
1291 * frag_list and returns true if the pointer was actually set
1292 **/
1293static inline bool ixgbe_close_active_frag_list(struct sk_buff *head)
1294{
1295 struct sk_buff *tail = IXGBE_CB(head)->tail;
1296
1297 if (!tail)
1298 return false;
1299
1300 ixgbe_merge_active_tail(tail);
1301
1302 IXGBE_CB(head)->tail = NULL;
1303
1304 return true;
1305}
1306
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001307/**
1308 * ixgbe_get_headlen - determine size of header for RSC/LRO/GRO/FCOE
1309 * @data: pointer to the start of the headers
1310 * @max_len: total length of section to find headers in
1311 *
1312 * This function is meant to determine the length of headers that will
1313 * be recognized by hardware for LRO, GRO, and RSC offloads. The main
1314 * motivation of doing this is to only perform one pull for IPv4 TCP
1315 * packets so that we can do basic things like calculating the gso_size
1316 * based on the average data per packet.
1317 **/
1318static unsigned int ixgbe_get_headlen(unsigned char *data,
1319 unsigned int max_len)
1320{
1321 union {
1322 unsigned char *network;
1323 /* l2 headers */
1324 struct ethhdr *eth;
1325 struct vlan_hdr *vlan;
1326 /* l3 headers */
1327 struct iphdr *ipv4;
1328 } hdr;
1329 __be16 protocol;
1330 u8 nexthdr = 0; /* default to not TCP */
1331 u8 hlen;
1332
1333 /* this should never happen, but better safe than sorry */
1334 if (max_len < ETH_HLEN)
1335 return max_len;
1336
1337 /* initialize network frame pointer */
1338 hdr.network = data;
1339
1340 /* set first protocol and move network header forward */
1341 protocol = hdr.eth->h_proto;
1342 hdr.network += ETH_HLEN;
1343
1344 /* handle any vlan tag if present */
1345 if (protocol == __constant_htons(ETH_P_8021Q)) {
1346 if ((hdr.network - data) > (max_len - VLAN_HLEN))
1347 return max_len;
1348
1349 protocol = hdr.vlan->h_vlan_encapsulated_proto;
1350 hdr.network += VLAN_HLEN;
1351 }
1352
1353 /* handle L3 protocols */
1354 if (protocol == __constant_htons(ETH_P_IP)) {
1355 if ((hdr.network - data) > (max_len - sizeof(struct iphdr)))
1356 return max_len;
1357
1358 /* access ihl as a u8 to avoid unaligned access on ia64 */
1359 hlen = (hdr.network[0] & 0x0F) << 2;
1360
1361 /* verify hlen meets minimum size requirements */
1362 if (hlen < sizeof(struct iphdr))
1363 return hdr.network - data;
1364
1365 /* record next protocol */
1366 nexthdr = hdr.ipv4->protocol;
1367 hdr.network += hlen;
1368#ifdef CONFIG_FCOE
1369 } else if (protocol == __constant_htons(ETH_P_FCOE)) {
1370 if ((hdr.network - data) > (max_len - FCOE_HEADER_LEN))
1371 return max_len;
1372 hdr.network += FCOE_HEADER_LEN;
1373#endif
1374 } else {
1375 return hdr.network - data;
1376 }
1377
1378 /* finally sort out TCP */
1379 if (nexthdr == IPPROTO_TCP) {
1380 if ((hdr.network - data) > (max_len - sizeof(struct tcphdr)))
1381 return max_len;
1382
1383 /* access doff as a u8 to avoid unaligned access on ia64 */
1384 hlen = (hdr.network[12] & 0xF0) >> 2;
1385
1386 /* verify hlen meets minimum size requirements */
1387 if (hlen < sizeof(struct tcphdr))
1388 return hdr.network - data;
1389
1390 hdr.network += hlen;
1391 }
1392
1393 /*
1394 * If everything has gone correctly hdr.network should be the
1395 * data section of the packet and will be the end of the header.
1396 * If not then it probably represents the end of the last recognized
1397 * header.
1398 */
1399 if ((hdr.network - data) < max_len)
1400 return hdr.network - data;
1401 else
1402 return max_len;
1403}
1404
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001405static void ixgbe_get_rsc_cnt(struct ixgbe_ring *rx_ring,
1406 union ixgbe_adv_rx_desc *rx_desc,
1407 struct sk_buff *skb)
1408{
1409 __le32 rsc_enabled;
1410 u32 rsc_cnt;
1411
1412 if (!ring_is_rsc_enabled(rx_ring))
1413 return;
1414
1415 rsc_enabled = rx_desc->wb.lower.lo_dword.data &
1416 cpu_to_le32(IXGBE_RXDADV_RSCCNT_MASK);
1417
1418 /* If this is an RSC frame rsc_cnt should be non-zero */
1419 if (!rsc_enabled)
1420 return;
1421
1422 rsc_cnt = le32_to_cpu(rsc_enabled);
1423 rsc_cnt >>= IXGBE_RXDADV_RSCCNT_SHIFT;
1424
1425 IXGBE_CB(skb)->append_cnt += rsc_cnt - 1;
Alexander Duyckaa801752010-11-16 19:27:02 -08001426}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001427
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001428static void ixgbe_set_rsc_gso_size(struct ixgbe_ring *ring,
1429 struct sk_buff *skb)
1430{
1431 u16 hdr_len = ixgbe_get_headlen(skb->data, skb_headlen(skb));
1432
1433 /* set gso_size to avoid messing up TCP MSS */
1434 skb_shinfo(skb)->gso_size = DIV_ROUND_UP((skb->len - hdr_len),
1435 IXGBE_CB(skb)->append_cnt);
1436}
1437
1438static void ixgbe_update_rsc_stats(struct ixgbe_ring *rx_ring,
1439 struct sk_buff *skb)
1440{
1441 /* if append_cnt is 0 then frame is not RSC */
1442 if (!IXGBE_CB(skb)->append_cnt)
1443 return;
1444
1445 rx_ring->rx_stats.rsc_count += IXGBE_CB(skb)->append_cnt;
1446 rx_ring->rx_stats.rsc_flush++;
1447
1448 ixgbe_set_rsc_gso_size(rx_ring, skb);
1449
1450 /* gso_size is computed using append_cnt so always clear it last */
1451 IXGBE_CB(skb)->append_cnt = 0;
1452}
1453
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001454static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001455 struct ixgbe_ring *rx_ring,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001456 int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07001457{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001458 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001459 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001460 struct ixgbe_rx_buffer *rx_buffer_info;
Auke Kok9a799d72007-09-15 14:07:45 -07001461 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001462 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001463 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001464#ifdef IXGBE_FCOE
1465 int ddp_bytes = 0;
1466#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001467 u16 i;
1468 u16 cleaned_count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001469
1470 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001471 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001472
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001473 while (ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_DD)) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001474 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001475
Milton Miller3c945e52010-02-19 17:44:42 +00001476 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001477
Alexander Duyckc267fc12010-11-16 19:27:00 -08001478 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1479
Auke Kok9a799d72007-09-15 14:07:45 -07001480 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001481 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001482 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001483
David S. Miller8decf862011-09-22 03:23:13 -04001484 /* linear means we are building an skb from multiple pages */
1485 if (!skb_is_nonlinear(skb)) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001486 u16 hlen;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001487 if (ring_is_ps_enabled(rx_ring)) {
1488 hlen = ixgbe_get_hlen(rx_desc);
1489 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1490 } else {
1491 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1492 }
1493
1494 skb_put(skb, hlen);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001495
1496 /*
1497 * Delay unmapping of the first packet. It carries the
1498 * header information, HW may still access the header
1499 * after writeback. Only unmap it when EOP is reached
1500 */
1501 if (!IXGBE_CB(skb)->head) {
1502 IXGBE_CB(skb)->delay_unmap = true;
1503 IXGBE_CB(skb)->dma = rx_buffer_info->dma;
1504 } else {
1505 skb = ixgbe_merge_active_tail(skb);
1506 dma_unmap_single(rx_ring->dev,
1507 rx_buffer_info->dma,
1508 rx_ring->rx_buf_len,
1509 DMA_FROM_DEVICE);
1510 }
1511 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001512 } else {
1513 /* assume packet split since header is unmapped */
1514 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001515 }
1516
1517 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001518 dma_unmap_page(rx_ring->dev,
1519 rx_buffer_info->page_dma,
1520 PAGE_SIZE / 2,
1521 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001522 rx_buffer_info->page_dma = 0;
1523 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001524 rx_buffer_info->page,
1525 rx_buffer_info->page_offset,
1526 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001527
Alexander Duyckc267fc12010-11-16 19:27:00 -08001528 if ((page_count(rx_buffer_info->page) == 1) &&
1529 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001530 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001531 else
1532 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001533
1534 skb->len += upper_len;
1535 skb->data_len += upper_len;
Eric Dumazet98130642011-10-13 07:59:41 +00001536 skb->truesize += PAGE_SIZE / 2;
Auke Kok9a799d72007-09-15 14:07:45 -07001537 }
1538
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001539 ixgbe_get_rsc_cnt(rx_ring, rx_desc, skb);
1540
Auke Kok9a799d72007-09-15 14:07:45 -07001541 i++;
1542 if (i == rx_ring->count)
1543 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001544
Alexander Duyck31f05a22010-08-19 13:40:31 +00001545 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001546 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001547 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001548
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001549 if ((!ixgbe_test_staterr(rx_desc, IXGBE_RXD_STAT_EOP))) {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001550 struct ixgbe_rx_buffer *next_buffer;
1551 u32 nextp;
1552
1553 if (IXGBE_CB(skb)->append_cnt) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001554 nextp = le32_to_cpu(
1555 rx_desc->wb.upper.status_error);
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001556 nextp >>= IXGBE_RXDADV_NEXTP_SHIFT;
1557 } else {
1558 nextp = i;
1559 }
1560
1561 next_buffer = &rx_ring->rx_buffer_info[nextp];
1562
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001563 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001564 rx_buffer_info->skb = next_buffer->skb;
1565 rx_buffer_info->dma = next_buffer->dma;
1566 next_buffer->skb = skb;
1567 next_buffer->dma = 0;
1568 } else {
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001569 struct sk_buff *next_skb = next_buffer->skb;
1570 ixgbe_add_active_tail(skb, next_skb);
1571 IXGBE_CB(next_skb)->head = skb;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001572 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001573 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001574 goto next_desc;
1575 }
1576
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001577 dma_unmap_single(rx_ring->dev,
1578 IXGBE_CB(skb)->dma,
1579 rx_ring->rx_buf_len,
1580 DMA_FROM_DEVICE);
1581 IXGBE_CB(skb)->dma = 0;
1582 IXGBE_CB(skb)->delay_unmap = false;
1583
1584 if (ixgbe_close_active_frag_list(skb) &&
1585 !IXGBE_CB(skb)->append_cnt) {
Alexander Duyckaa801752010-11-16 19:27:02 -08001586 /* if we got here without RSC the packet is invalid */
Alexander Duyck4c1975d2012-01-31 02:59:23 +00001587 dev_kfree_skb_any(skb);
1588 goto next_desc;
Alexander Duyckaa801752010-11-16 19:27:02 -08001589 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001590
Alexander Duyck1d2024f2012-01-31 02:59:29 +00001591 ixgbe_update_rsc_stats(rx_ring, skb);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001592
1593 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001594 if (unlikely(ixgbe_test_staterr(rx_desc,
1595 IXGBE_RXDADV_ERR_FRAME_ERR_MASK))) {
Alexander Duyckff886df2011-06-11 01:45:13 +00001596 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001597 goto next_desc;
1598 }
1599
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001600 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001601 if (adapter->netdev->features & NETIF_F_RXHASH)
1602 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001603
1604 /* probably a little skewed due to removing CRC */
1605 total_rx_bytes += skb->len;
1606 total_rx_packets++;
1607
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001608 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001609#ifdef IXGBE_FCOE
1610 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001611 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001612 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
David S. Miller823dcd22011-08-20 10:39:12 -07001613 if (!ddp_bytes) {
1614 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001615 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001616 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001617 }
Yi Zou332d4a72009-05-13 13:11:53 +00001618#endif /* IXGBE_FCOE */
Alexander Duyckf56e0cb2012-01-31 02:59:39 +00001619 ixgbe_receive_skb(q_vector, skb, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001620
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001621 budget--;
Auke Kok9a799d72007-09-15 14:07:45 -07001622next_desc:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001623 if (!budget)
Alexander Duyckc267fc12010-11-16 19:27:00 -08001624 break;
1625
Auke Kok9a799d72007-09-15 14:07:45 -07001626 /* return some buffers to hardware, one at a time is too slow */
1627 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001628 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001629 cleaned_count = 0;
1630 }
1631
1632 /* use prefetched values */
1633 rx_desc = next_rxd;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001634 }
1635
Auke Kok9a799d72007-09-15 14:07:45 -07001636 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001637 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001638
1639 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001640 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001641
Yi Zou3d8fd382009-06-08 14:38:44 +00001642#ifdef IXGBE_FCOE
1643 /* include DDPed FCoE data */
1644 if (ddp_bytes > 0) {
1645 unsigned int mss;
1646
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001647 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001648 sizeof(struct fc_frame_header) -
1649 sizeof(struct fcoe_crc_eof);
1650 if (mss > 512)
1651 mss &= ~511;
1652 total_rx_bytes += ddp_bytes;
1653 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1654 }
1655#endif /* IXGBE_FCOE */
1656
Alexander Duyckc267fc12010-11-16 19:27:00 -08001657 u64_stats_update_begin(&rx_ring->syncp);
1658 rx_ring->stats.packets += total_rx_packets;
1659 rx_ring->stats.bytes += total_rx_bytes;
1660 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001661 q_vector->rx.total_packets += total_rx_packets;
1662 q_vector->rx.total_bytes += total_rx_bytes;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00001663
1664 return !!budget;
Auke Kok9a799d72007-09-15 14:07:45 -07001665}
1666
Auke Kok9a799d72007-09-15 14:07:45 -07001667/**
1668 * ixgbe_configure_msix - Configure MSI-X hardware
1669 * @adapter: board private structure
1670 *
1671 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1672 * interrupts.
1673 **/
1674static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1675{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001676 struct ixgbe_q_vector *q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001677 int q_vectors, v_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001678 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001679
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001680 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1681
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00001682 /* Populate MSIX to EITR Select */
1683 if (adapter->num_vfs > 32) {
1684 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
1685 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
1686 }
1687
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001688 /*
1689 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001690 * corresponding register.
1691 */
1692 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001693 struct ixgbe_ring *ring;
Alexander Duyck7a921c92009-05-06 10:43:28 +00001694 q_vector = adapter->q_vector[v_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001695
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001696 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
1697 ixgbe_set_ivar(adapter, 0, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001698
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00001699 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
1700 ixgbe_set_ivar(adapter, 1, ring->reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001701
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001702 if (q_vector->tx.ring && !q_vector->rx.ring) {
1703 /* tx only vector */
1704 if (adapter->tx_itr_setting == 1)
1705 q_vector->itr = IXGBE_10K_ITR;
1706 else
1707 q_vector->itr = adapter->tx_itr_setting;
1708 } else {
1709 /* rx or rx/tx vector */
1710 if (adapter->rx_itr_setting == 1)
1711 q_vector->itr = IXGBE_20K_ITR;
1712 else
1713 q_vector->itr = adapter->rx_itr_setting;
1714 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001715
Alexander Duyckfe49f042009-06-04 16:00:09 +00001716 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07001717 }
1718
Alexander Duyckbd508172010-11-16 19:27:03 -08001719 switch (adapter->hw.mac.type) {
1720 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001721 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001722 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001723 break;
1724 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001725 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001726 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001727 break;
Alexander Duyckbd508172010-11-16 19:27:03 -08001728 default:
1729 break;
1730 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001731 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001732
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001733 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001734 mask = IXGBE_EIMS_ENABLE_MASK;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001735 mask &= ~(IXGBE_EIMS_OTHER |
1736 IXGBE_EIMS_MAILBOX |
1737 IXGBE_EIMS_LSC);
1738
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001739 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001740}
1741
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001742enum latency_range {
1743 lowest_latency = 0,
1744 low_latency = 1,
1745 bulk_latency = 2,
1746 latency_invalid = 255
1747};
1748
1749/**
1750 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001751 * @q_vector: structure containing interrupt and ring information
1752 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001753 *
1754 * Stores a new ITR value based on packets and byte
1755 * counts during the last interrupt. The advantage of per interrupt
1756 * computation is faster updates and more accurate ITR for the current
1757 * traffic pattern. Constants in this function were computed
1758 * based on theoretical maximum wire speed and thresholds were set based
1759 * on testing data as well as attempting to minimize response time
1760 * while increasing bulk throughput.
1761 * this functionality is controlled by the InterruptThrottleRate module
1762 * parameter (see ixgbe_param.c)
1763 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001764static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1765 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001766{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001767 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001768 struct ixgbe_adapter *adapter = q_vector->adapter;
1769 int bytes = ring_container->total_bytes;
1770 int packets = ring_container->total_packets;
1771 u32 timepassed_us;
1772 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001773
1774 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001775 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001776
1777 /* simple throttlerate management
1778 * 0-20MB/s lowest (100000 ints/s)
1779 * 20-100MB/s low (20000 ints/s)
1780 * 100-1249MB/s bulk (8000 ints/s)
1781 */
1782 /* what was last interrupt timeslice? */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001783 timepassed_us = q_vector->itr >> 2;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001784 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1785
1786 switch (itr_setting) {
1787 case lowest_latency:
1788 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001789 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001790 break;
1791 case low_latency:
1792 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001793 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001794 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001795 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001796 break;
1797 case bulk_latency:
1798 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001799 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001800 break;
1801 }
1802
Alexander Duyckbd198052011-06-11 01:45:08 +00001803 /* clear work counters since we have the values we need */
1804 ring_container->total_bytes = 0;
1805 ring_container->total_packets = 0;
1806
1807 /* write updated itr to ring container */
1808 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001809}
1810
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001811/**
1812 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001813 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001814 *
1815 * This function is made to be called by ethtool and by the driver
1816 * when it needs to update EITR registers at runtime. Hardware
1817 * specific quirks/differences are taken care of here.
1818 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001819void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001820{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001821 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001822 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001823 int v_idx = q_vector->v_idx;
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001824 u32 itr_reg = q_vector->itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001825
Alexander Duyckbd508172010-11-16 19:27:03 -08001826 switch (adapter->hw.mac.type) {
1827 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001828 /* must write high and low 16 bits to reset counter */
1829 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001830 break;
1831 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001832 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001833 /*
1834 * set the WDIS bit to not clear the timer bits and cause an
1835 * immediate assertion of the interrupt
1836 */
1837 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001838 break;
1839 default:
1840 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001841 }
1842 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1843}
1844
Alexander Duyckbd198052011-06-11 01:45:08 +00001845static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001846{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001847 u32 new_itr = q_vector->itr;
Alexander Duyckbd198052011-06-11 01:45:08 +00001848 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001849
Alexander Duyckbd198052011-06-11 01:45:08 +00001850 ixgbe_update_itr(q_vector, &q_vector->tx);
1851 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001852
Alexander Duyck08c88332011-06-11 01:45:03 +00001853 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001854
1855 switch (current_itr) {
1856 /* counts and packets in update_itr are dependent on these numbers */
1857 case lowest_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001858 new_itr = IXGBE_100K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001859 break;
1860 case low_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001861 new_itr = IXGBE_20K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001862 break;
1863 case bulk_latency:
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001864 new_itr = IXGBE_8K_ITR;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001865 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001866 default:
1867 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001868 }
1869
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001870 if (new_itr != q_vector->itr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001871 /* do an exponential smoothing */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001872 new_itr = (10 * new_itr * q_vector->itr) /
1873 ((9 * new_itr) + q_vector->itr);
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001874
Alexander Duyckbd198052011-06-11 01:45:08 +00001875 /* save the algorithm value here */
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00001876 q_vector->itr = new_itr & IXGBE_MAX_EITR;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001877
1878 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001879 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001880}
1881
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001882/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001883 * ixgbe_check_overtemp_subtask - check for over tempurature
1884 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001885 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001886static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001887{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001888 struct ixgbe_hw *hw = &adapter->hw;
1889 u32 eicr = adapter->interrupt_event;
1890
Alexander Duyckf0f97782011-04-22 04:08:09 +00001891 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001892 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001893
Alexander Duyckf0f97782011-04-22 04:08:09 +00001894 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1895 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1896 return;
1897
1898 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1899
Joe Perches7ca647b2010-09-07 21:35:40 +00001900 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001901 case IXGBE_DEV_ID_82599_T3_LOM:
1902 /*
1903 * Since the warning interrupt is for both ports
1904 * we don't have to check if:
1905 * - This interrupt wasn't for our port.
1906 * - We may have missed the interrupt so always have to
1907 * check if we got a LSC
1908 */
1909 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1910 !(eicr & IXGBE_EICR_LSC))
1911 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001912
Alexander Duyckf0f97782011-04-22 04:08:09 +00001913 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1914 u32 autoneg;
1915 bool link_up = false;
1916
Joe Perches7ca647b2010-09-07 21:35:40 +00001917 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1918
Alexander Duyckf0f97782011-04-22 04:08:09 +00001919 if (link_up)
1920 return;
1921 }
1922
1923 /* Check if this is not due to overtemp */
1924 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1925 return;
1926
1927 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001928 default:
1929 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1930 return;
1931 break;
1932 }
1933 e_crit(drv,
1934 "Network adapter has been stopped because it has over heated. "
1935 "Restart the computer. If the problem persists, "
1936 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001937
1938 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001939}
1940
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001941static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1942{
1943 struct ixgbe_hw *hw = &adapter->hw;
1944
1945 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1946 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001947 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001948 /* write to clear the interrupt */
1949 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1950 }
1951}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001952
Jacob Keller4f51bf72011-08-20 04:49:45 +00001953static void ixgbe_check_overtemp_event(struct ixgbe_adapter *adapter, u32 eicr)
1954{
1955 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1956 return;
1957
1958 switch (adapter->hw.mac.type) {
1959 case ixgbe_mac_82599EB:
1960 /*
1961 * Need to check link state so complete overtemp check
1962 * on service task
1963 */
1964 if (((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC)) &&
1965 (!test_bit(__IXGBE_DOWN, &adapter->state))) {
1966 adapter->interrupt_event = eicr;
1967 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1968 ixgbe_service_event_schedule(adapter);
1969 return;
1970 }
1971 return;
1972 case ixgbe_mac_X540:
1973 if (!(eicr & IXGBE_EICR_TS))
1974 return;
1975 break;
1976 default:
1977 return;
1978 }
1979
1980 e_crit(drv,
1981 "Network adapter has been stopped because it has over heated. "
1982 "Restart the computer. If the problem persists, "
1983 "power off the system and replace the adapter\n");
1984}
1985
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001986static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1987{
1988 struct ixgbe_hw *hw = &adapter->hw;
1989
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001990 if (eicr & IXGBE_EICR_GPI_SDP2) {
1991 /* Clear the interrupt */
1992 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001993 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1994 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1995 ixgbe_service_event_schedule(adapter);
1996 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001997 }
1998
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001999 if (eicr & IXGBE_EICR_GPI_SDP1) {
2000 /* Clear the interrupt */
2001 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00002002 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2003 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
2004 ixgbe_service_event_schedule(adapter);
2005 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002006 }
2007}
2008
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002009static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
2010{
2011 struct ixgbe_hw *hw = &adapter->hw;
2012
2013 adapter->lsc_int++;
2014 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
2015 adapter->link_check_timeout = jiffies;
2016 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2017 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00002018 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00002019 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002020 }
2021}
2022
Alexander Duyckfe49f042009-06-04 16:00:09 +00002023static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2024 u64 qmask)
2025{
2026 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002027 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002028
Alexander Duyckbd508172010-11-16 19:27:03 -08002029 switch (hw->mac.type) {
2030 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002031 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002032 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2033 break;
2034 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002035 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002036 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002037 if (mask)
2038 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002039 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002040 if (mask)
2041 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2042 break;
2043 default:
2044 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002045 }
2046 /* skip the flush */
2047}
2048
2049static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002050 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002051{
2052 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002053 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002054
Alexander Duyckbd508172010-11-16 19:27:03 -08002055 switch (hw->mac.type) {
2056 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002057 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002058 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2059 break;
2060 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002061 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002062 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002063 if (mask)
2064 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002065 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002066 if (mask)
2067 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2068 break;
2069 default:
2070 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002071 }
2072 /* skip the flush */
2073}
2074
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002075/**
Alexander Duyck2c4af692011-07-15 07:29:55 +00002076 * ixgbe_irq_enable - Enable default interrupt generation settings
2077 * @adapter: board private structure
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002078 **/
Alexander Duyck2c4af692011-07-15 07:29:55 +00002079static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2080 bool flush)
Auke Kok9a799d72007-09-15 14:07:45 -07002081{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002082 u32 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002083
Alexander Duyck2c4af692011-07-15 07:29:55 +00002084 /* don't reenable LSC while waiting for link */
2085 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
2086 mask &= ~IXGBE_EIMS_LSC;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002087
Alexander Duyck2c4af692011-07-15 07:29:55 +00002088 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Jacob Keller4f51bf72011-08-20 04:49:45 +00002089 switch (adapter->hw.mac.type) {
2090 case ixgbe_mac_82599EB:
2091 mask |= IXGBE_EIMS_GPI_SDP0;
2092 break;
2093 case ixgbe_mac_X540:
2094 mask |= IXGBE_EIMS_TS;
2095 break;
2096 default:
2097 break;
2098 }
Alexander Duyck2c4af692011-07-15 07:29:55 +00002099 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2100 mask |= IXGBE_EIMS_GPI_SDP1;
2101 switch (adapter->hw.mac.type) {
2102 case ixgbe_mac_82599EB:
Alexander Duyck2c4af692011-07-15 07:29:55 +00002103 mask |= IXGBE_EIMS_GPI_SDP1;
2104 mask |= IXGBE_EIMS_GPI_SDP2;
Don Skidmore858bc082011-08-04 09:28:30 +00002105 case ixgbe_mac_X540:
2106 mask |= IXGBE_EIMS_ECC;
Alexander Duyck2c4af692011-07-15 07:29:55 +00002107 mask |= IXGBE_EIMS_MAILBOX;
2108 break;
2109 default:
2110 break;
2111 }
2112 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2113 !(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
2114 mask |= IXGBE_EIMS_FLOW_DIR;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002115
Alexander Duyck2c4af692011-07-15 07:29:55 +00002116 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
2117 if (queues)
2118 ixgbe_irq_enable_queues(adapter, ~0);
2119 if (flush)
2120 IXGBE_WRITE_FLUSH(&adapter->hw);
Auke Kok9a799d72007-09-15 14:07:45 -07002121}
2122
Alexander Duyck2c4af692011-07-15 07:29:55 +00002123static irqreturn_t ixgbe_msix_other(int irq, void *data)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002124{
Alexander Duyck2c4af692011-07-15 07:29:55 +00002125 struct ixgbe_adapter *adapter = data;
2126 struct ixgbe_hw *hw = &adapter->hw;
2127 u32 eicr;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002128
Alexander Duyck2c4af692011-07-15 07:29:55 +00002129 /*
2130 * Workaround for Silicon errata. Use clear-by-write instead
2131 * of clear-by-read. Reading with EICS will return the
2132 * interrupt causes without clearing, which later be done
2133 * with the write to EICR.
2134 */
2135 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
2136 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002137
Alexander Duyck2c4af692011-07-15 07:29:55 +00002138 if (eicr & IXGBE_EICR_LSC)
2139 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002140
Alexander Duyck2c4af692011-07-15 07:29:55 +00002141 if (eicr & IXGBE_EICR_MAILBOX)
2142 ixgbe_msg_task(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002143
Alexander Duyck2c4af692011-07-15 07:29:55 +00002144 switch (hw->mac.type) {
2145 case ixgbe_mac_82599EB:
2146 case ixgbe_mac_X540:
2147 if (eicr & IXGBE_EICR_ECC)
2148 e_info(link, "Received unrecoverable ECC Err, please "
2149 "reboot\n");
2150 /* Handle Flow Director Full threshold interrupt */
2151 if (eicr & IXGBE_EICR_FLOW_DIR) {
2152 int reinit_count = 0;
2153 int i;
2154 for (i = 0; i < adapter->num_tx_queues; i++) {
2155 struct ixgbe_ring *ring = adapter->tx_ring[i];
2156 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
2157 &ring->state))
2158 reinit_count++;
2159 }
2160 if (reinit_count) {
2161 /* no more flow director interrupts until after init */
2162 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
2163 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
2164 ixgbe_service_event_schedule(adapter);
2165 }
2166 }
2167 ixgbe_check_sfp_event(adapter, eicr);
Jacob Keller4f51bf72011-08-20 04:49:45 +00002168 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyck2c4af692011-07-15 07:29:55 +00002169 break;
2170 default:
2171 break;
Auke Kok9a799d72007-09-15 14:07:45 -07002172 }
2173
Alexander Duyck2c4af692011-07-15 07:29:55 +00002174 ixgbe_check_fan_failure(adapter, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07002175
Alexander Duyck2c4af692011-07-15 07:29:55 +00002176 /* re-enable the original interrupt state, no lsc, no queues */
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002177 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck2c4af692011-07-15 07:29:55 +00002178 ixgbe_irq_enable(adapter, false, false);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002179
Alexander Duyck2c4af692011-07-15 07:29:55 +00002180 return IRQ_HANDLED;
2181}
2182
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002183static irqreturn_t ixgbe_msix_clean_rings(int irq, void *data)
Auke Kok9a799d72007-09-15 14:07:45 -07002184{
2185 struct ixgbe_q_vector *q_vector = data;
2186
Auke Kok9a799d72007-09-15 14:07:45 -07002187 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002188
2189 if (q_vector->rx.ring || q_vector->tx.ring)
2190 napi_schedule(&q_vector->napi);
Auke Kok9a799d72007-09-15 14:07:45 -07002191
2192 return IRQ_HANDLED;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002193}
2194
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002195static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002196 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002197{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002198 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002199 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002200
Alexander Duyck22745432010-11-16 19:27:10 -08002201 rx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002202 rx_ring->next = q_vector->rx.ring;
2203 q_vector->rx.ring = rx_ring;
2204 q_vector->rx.count++;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002205}
Auke Kok9a799d72007-09-15 14:07:45 -07002206
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002207static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002208 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002209{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002210 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002211 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002212
Alexander Duyck22745432010-11-16 19:27:10 -08002213 tx_ring->q_vector = q_vector;
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002214 tx_ring->next = q_vector->tx.ring;
2215 q_vector->tx.ring = tx_ring;
2216 q_vector->tx.count++;
Alexander Duyckbd198052011-06-11 01:45:08 +00002217 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002218}
Auke Kok9a799d72007-09-15 14:07:45 -07002219
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002220/**
2221 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2222 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002223 *
2224 * This function maps descriptor rings to the queue-specific vectors
2225 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2226 * one vector per ring/queue, but on a constrained vector budget, we
2227 * group the rings as "efficiently" as possible. You would add new
2228 * mapping configurations in here.
2229 **/
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002230static void ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002231{
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002232 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2233 int rxr_remaining = adapter->num_rx_queues, rxr_idx = 0;
2234 int txr_remaining = adapter->num_tx_queues, txr_idx = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002235 int v_start = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002236
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002237 /* only one q_vector if MSI-X is disabled. */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002238 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002239 q_vectors = 1;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002240
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002241 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002242 * If we don't have enough vectors for a 1-to-1 mapping, we'll have to
2243 * group them so there are multiple queues per vector.
2244 *
2245 * Re-adjusting *qpv takes care of the remainder.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002247 for (; v_start < q_vectors && rxr_remaining; v_start++) {
2248 int rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - v_start);
2249 for (; rqpv; rqpv--, rxr_idx++, rxr_remaining--)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002250 map_vector_to_rxq(adapter, v_start, rxr_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002251 }
2252
2253 /*
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002254 * If there are not enough q_vectors for each ring to have it's own
2255 * vector then we must pair up Rx/Tx on a each vector
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256 */
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002257 if ((v_start + txr_remaining) > q_vectors)
2258 v_start = 0;
2259
2260 for (; v_start < q_vectors && txr_remaining; v_start++) {
2261 int tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - v_start);
2262 for (; tqpv; tqpv--, txr_idx++, txr_remaining--)
2263 map_vector_to_txq(adapter, v_start, txr_idx);
Auke Kok9a799d72007-09-15 14:07:45 -07002264 }
Auke Kok9a799d72007-09-15 14:07:45 -07002265}
2266
2267/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2269 * @adapter: board private structure
2270 *
2271 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2272 * interrupts from the kernel.
2273 **/
2274static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2275{
2276 struct net_device *netdev = adapter->netdev;
Alexander Duyck207867f2011-07-15 03:05:37 +00002277 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2278 int vector, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002279 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002280
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002281 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002282 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
Alexander Duyck207867f2011-07-15 03:05:37 +00002283 struct msix_entry *entry = &adapter->msix_entries[vector];
Robert Olssoncb13fc22008-11-25 16:43:52 -08002284
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002285 if (q_vector->tx.ring && q_vector->rx.ring) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002286 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002287 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002288 ti++;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002289 } else if (q_vector->rx.ring) {
2290 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2291 "%s-%s-%d", netdev->name, "rx", ri++);
2292 } else if (q_vector->tx.ring) {
2293 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2294 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002295 } else {
2296 /* skip this unused q_vector */
2297 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002298 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002299 err = request_irq(entry->vector, &ixgbe_msix_clean_rings, 0,
2300 q_vector->name, q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002302 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002303 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002304 goto free_queue_irqs;
2305 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002306 /* If Flow Director is enabled, set interrupt affinity */
2307 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
2308 /* assign the mask for this irq */
2309 irq_set_affinity_hint(entry->vector,
2310 q_vector->affinity_mask);
2311 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312 }
2313
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyck2c4af692011-07-15 07:29:55 +00002315 ixgbe_msix_other, 0, netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002316 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002317 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002318 goto free_queue_irqs;
2319 }
2320
2321 return 0;
2322
2323free_queue_irqs:
Alexander Duyck207867f2011-07-15 03:05:37 +00002324 while (vector) {
2325 vector--;
2326 irq_set_affinity_hint(adapter->msix_entries[vector].vector,
2327 NULL);
2328 free_irq(adapter->msix_entries[vector].vector,
2329 adapter->q_vector[vector]);
2330 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002331 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2332 pci_disable_msix(adapter->pdev);
2333 kfree(adapter->msix_entries);
2334 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335 return err;
2336}
2337
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002338/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002339 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002340 * @irq: interrupt number
2341 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002342 **/
2343static irqreturn_t ixgbe_intr(int irq, void *data)
2344{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002345 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002346 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002347 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002348 u32 eicr;
2349
Don Skidmore54037502009-02-21 15:42:56 -08002350 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002351 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002352 * before the read of EICR.
2353 */
2354 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2355
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
Stephen Hemminger52f33af2011-12-22 16:34:52 +00002357 * therefore no explicit interrupt disable is necessary */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002358 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002359 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002360 /*
2361 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002362 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002363 * have disabled interrupts due to EIAM
2364 * finish the workaround of silicon errata on 82598. Unmask
2365 * the interrupt that we masked before the EICR read.
2366 */
2367 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2368 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002369 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002370 }
Auke Kok9a799d72007-09-15 14:07:45 -07002371
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002372 if (eicr & IXGBE_EICR_LSC)
2373 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002374
Alexander Duyckbd508172010-11-16 19:27:03 -08002375 switch (hw->mac.type) {
2376 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002377 ixgbe_check_sfp_event(adapter, eicr);
Don Skidmore0ccb9742011-08-04 02:07:48 +00002378 /* Fall through */
2379 case ixgbe_mac_X540:
2380 if (eicr & IXGBE_EICR_ECC)
2381 e_info(link, "Received unrecoverable ECC err, please "
2382 "reboot\n");
Jacob Keller4f51bf72011-08-20 04:49:45 +00002383 ixgbe_check_overtemp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002384 break;
2385 default:
2386 break;
2387 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002388
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002389 ixgbe_check_fan_failure(adapter, eicr);
2390
Alexander Duyck7a921c92009-05-06 10:43:28 +00002391 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002392 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002393 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002394 }
2395
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002396 /*
2397 * re-enable link(maybe) and non-queue interrupts, no flush.
2398 * ixgbe_poll will re-enable the queue interrupts
2399 */
2400
2401 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2402 ixgbe_irq_enable(adapter, false, false);
2403
Auke Kok9a799d72007-09-15 14:07:45 -07002404 return IRQ_HANDLED;
2405}
2406
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002407static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2408{
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002409 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2410 int i;
2411
2412 /* legacy and MSI only use one vector */
2413 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
2414 q_vectors = 1;
2415
2416 for (i = 0; i < adapter->num_rx_queues; i++) {
2417 adapter->rx_ring[i]->q_vector = NULL;
2418 adapter->rx_ring[i]->next = NULL;
2419 }
2420 for (i = 0; i < adapter->num_tx_queues; i++) {
2421 adapter->tx_ring[i]->q_vector = NULL;
2422 adapter->tx_ring[i]->next = NULL;
2423 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002424
2425 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002426 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00002427 memset(&q_vector->rx, 0, sizeof(struct ixgbe_ring_container));
2428 memset(&q_vector->tx, 0, sizeof(struct ixgbe_ring_container));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002429 }
2430}
2431
Auke Kok9a799d72007-09-15 14:07:45 -07002432/**
2433 * ixgbe_request_irq - initialize interrupts
2434 * @adapter: board private structure
2435 *
2436 * Attempts to configure interrupts using the best available
2437 * capabilities of the hardware and kernel.
2438 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002439static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002440{
2441 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002442 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002443
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002444 /* map all of the rings to the q_vectors */
2445 ixgbe_map_rings_to_vectors(adapter);
2446
2447 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002448 err = ixgbe_request_msix_irqs(adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002449 else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED)
Joe Perchesa0607fd2009-11-18 23:29:17 -08002450 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002451 netdev->name, adapter);
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002452 else
Joe Perchesa0607fd2009-11-18 23:29:17 -08002453 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002454 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002455
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002456 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002457 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002458
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002459 /* place q_vectors and rings back into a known good state */
2460 ixgbe_reset_q_vectors(adapter);
2461 }
2462
Auke Kok9a799d72007-09-15 14:07:45 -07002463 return err;
2464}
2465
2466static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2467{
Auke Kok9a799d72007-09-15 14:07:45 -07002468 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002469 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002470
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002471 q_vectors = adapter->num_msix_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002472 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002473 free_irq(adapter->msix_entries[i].vector, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002474 i--;
Alexander Duyck4cc6df22011-07-15 03:05:51 +00002475
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002476 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002477 /* free only the irqs that were actually requested */
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00002478 if (!adapter->q_vector[i]->rx.ring &&
2479 !adapter->q_vector[i]->tx.ring)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002480 continue;
2481
Alexander Duyck207867f2011-07-15 03:05:37 +00002482 /* clear the affinity_mask in the IRQ descriptor */
2483 irq_set_affinity_hint(adapter->msix_entries[i].vector,
2484 NULL);
2485
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002486 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002487 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002488 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002489 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002490 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002491 }
Alexander Duyck207867f2011-07-15 03:05:37 +00002492
2493 /* clear q_vector state information */
2494 ixgbe_reset_q_vectors(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002495}
2496
2497/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002498 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2499 * @adapter: board private structure
2500 **/
2501static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2502{
Alexander Duyckbd508172010-11-16 19:27:03 -08002503 switch (adapter->hw.mac.type) {
2504 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002505 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002506 break;
2507 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002508 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002509 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2510 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002511 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002512 break;
2513 default:
2514 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002515 }
2516 IXGBE_WRITE_FLUSH(&adapter->hw);
2517 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2518 int i;
2519 for (i = 0; i < adapter->num_msix_vectors; i++)
2520 synchronize_irq(adapter->msix_entries[i].vector);
2521 } else {
2522 synchronize_irq(adapter->pdev->irq);
2523 }
2524}
2525
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002526/**
Auke Kok9a799d72007-09-15 14:07:45 -07002527 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2528 *
2529 **/
2530static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2531{
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002532 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002533
Emil Tantilovd5bf4f62011-08-31 00:01:16 +00002534 /* rx/tx vector */
2535 if (adapter->rx_itr_setting == 1)
2536 q_vector->itr = IXGBE_20K_ITR;
2537 else
2538 q_vector->itr = adapter->rx_itr_setting;
2539
2540 ixgbe_write_eitr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002541
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002542 ixgbe_set_ivar(adapter, 0, 0, 0);
2543 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002544
Emil Tantilov396e7992010-07-01 20:05:12 +00002545 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002546}
2547
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002548/**
2549 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2550 * @adapter: board private structure
2551 * @ring: structure containing ring specific data
2552 *
2553 * Configure the Tx descriptor ring after a reset.
2554 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002555void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2556 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002557{
2558 struct ixgbe_hw *hw = &adapter->hw;
2559 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002560 int wait_loop = 10;
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002561 u32 txdctl = IXGBE_TXDCTL_ENABLE;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002562 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002563
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002564 /* disable queue to avoid issues while updating state */
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002565 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), 0);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002566 IXGBE_WRITE_FLUSH(hw);
2567
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002568 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002569 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002570 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2571 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2572 ring->count * sizeof(union ixgbe_adv_tx_desc));
2573 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2574 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002575 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002576
Alexander Duyckb88c6de2011-07-15 03:06:12 +00002577 /*
2578 * set WTHRESH to encourage burst writeback, it should not be set
2579 * higher than 1 when ITR is 0 as it could cause false TX hangs
2580 *
2581 * In order to avoid issues WTHRESH + PTHRESH should always be equal
2582 * to or less than the number of on chip descriptors, which is
2583 * currently 40.
2584 */
2585 if (!adapter->tx_itr_setting || !adapter->rx_itr_setting)
2586 txdctl |= (1 << 16); /* WTHRESH = 1 */
2587 else
2588 txdctl |= (8 << 16); /* WTHRESH = 8 */
2589
2590 /* PTHRESH=32 is needed to avoid a Tx hang with DFP enabled. */
2591 txdctl |= (1 << 8) | /* HTHRESH = 1 */
2592 32; /* PTHRESH = 32 */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002593
2594 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002595 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2596 adapter->atr_sample_rate) {
2597 ring->atr_sample_rate = adapter->atr_sample_rate;
2598 ring->atr_count = 0;
2599 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2600 } else {
2601 ring->atr_sample_rate = 0;
2602 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002603
John Fastabendc84d3242010-11-16 19:27:12 -08002604 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2605
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002606 /* enable queue */
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002607 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2608
2609 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2610 if (hw->mac.type == ixgbe_mac_82598EB &&
2611 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2612 return;
2613
2614 /* poll to verify queue is enabled */
2615 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002616 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002617 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2618 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2619 if (!wait_loop)
2620 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002621}
2622
Alexander Duyck120ff942010-08-19 13:34:50 +00002623static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2624{
2625 struct ixgbe_hw *hw = &adapter->hw;
2626 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002627 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002628 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002629
2630 if (hw->mac.type == ixgbe_mac_82598EB)
2631 return;
2632
2633 /* disable the arbiter while setting MTQC */
2634 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2635 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2636 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2637
2638 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002639 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002640 case (IXGBE_FLAG_SRIOV_ENABLED):
2641 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2642 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2643 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002644 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002645 if (!tcs)
2646 reg = IXGBE_MTQC_64Q_1PB;
2647 else if (tcs <= 4)
2648 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2649 else
2650 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2651
2652 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2653
2654 /* Enable Security TX Buffer IFG for multiple pb */
2655 if (tcs) {
2656 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2657 reg |= IXGBE_SECTX_DCB;
2658 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2659 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002660 break;
2661 }
2662
2663 /* re-enable the arbiter */
2664 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2665 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2666}
2667
Auke Kok9a799d72007-09-15 14:07:45 -07002668/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002669 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002670 * @adapter: board private structure
2671 *
2672 * Configure the Tx unit of the MAC after a reset.
2673 **/
2674static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2675{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002676 struct ixgbe_hw *hw = &adapter->hw;
2677 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002678 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002679
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002680 ixgbe_setup_mtqc(adapter);
2681
2682 if (hw->mac.type != ixgbe_mac_82598EB) {
2683 /* DMATXCTL.EN must be before Tx queues are enabled */
2684 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2685 dmatxctl |= IXGBE_DMATXCTL_TE;
2686 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2687 }
2688
Auke Kok9a799d72007-09-15 14:07:45 -07002689 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002690 for (i = 0; i < adapter->num_tx_queues; i++)
2691 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002692}
2693
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002694#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002695
Yi Zoua6616b42009-08-06 13:05:23 +00002696static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002697 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002698{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002699 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002700 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002701
Alexander Duyckbd508172010-11-16 19:27:03 -08002702 switch (adapter->hw.mac.type) {
2703 case ixgbe_mac_82598EB: {
2704 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2705 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002706 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002707 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002708 break;
2709 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002710 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002711 default:
2712 break;
2713 }
2714
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002715 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002716
2717 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2718 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002719 if (adapter->num_vfs)
2720 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002721
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002722 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2723 IXGBE_SRRCTL_BSIZEHDR_MASK;
2724
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002725 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002726#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2727 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2728#else
2729 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2730#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002731 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002732 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002733 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2734 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002735 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002736 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002737
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002738 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002739}
2740
Alexander Duyck05abb122010-08-19 13:35:41 +00002741static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002742{
Alexander Duyck05abb122010-08-19 13:35:41 +00002743 struct ixgbe_hw *hw = &adapter->hw;
2744 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002745 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2746 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002747 u32 mrqc = 0, reta = 0;
2748 u32 rxcsum;
2749 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002750 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002751 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2752
2753 if (tcs)
2754 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002755
Alexander Duyck05abb122010-08-19 13:35:41 +00002756 /* Fill out hash function seeds */
2757 for (i = 0; i < 10; i++)
2758 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002759
Alexander Duyck05abb122010-08-19 13:35:41 +00002760 /* Fill out redirection table */
2761 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002762 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002763 j = 0;
2764 /* reta = 4-byte sliding window of
2765 * 0x00..(indices-1)(indices-1)00..etc. */
2766 reta = (reta << 8) | (j * 0x11);
2767 if ((i & 3) == 3)
2768 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2769 }
2770
2771 /* Disable indicating checksum in descriptor, enables RSS hash */
2772 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2773 rxcsum |= IXGBE_RXCSUM_PCSD;
2774 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2775
John Fastabend8b1c0b22011-05-03 02:26:48 +00002776 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2777 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002778 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002779 } else {
2780 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2781 | IXGBE_FLAG_SRIOV_ENABLED);
2782
2783 switch (mask) {
2784 case (IXGBE_FLAG_RSS_ENABLED):
2785 if (!tcs)
2786 mrqc = IXGBE_MRQC_RSSEN;
2787 else if (tcs <= 4)
2788 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2789 else
2790 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2791 break;
2792 case (IXGBE_FLAG_SRIOV_ENABLED):
2793 mrqc = IXGBE_MRQC_VMDQEN;
2794 break;
2795 default:
2796 break;
2797 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002798 }
2799
Alexander Duyck05abb122010-08-19 13:35:41 +00002800 /* Perform hash on these packet types */
2801 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2802 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2803 | IXGBE_MRQC_RSS_FIELD_IPV6
2804 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2805
2806 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002807}
2808
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002809/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002810 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2811 * @adapter: address of board private structure
2812 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002813 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002814static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002815 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002816{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002817 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002818 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002819 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002820 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002821
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002822 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002823 return;
2824
2825 rx_buf_len = ring->rx_buf_len;
2826 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002827 rscctrl |= IXGBE_RSCCTL_RSCEN;
2828 /*
2829 * we must limit the number of descriptors so that the
2830 * total size of max desc * buf_len is not greater
2831 * than 65535
2832 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002833 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002834#if (MAX_SKB_FRAGS > 16)
2835 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2836#elif (MAX_SKB_FRAGS > 8)
2837 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2838#elif (MAX_SKB_FRAGS > 4)
2839 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2840#else
2841 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2842#endif
2843 } else {
Alexander Duyck919e78a2011-08-26 09:52:38 +00002844 if (rx_buf_len < IXGBE_RXBUFFER_4K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002845 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
Alexander Duyck919e78a2011-08-26 09:52:38 +00002846 else if (rx_buf_len < IXGBE_RXBUFFER_8K)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002847 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2848 else
2849 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2850 }
Alexander Duyck73670962010-08-19 13:38:34 +00002851 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002852}
2853
Alexander Duyck9e10e042010-08-19 13:40:06 +00002854/**
2855 * ixgbe_set_uta - Set unicast filter table address
2856 * @adapter: board private structure
2857 *
2858 * The unicast table address is a register array of 32-bit registers.
2859 * The table is meant to be used in a way similar to how the MTA is used
2860 * however due to certain limitations in the hardware it is necessary to
2861 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2862 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2863 **/
2864static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2865{
2866 struct ixgbe_hw *hw = &adapter->hw;
2867 int i;
2868
2869 /* The UTA table only exists on 82599 hardware and newer */
2870 if (hw->mac.type < ixgbe_mac_82599EB)
2871 return;
2872
2873 /* we only need to do this if VMDq is enabled */
2874 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2875 return;
2876
2877 for (i = 0; i < 128; i++)
2878 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2879}
2880
2881#define IXGBE_MAX_RX_DESC_POLL 10
2882static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2883 struct ixgbe_ring *ring)
2884{
2885 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002886 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2887 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002888 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002889
2890 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2891 if (hw->mac.type == ixgbe_mac_82598EB &&
2892 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2893 return;
2894
2895 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002896 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002897 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2898 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2899
2900 if (!wait_loop) {
2901 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2902 "the polling period\n", reg_idx);
2903 }
2904}
2905
Yi Zou2d39d572011-01-06 14:29:56 +00002906void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2907 struct ixgbe_ring *ring)
2908{
2909 struct ixgbe_hw *hw = &adapter->hw;
2910 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2911 u32 rxdctl;
2912 u8 reg_idx = ring->reg_idx;
2913
2914 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2915 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2916
2917 /* write value back with RXDCTL.ENABLE bit cleared */
2918 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2919
2920 if (hw->mac.type == ixgbe_mac_82598EB &&
2921 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2922 return;
2923
2924 /* the hardware may take up to 100us to really disable the rx queue */
2925 do {
2926 udelay(10);
2927 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2928 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2929
2930 if (!wait_loop) {
2931 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2932 "the polling period\n", reg_idx);
2933 }
2934}
2935
Alexander Duyck84418e32010-08-19 13:40:54 +00002936void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2937 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002938{
2939 struct ixgbe_hw *hw = &adapter->hw;
2940 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002941 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002942 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002943
Alexander Duyck9e10e042010-08-19 13:40:06 +00002944 /* disable queue to avoid issues while updating state */
2945 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00002946 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002947
Alexander Duyckacd37172010-08-19 13:36:05 +00002948 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
2949 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
2950 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
2951 ring->count * sizeof(union ixgbe_adv_rx_desc));
2952 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
2953 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002954 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002955
2956 ixgbe_configure_srrctl(adapter, ring);
2957 ixgbe_configure_rscctl(adapter, ring);
2958
Greg Rosee9f98072011-01-26 01:06:07 +00002959 /* If operating in IOV mode set RLPML for X540 */
2960 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
2961 hw->mac.type == ixgbe_mac_X540) {
2962 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
2963 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
2964 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
2965 }
2966
Alexander Duyck9e10e042010-08-19 13:40:06 +00002967 if (hw->mac.type == ixgbe_mac_82598EB) {
2968 /*
2969 * enable cache line friendly hardware writes:
2970 * PTHRESH=32 descriptors (half the internal cache),
2971 * this also removes ugly rx_no_buffer_count increment
2972 * HTHRESH=4 descriptors (to minimize latency on fetch)
2973 * WTHRESH=8 burst writeback up to two cache lines
2974 */
2975 rxdctl &= ~0x3FFFFF;
2976 rxdctl |= 0x080420;
2977 }
2978
2979 /* enable receive descriptor ring */
2980 rxdctl |= IXGBE_RXDCTL_ENABLE;
2981 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2982
2983 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00002984 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00002985}
2986
Alexander Duyck48654522010-08-19 13:36:27 +00002987static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
2988{
2989 struct ixgbe_hw *hw = &adapter->hw;
2990 int p;
2991
2992 /* PSRTYPE must be initialized in non 82598 adapters */
2993 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002994 IXGBE_PSRTYPE_UDPHDR |
2995 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00002996 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00002997 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00002998
2999 if (hw->mac.type == ixgbe_mac_82598EB)
3000 return;
3001
3002 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3003 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3004
3005 for (p = 0; p < adapter->num_rx_pools; p++)
3006 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3007 psrtype);
3008}
3009
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003010static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3011{
3012 struct ixgbe_hw *hw = &adapter->hw;
3013 u32 gcr_ext;
3014 u32 vt_reg_bits;
3015 u32 reg_offset, vf_shift;
3016 u32 vmdctl;
Greg Rosede4c7f62011-09-29 05:57:33 +00003017 int i;
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003018
3019 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3020 return;
3021
3022 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3023 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3024 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3025 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3026
3027 vf_shift = adapter->num_vfs % 32;
3028 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3029
3030 /* Enable only the PF's pool for Tx/Rx */
3031 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3032 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3033 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3034 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3035 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3036
3037 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3038 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3039
3040 /*
3041 * Set up VF register offsets for selected VT Mode,
3042 * i.e. 32 or 64 VFs for SR-IOV
3043 */
3044 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3045 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3046 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3047 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3048
3049 /* enable Tx loopback for VF/PF communication */
3050 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003051 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003052 hw->mac.ops.set_mac_anti_spoofing(hw,
Greg Rosede4c7f62011-09-29 05:57:33 +00003053 (adapter->num_vfs != 0),
Greg Rosea985b6c32010-11-18 03:02:52 +00003054 adapter->num_vfs);
Greg Rosede4c7f62011-09-29 05:57:33 +00003055 /* For VFs that have spoof checking turned off */
3056 for (i = 0; i < adapter->num_vfs; i++) {
3057 if (!adapter->vfinfo[i].spoofchk_enabled)
3058 ixgbe_ndo_set_vf_spoofchk(adapter->netdev, i, false);
3059 }
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003060}
3061
Alexander Duyck477de6e2010-08-19 13:38:11 +00003062static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003063{
Auke Kok9a799d72007-09-15 14:07:45 -07003064 struct ixgbe_hw *hw = &adapter->hw;
3065 struct net_device *netdev = adapter->netdev;
3066 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003067 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003068 struct ixgbe_ring *rx_ring;
3069 int i;
3070 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003071
Auke Kok9a799d72007-09-15 14:07:45 -07003072 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003073 /* On by default */
3074 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3075
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003076 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003077 if (adapter->num_vfs)
3078 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3079
3080 /* Disable packet split due to 82599 erratum #45 */
3081 if (hw->mac.type == ixgbe_mac_82599EB)
3082 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003083
Alexander Duyck477de6e2010-08-19 13:38:11 +00003084#ifdef IXGBE_FCOE
3085 /* adjust max frame to be able to do baby jumbo for FCoE */
3086 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3087 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3088 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3089
3090#endif /* IXGBE_FCOE */
3091 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3092 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3093 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3094 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3095
3096 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003097 }
3098
Alexander Duyck919e78a2011-08-26 09:52:38 +00003099 /* MHADD will allow an extra 4 bytes past for vlan tagged frames */
3100 max_frame += VLAN_HLEN;
3101
3102 /* Set the RX buffer length according to the mode */
3103 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
3104 rx_buf_len = IXGBE_RX_HDR_SIZE;
3105 } else {
3106 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
3107 (netdev->mtu <= ETH_DATA_LEN))
3108 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
3109 /*
3110 * Make best use of allocation by using all but 1K of a
3111 * power of 2 allocation that will be used for skb->head.
3112 */
3113 else if (max_frame <= IXGBE_RXBUFFER_3K)
3114 rx_buf_len = IXGBE_RXBUFFER_3K;
3115 else if (max_frame <= IXGBE_RXBUFFER_7K)
3116 rx_buf_len = IXGBE_RXBUFFER_7K;
3117 else if (max_frame <= IXGBE_RXBUFFER_15K)
3118 rx_buf_len = IXGBE_RXBUFFER_15K;
3119 else
3120 rx_buf_len = IXGBE_MAX_RXBUFFER;
3121 }
3122
Auke Kok9a799d72007-09-15 14:07:45 -07003123 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003124 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3125 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003126 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3127
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003128 /*
3129 * Setup the HW Rx Head and Tail Descriptor Pointers and
3130 * the Base and Length of the Rx Descriptor Ring
3131 */
Auke Kok9a799d72007-09-15 14:07:45 -07003132 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003133 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003134 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003135
Yi Zou6e455b892009-08-06 13:05:44 +00003136 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003137 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003138 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003139 clear_ring_ps_enabled(rx_ring);
3140
3141 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3142 set_ring_rsc_enabled(rx_ring);
3143 else
3144 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003145
Yi Zou63f39bd2009-05-17 12:34:35 +00003146#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003147 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003148 struct ixgbe_ring_feature *f;
3149 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003150 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003151 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003152 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3153 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003154 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003155 } else if (!ring_is_rsc_enabled(rx_ring) &&
3156 !ring_is_ps_enabled(rx_ring)) {
3157 rx_ring->rx_buf_len =
3158 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003159 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003160 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003161#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003162 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003163}
3164
Alexander Duyck73670962010-08-19 13:38:34 +00003165static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3166{
3167 struct ixgbe_hw *hw = &adapter->hw;
3168 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3169
3170 switch (hw->mac.type) {
3171 case ixgbe_mac_82598EB:
3172 /*
3173 * For VMDq support of different descriptor types or
3174 * buffer sizes through the use of multiple SRRCTL
3175 * registers, RDRXCTL.MVMEN must be set to 1
3176 *
3177 * also, the manual doesn't mention it clearly but DCA hints
3178 * will only use queue 0's tags unless this bit is set. Side
3179 * effects of setting this bit are only that SRRCTL must be
3180 * fully programmed [0..15]
3181 */
3182 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3183 break;
3184 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003185 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003186 /* Disable RSC for ACK packets */
3187 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3188 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3189 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3190 /* hardware requires some bits to be set by default */
3191 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3192 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3193 break;
3194 default:
3195 /* We should do nothing since we don't know this hardware */
3196 return;
3197 }
3198
3199 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3200}
3201
Alexander Duyck477de6e2010-08-19 13:38:11 +00003202/**
3203 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3204 * @adapter: board private structure
3205 *
3206 * Configure the Rx unit of the MAC after a reset.
3207 **/
3208static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3209{
3210 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003211 int i;
3212 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003213
3214 /* disable receives while setting up the descriptors */
3215 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3216 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3217
3218 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003219 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003220
Alexander Duyck9e10e042010-08-19 13:40:06 +00003221 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003222 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003223
Alexander Duyck9e10e042010-08-19 13:40:06 +00003224 ixgbe_set_uta(adapter);
3225
Alexander Duyck477de6e2010-08-19 13:38:11 +00003226 /* set_rx_buffer_len must be called before ring initialization */
3227 ixgbe_set_rx_buffer_len(adapter);
3228
3229 /*
3230 * Setup the HW Rx Head and Tail Descriptor Pointers and
3231 * the Base and Length of the Rx Descriptor Ring
3232 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003233 for (i = 0; i < adapter->num_rx_queues; i++)
3234 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003235
Alexander Duyck9e10e042010-08-19 13:40:06 +00003236 /* disable drop enable for 82598 parts */
3237 if (hw->mac.type == ixgbe_mac_82598EB)
3238 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3239
3240 /* enable all receives */
3241 rxctrl |= IXGBE_RXCTRL_RXEN;
3242 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003243}
3244
Jiri Pirko8e586132011-12-08 19:52:37 -05003245static int ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003246{
3247 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003248 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003249 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003250
3251 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003252 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003253 set_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003254
3255 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003256}
3257
Jiri Pirko8e586132011-12-08 19:52:37 -05003258static int ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
Auke Kok9a799d72007-09-15 14:07:45 -07003259{
3260 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003261 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003262 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003263
Auke Kok9a799d72007-09-15 14:07:45 -07003264 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003265 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003266 clear_bit(vid, adapter->active_vlans);
Jiri Pirko8e586132011-12-08 19:52:37 -05003267
3268 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07003269}
3270
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003271/**
3272 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3273 * @adapter: driver data
3274 */
3275static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3276{
3277 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003278 u32 vlnctrl;
3279
3280 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3281 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3282 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3283}
3284
3285/**
3286 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3287 * @adapter: driver data
3288 */
3289static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3290{
3291 struct ixgbe_hw *hw = &adapter->hw;
3292 u32 vlnctrl;
3293
3294 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3295 vlnctrl |= IXGBE_VLNCTRL_VFE;
3296 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3297 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3298}
3299
3300/**
3301 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3302 * @adapter: driver data
3303 */
3304static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3305{
3306 struct ixgbe_hw *hw = &adapter->hw;
3307 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003308 int i, j;
3309
3310 switch (hw->mac.type) {
3311 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003312 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3313 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003314 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3315 break;
3316 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003317 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003318 for (i = 0; i < adapter->num_rx_queues; i++) {
3319 j = adapter->rx_ring[i]->reg_idx;
3320 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3321 vlnctrl &= ~IXGBE_RXDCTL_VME;
3322 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3323 }
3324 break;
3325 default:
3326 break;
3327 }
3328}
3329
3330/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003331 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003332 * @adapter: driver data
3333 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003334static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003335{
3336 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003337 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003338 int i, j;
3339
3340 switch (hw->mac.type) {
3341 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003342 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3343 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003344 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3345 break;
3346 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003347 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003348 for (i = 0; i < adapter->num_rx_queues; i++) {
3349 j = adapter->rx_ring[i]->reg_idx;
3350 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3351 vlnctrl |= IXGBE_RXDCTL_VME;
3352 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3353 }
3354 break;
3355 default:
3356 break;
3357 }
3358}
3359
Auke Kok9a799d72007-09-15 14:07:45 -07003360static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3361{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003362 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003363
Jesse Grossf62bbb52010-10-20 13:56:10 +00003364 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3365
3366 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3367 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003368}
3369
3370/**
Alexander Duyck28500622010-06-15 09:25:48 +00003371 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3372 * @netdev: network interface device structure
3373 *
3374 * Writes unicast address list to the RAR table.
3375 * Returns: -ENOMEM on failure/insufficient address space
3376 * 0 on no addresses written
3377 * X on writing X addresses to the RAR table
3378 **/
3379static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3380{
3381 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3382 struct ixgbe_hw *hw = &adapter->hw;
3383 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003384 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003385 int count = 0;
3386
3387 /* return ENOMEM indicating insufficient memory for addresses */
3388 if (netdev_uc_count(netdev) > rar_entries)
3389 return -ENOMEM;
3390
3391 if (!netdev_uc_empty(netdev) && rar_entries) {
3392 struct netdev_hw_addr *ha;
3393 /* return error if we do not support writing to RAR table */
3394 if (!hw->mac.ops.set_rar)
3395 return -ENOMEM;
3396
3397 netdev_for_each_uc_addr(ha, netdev) {
3398 if (!rar_entries)
3399 break;
3400 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3401 vfn, IXGBE_RAH_AV);
3402 count++;
3403 }
3404 }
3405 /* write the addresses in reverse order to avoid write combining */
3406 for (; rar_entries > 0 ; rar_entries--)
3407 hw->mac.ops.clear_rar(hw, rar_entries);
3408
3409 return count;
3410}
3411
3412/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003413 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003414 * @netdev: network interface device structure
3415 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003416 * The set_rx_method entry point is called whenever the unicast/multicast
3417 * address list or the network interface flags are updated. This routine is
3418 * responsible for configuring the hardware for proper unicast, multicast and
3419 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003420 **/
Greg Rose7f870472010-01-09 02:25:29 +00003421void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003422{
3423 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3424 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003425 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3426 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003427
3428 /* Check for Promiscuous and All Multicast modes */
3429
3430 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3431
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003432 /* set all bits that we expect to always be set */
3433 fctrl |= IXGBE_FCTRL_BAM;
3434 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3435 fctrl |= IXGBE_FCTRL_PMCF;
3436
Alexander Duyck28500622010-06-15 09:25:48 +00003437 /* clear the bits we are changing the status of */
3438 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3439
Auke Kok9a799d72007-09-15 14:07:45 -07003440 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003441 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003442 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003443 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003444 /* don't hardware filter vlans in promisc mode */
3445 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003446 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003447 if (netdev->flags & IFF_ALLMULTI) {
3448 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003449 vmolr |= IXGBE_VMOLR_MPE;
3450 } else {
3451 /*
3452 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003453 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003454 * that we can at least receive multicast traffic
3455 */
3456 hw->mac.ops.update_mc_addr_list(hw, netdev);
3457 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003458 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003459 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003460 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003461 /*
3462 * Write addresses to available RAR registers, if there is not
3463 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003464 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003465 */
3466 count = ixgbe_write_uc_addr_list(netdev);
3467 if (count < 0) {
3468 fctrl |= IXGBE_FCTRL_UPE;
3469 vmolr |= IXGBE_VMOLR_ROPE;
3470 }
3471 }
3472
3473 if (adapter->num_vfs) {
3474 ixgbe_restore_vf_multicasts(adapter);
3475 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3476 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3477 IXGBE_VMOLR_ROPE);
3478 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003479 }
3480
3481 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003482
3483 if (netdev->features & NETIF_F_HW_VLAN_RX)
3484 ixgbe_vlan_strip_enable(adapter);
3485 else
3486 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003487}
3488
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003489static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3490{
3491 int q_idx;
3492 struct ixgbe_q_vector *q_vector;
3493 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3494
3495 /* legacy and MSI only use one vector */
3496 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3497 q_vectors = 1;
3498
3499 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003500 q_vector = adapter->q_vector[q_idx];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00003501 napi_enable(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003502 }
3503}
3504
3505static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3506{
3507 int q_idx;
3508 struct ixgbe_q_vector *q_vector;
3509 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3510
3511 /* legacy and MSI only use one vector */
3512 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3513 q_vectors = 1;
3514
3515 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003516 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003517 napi_disable(&q_vector->napi);
3518 }
3519}
3520
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003521#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003522/*
3523 * ixgbe_configure_dcb - Configure DCB hardware
3524 * @adapter: ixgbe adapter struct
3525 *
3526 * This is called by the driver on open to configure the DCB hardware.
3527 * This is also called by the gennetlink interface when reconfiguring
3528 * the DCB state.
3529 */
3530static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3531{
3532 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003533 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003534
Alexander Duyck67ebd792010-08-19 13:34:04 +00003535 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3536 if (hw->mac.type == ixgbe_mac_82598EB)
3537 netif_set_gso_max_size(adapter->netdev, 65536);
3538 return;
3539 }
3540
3541 if (hw->mac.type == ixgbe_mac_82598EB)
3542 netif_set_gso_max_size(adapter->netdev, 32768);
3543
Alexander Duyck2f90b862008-11-20 20:52:10 -08003544
Alexander Duyck2f90b862008-11-20 20:52:10 -08003545 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003546 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003547
Alexander Duyck2f90b862008-11-20 20:52:10 -08003548 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003549
John Fastabendb1208182011-10-15 05:00:10 +00003550#ifdef IXGBE_FCOE
3551 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3552 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3553#endif
3554
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003555 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003556 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003557 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3558 DCB_TX_CONFIG);
3559 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3560 DCB_RX_CONFIG);
3561 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
John Fastabendb1208182011-10-15 05:00:10 +00003562 } else if (adapter->ixgbe_ieee_ets && adapter->ixgbe_ieee_pfc) {
3563 ixgbe_dcb_hw_ets(&adapter->hw,
3564 adapter->ixgbe_ieee_ets,
3565 max_frame);
3566 ixgbe_dcb_hw_pfc_config(&adapter->hw,
3567 adapter->ixgbe_ieee_pfc->pfc_en,
3568 adapter->ixgbe_ieee_ets->prio_tc);
John Fastabendc27931d2011-02-23 05:58:25 +00003569 }
John Fastabend8187cd42011-02-23 05:58:08 +00003570
3571 /* Enable RSS Hash per TC */
3572 if (hw->mac.type != ixgbe_mac_82598EB) {
3573 int i;
3574 u32 reg = 0;
3575
3576 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3577 u8 msb = 0;
3578 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3579
3580 while (cnt >>= 1)
3581 msb++;
3582
3583 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3584 }
3585 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3586 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003587}
John Fastabend9da712d2011-08-23 03:14:22 +00003588#endif
3589
3590/* Additional bittime to account for IXGBE framing */
3591#define IXGBE_ETH_FRAMING 20
3592
3593/*
3594 * ixgbe_hpbthresh - calculate high water mark for flow control
3595 *
3596 * @adapter: board private structure to calculate for
3597 * @pb - packet buffer to calculate
3598 */
3599static int ixgbe_hpbthresh(struct ixgbe_adapter *adapter, int pb)
3600{
3601 struct ixgbe_hw *hw = &adapter->hw;
3602 struct net_device *dev = adapter->netdev;
3603 int link, tc, kb, marker;
3604 u32 dv_id, rx_pba;
3605
3606 /* Calculate max LAN frame size */
3607 tc = link = dev->mtu + ETH_HLEN + ETH_FCS_LEN + IXGBE_ETH_FRAMING;
3608
3609#ifdef IXGBE_FCOE
3610 /* FCoE traffic class uses FCOE jumbo frames */
3611 if (dev->features & NETIF_F_FCOE_MTU) {
3612 int fcoe_pb = 0;
3613
3614#ifdef CONFIG_IXGBE_DCB
3615 fcoe_pb = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003616
3617#endif
John Fastabend9da712d2011-08-23 03:14:22 +00003618 if (fcoe_pb == pb && tc < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3619 tc = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3620 }
3621#endif
3622
3623 /* Calculate delay value for device */
3624 switch (hw->mac.type) {
3625 case ixgbe_mac_X540:
3626 dv_id = IXGBE_DV_X540(link, tc);
3627 break;
3628 default:
3629 dv_id = IXGBE_DV(link, tc);
3630 break;
3631 }
3632
3633 /* Loopback switch introduces additional latency */
3634 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3635 dv_id += IXGBE_B2BT(tc);
3636
3637 /* Delay value is calculated in bit times convert to KB */
3638 kb = IXGBE_BT2KB(dv_id);
3639 rx_pba = IXGBE_READ_REG(hw, IXGBE_RXPBSIZE(pb)) >> 10;
3640
3641 marker = rx_pba - kb;
3642
3643 /* It is possible that the packet buffer is not large enough
3644 * to provide required headroom. In this case throw an error
3645 * to user and a do the best we can.
3646 */
3647 if (marker < 0) {
3648 e_warn(drv, "Packet Buffer(%i) can not provide enough"
3649 "headroom to support flow control."
3650 "Decrease MTU or number of traffic classes\n", pb);
3651 marker = tc + 1;
3652 }
3653
3654 return marker;
3655}
3656
3657/*
3658 * ixgbe_lpbthresh - calculate low water mark for for flow control
3659 *
3660 * @adapter: board private structure to calculate for
3661 * @pb - packet buffer to calculate
3662 */
3663static int ixgbe_lpbthresh(struct ixgbe_adapter *adapter)
3664{
3665 struct ixgbe_hw *hw = &adapter->hw;
3666 struct net_device *dev = adapter->netdev;
3667 int tc;
3668 u32 dv_id;
3669
3670 /* Calculate max LAN frame size */
3671 tc = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
3672
3673 /* Calculate delay value for device */
3674 switch (hw->mac.type) {
3675 case ixgbe_mac_X540:
3676 dv_id = IXGBE_LOW_DV_X540(tc);
3677 break;
3678 default:
3679 dv_id = IXGBE_LOW_DV(tc);
3680 break;
3681 }
3682
3683 /* Delay value is calculated in bit times convert to KB */
3684 return IXGBE_BT2KB(dv_id);
3685}
3686
3687/*
3688 * ixgbe_pbthresh_setup - calculate and setup high low water marks
3689 */
3690static void ixgbe_pbthresh_setup(struct ixgbe_adapter *adapter)
3691{
3692 struct ixgbe_hw *hw = &adapter->hw;
3693 int num_tc = netdev_get_num_tc(adapter->netdev);
3694 int i;
3695
3696 if (!num_tc)
3697 num_tc = 1;
3698
3699 hw->fc.low_water = ixgbe_lpbthresh(adapter);
3700
3701 for (i = 0; i < num_tc; i++) {
3702 hw->fc.high_water[i] = ixgbe_hpbthresh(adapter, i);
3703
3704 /* Low water marks must not be larger than high water marks */
3705 if (hw->fc.low_water > hw->fc.high_water[i])
3706 hw->fc.low_water = 0;
3707 }
3708}
John Fastabend80605c652011-05-02 12:34:10 +00003709
3710static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3711{
John Fastabend80605c652011-05-02 12:34:10 +00003712 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckf7e10272011-07-21 00:40:35 +00003713 int hdrm;
3714 u8 tc = netdev_get_num_tc(adapter->netdev);
John Fastabend80605c652011-05-02 12:34:10 +00003715
3716 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3717 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
Alexander Duyckf7e10272011-07-21 00:40:35 +00003718 hdrm = 32 << adapter->fdir_pballoc;
3719 else
3720 hdrm = 0;
John Fastabend80605c652011-05-02 12:34:10 +00003721
Alexander Duyckf7e10272011-07-21 00:40:35 +00003722 hw->mac.ops.set_rxpba(hw, tc, hdrm, PBA_STRATEGY_EQUAL);
John Fastabend9da712d2011-08-23 03:14:22 +00003723 ixgbe_pbthresh_setup(adapter);
John Fastabend80605c652011-05-02 12:34:10 +00003724}
3725
Alexander Duycke4911d52011-05-11 07:18:52 +00003726static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3727{
3728 struct ixgbe_hw *hw = &adapter->hw;
3729 struct hlist_node *node, *node2;
3730 struct ixgbe_fdir_filter *filter;
3731
3732 spin_lock(&adapter->fdir_perfect_lock);
3733
3734 if (!hlist_empty(&adapter->fdir_filter_list))
3735 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3736
3737 hlist_for_each_entry_safe(filter, node, node2,
3738 &adapter->fdir_filter_list, fdir_node) {
3739 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003740 &filter->filter,
3741 filter->sw_idx,
3742 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3743 IXGBE_FDIR_DROP_QUEUE :
3744 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003745 }
3746
3747 spin_unlock(&adapter->fdir_perfect_lock);
3748}
3749
Auke Kok9a799d72007-09-15 14:07:45 -07003750static void ixgbe_configure(struct ixgbe_adapter *adapter)
3751{
John Fastabend80605c652011-05-02 12:34:10 +00003752 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003753#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003754 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003755#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003756
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003757 ixgbe_set_rx_mode(adapter->netdev);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003758 ixgbe_restore_vlan(adapter);
3759
Yi Zoueacd73f2009-05-13 13:11:06 +00003760#ifdef IXGBE_FCOE
3761 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3762 ixgbe_configure_fcoe(adapter);
3763
3764#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003765 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003766 ixgbe_init_fdir_signature_82599(&adapter->hw,
3767 adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003768 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3769 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3770 adapter->fdir_pballoc);
3771 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003772 }
Alexander Duyck4c1d7b42011-07-21 00:40:30 +00003773
Alexander Duyck933d41f2010-09-07 21:34:29 +00003774 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003775
Auke Kok9a799d72007-09-15 14:07:45 -07003776 ixgbe_configure_tx(adapter);
3777 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003778}
3779
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003780static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3781{
3782 switch (hw->phy.type) {
3783 case ixgbe_phy_sfp_avago:
3784 case ixgbe_phy_sfp_ftl:
3785 case ixgbe_phy_sfp_intel:
3786 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003787 case ixgbe_phy_sfp_passive_tyco:
3788 case ixgbe_phy_sfp_passive_unknown:
3789 case ixgbe_phy_sfp_active_unknown:
3790 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003791 return true;
Alexander Duyck8917b442011-07-21 00:40:51 +00003792 case ixgbe_phy_nl:
3793 if (hw->mac.type == ixgbe_mac_82598EB)
3794 return true;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003795 default:
3796 return false;
3797 }
3798}
3799
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003800/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003801 * ixgbe_sfp_link_config - set up SFP+ link
3802 * @adapter: pointer to private adapter struct
3803 **/
3804static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3805{
Alexander Duyck70864002011-04-27 09:13:56 +00003806 /*
Stephen Hemminger52f33af2011-12-22 16:34:52 +00003807 * We are assuming the worst case scenario here, and that
Alexander Duyck70864002011-04-27 09:13:56 +00003808 * is that an SFP was inserted/removed after the reset
3809 * but before SFP detection was enabled. As such the best
3810 * solution is to just start searching as soon as we start
3811 */
3812 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3813 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003814
Alexander Duyck70864002011-04-27 09:13:56 +00003815 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003816}
3817
3818/**
3819 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003820 * @hw: pointer to private hardware struct
3821 *
3822 * Returns 0 on success, negative on failure
3823 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003824static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003825{
3826 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003827 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003828 u32 ret = IXGBE_ERR_LINK_SETUP;
3829
3830 if (hw->mac.ops.check_link)
3831 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3832
3833 if (ret)
3834 goto link_cfg_out;
3835
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003836 autoneg = hw->phy.autoneg_advertised;
3837 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003838 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3839 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003840 if (ret)
3841 goto link_cfg_out;
3842
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003843 if (hw->mac.ops.setup_link)
3844 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003845link_cfg_out:
3846 return ret;
3847}
3848
Alexander Duycka34bcff2010-08-19 13:39:20 +00003849static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003850{
Auke Kok9a799d72007-09-15 14:07:45 -07003851 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003852 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003853
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003854 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003855 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3856 IXGBE_GPIE_OCD;
3857 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003858 /*
3859 * use EIAM to auto-mask when MSI-X interrupt is asserted
3860 * this saves a register write for every interrupt
3861 */
3862 switch (hw->mac.type) {
3863 case ixgbe_mac_82598EB:
3864 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3865 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003866 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003867 case ixgbe_mac_X540:
3868 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003869 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3870 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3871 break;
3872 }
3873 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003874 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3875 * specifically only auto mask tx and rx interrupts */
3876 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003877 }
3878
Alexander Duycka34bcff2010-08-19 13:39:20 +00003879 /* XXX: to interrupt immediately for EICS writes, enable this */
3880 /* gpie |= IXGBE_GPIE_EIMEN; */
3881
3882 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3883 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3884 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003885 }
3886
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003887 /* Enable Thermal over heat sensor interrupt */
Don Skidmoref3df98e2011-08-17 10:15:21 +00003888 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) {
3889 switch (adapter->hw.mac.type) {
3890 case ixgbe_mac_82599EB:
3891 gpie |= IXGBE_SDP0_GPIEN;
3892 break;
3893 case ixgbe_mac_X540:
3894 gpie |= IXGBE_EIMS_TS;
3895 break;
3896 default:
3897 break;
3898 }
3899 }
Alexander Duyck5fdd31f2011-07-21 00:40:45 +00003900
Alexander Duycka34bcff2010-08-19 13:39:20 +00003901 /* Enable fan failure interrupt */
3902 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003903 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003904
Don Skidmore2698b202011-04-13 07:01:52 +00003905 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003906 gpie |= IXGBE_SDP1_GPIEN;
3907 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003908 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003909
3910 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3911}
3912
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003913static void ixgbe_up_complete(struct ixgbe_adapter *adapter)
Alexander Duycka34bcff2010-08-19 13:39:20 +00003914{
3915 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003916 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003917 u32 ctrl_ext;
3918
3919 ixgbe_get_hw_control(adapter);
3920 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003921
Auke Kok9a799d72007-09-15 14:07:45 -07003922 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3923 ixgbe_configure_msix(adapter);
3924 else
3925 ixgbe_configure_msi_and_legacy(adapter);
3926
Don Skidmorec6ecf392010-12-03 03:31:51 +00003927 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3928 if (hw->mac.ops.enable_tx_laser &&
3929 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003930 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003931 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003932 hw->mac.ops.enable_tx_laser(hw);
3933
Auke Kok9a799d72007-09-15 14:07:45 -07003934 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003935 ixgbe_napi_enable_all(adapter);
3936
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003937 if (ixgbe_is_sfp(hw)) {
3938 ixgbe_sfp_link_config(adapter);
3939 } else {
3940 err = ixgbe_non_sfp_link_config(hw);
3941 if (err)
3942 e_err(probe, "link_config FAILED %d\n", err);
3943 }
3944
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003945 /* clear any pending interrupts, may auto mask */
3946 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003947 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003948
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003949 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003950 * If this adapter has a fan, check to see if we had a failure
3951 * before we enabled the interrupt.
3952 */
3953 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3954 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3955 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003956 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003957 }
3958
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003959 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003960 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003961
Auke Kok9a799d72007-09-15 14:07:45 -07003962 /* bring the link up in the watchdog, this could race with our first
3963 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003964 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3965 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003966 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003967
3968 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3969 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3970 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3971 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
Auke Kok9a799d72007-09-15 14:07:45 -07003972}
3973
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003974void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3975{
3976 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003977 /* put off any impending NetWatchDogTimeout */
3978 adapter->netdev->trans_start = jiffies;
3979
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003980 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003981 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003982 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003983 /*
3984 * If SR-IOV enabled then wait a bit before bringing the adapter
3985 * back up to give the VFs time to respond to the reset. The
3986 * two second wait is based upon the watchdog timer cycle in
3987 * the VF driver.
3988 */
3989 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3990 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003991 ixgbe_up(adapter);
3992 clear_bit(__IXGBE_RESETTING, &adapter->state);
3993}
3994
Alexander Duyckc7ccde02011-07-21 00:40:40 +00003995void ixgbe_up(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003996{
3997 /* hardware has been reset, we need to reload some things */
3998 ixgbe_configure(adapter);
3999
Alexander Duyckc7ccde02011-07-21 00:40:40 +00004000 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004001}
4002
4003void ixgbe_reset(struct ixgbe_adapter *adapter)
4004{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004005 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004006 int err;
4007
Alexander Duyck70864002011-04-27 09:13:56 +00004008 /* lock SFP init bit to prevent race conditions with the watchdog */
4009 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4010 usleep_range(1000, 2000);
4011
4012 /* clear all SFP and link config related flags while holding SFP_INIT */
4013 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4014 IXGBE_FLAG2_SFP_NEEDS_RESET);
4015 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4016
Don Skidmore8ca783a2009-05-26 20:40:47 -07004017 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004018 switch (err) {
4019 case 0:
4020 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004021 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004022 break;
4023 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004024 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004025 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004026 case IXGBE_ERR_EEPROM_VERSION:
4027 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004028 e_dev_warn("This device is a pre-production adapter/LOM. "
Stephen Hemminger52f33af2011-12-22 16:34:52 +00004029 "Please be aware there may be issues associated with "
Emil Tantilov849c4542010-06-03 16:53:41 +00004030 "your hardware. If you are experiencing problems "
4031 "please contact your Intel or hardware "
4032 "representative who provided you with this "
4033 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004034 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004035 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004036 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004037 }
Auke Kok9a799d72007-09-15 14:07:45 -07004038
Alexander Duyck70864002011-04-27 09:13:56 +00004039 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4040
Auke Kok9a799d72007-09-15 14:07:45 -07004041 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004042 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4043 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004044}
4045
Auke Kok9a799d72007-09-15 14:07:45 -07004046/**
4047 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004048 * @rx_ring: ring to free buffers from
4049 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004050static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004051{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004052 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004053 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004054 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004055
Alexander Duyck84418e32010-08-19 13:40:54 +00004056 /* ring already cleared, nothing to do */
4057 if (!rx_ring->rx_buffer_info)
4058 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004059
Alexander Duyck84418e32010-08-19 13:40:54 +00004060 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004061 for (i = 0; i < rx_ring->count; i++) {
4062 struct ixgbe_rx_buffer *rx_buffer_info;
4063
4064 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4065 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004066 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004067 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004068 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004069 rx_buffer_info->dma = 0;
4070 }
4071 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004072 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004073 rx_buffer_info->skb = NULL;
Alexander Duyck4c1975d2012-01-31 02:59:23 +00004074 /* We need to clean up RSC frag lists */
4075 skb = ixgbe_merge_active_tail(skb);
4076 ixgbe_close_active_frag_list(skb);
4077 if (IXGBE_CB(skb)->delay_unmap) {
4078 dma_unmap_single(dev,
4079 IXGBE_CB(skb)->dma,
4080 rx_ring->rx_buf_len,
4081 DMA_FROM_DEVICE);
4082 IXGBE_CB(skb)->dma = 0;
4083 IXGBE_CB(skb)->delay_unmap = false;
4084 }
4085 dev_kfree_skb(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004086 }
4087 if (!rx_buffer_info->page)
4088 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004089 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004090 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004091 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004092 rx_buffer_info->page_dma = 0;
4093 }
Auke Kok9a799d72007-09-15 14:07:45 -07004094 put_page(rx_buffer_info->page);
4095 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004096 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004097 }
4098
4099 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4100 memset(rx_ring->rx_buffer_info, 0, size);
4101
4102 /* Zero out the descriptor ring */
4103 memset(rx_ring->desc, 0, rx_ring->size);
4104
4105 rx_ring->next_to_clean = 0;
4106 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004107}
4108
4109/**
4110 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004111 * @tx_ring: ring to be cleaned
4112 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004113static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004114{
4115 struct ixgbe_tx_buffer *tx_buffer_info;
4116 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004117 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004118
Alexander Duyck84418e32010-08-19 13:40:54 +00004119 /* ring already cleared, nothing to do */
4120 if (!tx_ring->tx_buffer_info)
4121 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004122
Alexander Duyck84418e32010-08-19 13:40:54 +00004123 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004124 for (i = 0; i < tx_ring->count; i++) {
4125 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004126 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004127 }
4128
4129 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4130 memset(tx_ring->tx_buffer_info, 0, size);
4131
4132 /* Zero out the descriptor ring */
4133 memset(tx_ring->desc, 0, tx_ring->size);
4134
4135 tx_ring->next_to_use = 0;
4136 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004137}
4138
4139/**
Auke Kok9a799d72007-09-15 14:07:45 -07004140 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4141 * @adapter: board private structure
4142 **/
4143static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4144{
4145 int i;
4146
4147 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004148 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004149}
4150
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004151/**
4152 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4153 * @adapter: board private structure
4154 **/
4155static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4156{
4157 int i;
4158
4159 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004160 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004161}
4162
Alexander Duycke4911d52011-05-11 07:18:52 +00004163static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4164{
4165 struct hlist_node *node, *node2;
4166 struct ixgbe_fdir_filter *filter;
4167
4168 spin_lock(&adapter->fdir_perfect_lock);
4169
4170 hlist_for_each_entry_safe(filter, node, node2,
4171 &adapter->fdir_filter_list, fdir_node) {
4172 hlist_del(&filter->fdir_node);
4173 kfree(filter);
4174 }
4175 adapter->fdir_filter_count = 0;
4176
4177 spin_unlock(&adapter->fdir_perfect_lock);
4178}
4179
Auke Kok9a799d72007-09-15 14:07:45 -07004180void ixgbe_down(struct ixgbe_adapter *adapter)
4181{
4182 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004183 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004184 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004185 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07004186
4187 /* signal that we are down to the interrupt handler */
4188 set_bit(__IXGBE_DOWN, &adapter->state);
4189
4190 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004191 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4192 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004193
Yi Zou2d39d572011-01-06 14:29:56 +00004194 /* disable all enabled rx queues */
4195 for (i = 0; i < adapter->num_rx_queues; i++)
4196 /* this call also flushes the previous write */
4197 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4198
Don Skidmore032b4322011-03-18 09:32:53 +00004199 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004200
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004201 netif_tx_stop_all_queues(netdev);
4202
Alexander Duyck70864002011-04-27 09:13:56 +00004203 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004204 netif_carrier_off(netdev);
4205 netif_tx_disable(netdev);
4206
4207 ixgbe_irq_disable(adapter);
4208
4209 ixgbe_napi_disable_all(adapter);
4210
Alexander Duyckd034acf2011-04-27 09:25:34 +00004211 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4212 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004213 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4214
4215 del_timer_sync(&adapter->service_timer);
4216
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004217 if (adapter->num_vfs) {
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004218 /* Clear EITR Select mapping */
4219 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
4220
4221 /* Mark all the VFs as inactive */
4222 for (i = 0 ; i < adapter->num_vfs; i++)
Rusty Russell3db1cd52011-12-19 13:56:45 +00004223 adapter->vfinfo[i].clear_to_send = false;
Alexander Duyck8e34d1a2011-07-15 07:29:49 +00004224
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004225 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004226 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004227
Auke Kok9a799d72007-09-15 14:07:45 -07004228 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004229 ixgbe_disable_tx_rx(adapter);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004230 }
4231
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004232 /* disable transmits in the hardware now that interrupts are off */
4233 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004234 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004235 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004236 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004237
4238 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004239 switch (hw->mac.type) {
4240 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004241 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004242 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004243 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4244 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004245 break;
4246 default:
4247 break;
4248 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004249
Paul Larson6f4a0e42008-06-24 17:00:56 -07004250 if (!pci_channel_offline(adapter->pdev))
4251 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004252
4253 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4254 if (hw->mac.ops.disable_tx_laser &&
4255 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004256 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004257 (hw->mac.type == ixgbe_mac_82599EB))))
4258 hw->mac.ops.disable_tx_laser(hw);
4259
Auke Kok9a799d72007-09-15 14:07:45 -07004260 ixgbe_clean_all_tx_rings(adapter);
4261 ixgbe_clean_all_rx_rings(adapter);
4262
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004263#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004264 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004265 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004266#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004267}
4268
Auke Kok9a799d72007-09-15 14:07:45 -07004269/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004270 * ixgbe_poll - NAPI Rx polling callback
4271 * @napi: structure for representing this polling device
4272 * @budget: how many packets driver is allowed to clean
4273 *
4274 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004275 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004276static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004277{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004278 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004279 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004280 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004281 struct ixgbe_ring *ring;
4282 int per_ring_budget;
4283 bool clean_complete = true;
Auke Kok9a799d72007-09-15 14:07:45 -07004284
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004285#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004286 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4287 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004288#endif
4289
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004290 for (ring = q_vector->tx.ring; ring != NULL; ring = ring->next)
4291 clean_complete &= !!ixgbe_clean_tx_irq(q_vector, ring);
Auke Kok9a799d72007-09-15 14:07:45 -07004292
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004293 /* attempt to distribute budget to each queue fairly, but don't allow
4294 * the budget to go below 1 because we'll exit polling */
4295 if (q_vector->rx.count > 1)
4296 per_ring_budget = max(budget/q_vector->rx.count, 1);
4297 else
4298 per_ring_budget = budget;
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004299
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004300 for (ring = q_vector->rx.ring; ring != NULL; ring = ring->next)
4301 clean_complete &= ixgbe_clean_rx_irq(q_vector, ring,
4302 per_ring_budget);
4303
4304 /* If all work not completed, return budget and keep polling */
4305 if (!clean_complete)
4306 return budget;
4307
4308 /* all work done, exit the polling mode */
4309 napi_complete(napi);
4310 if (adapter->rx_itr_setting & 1)
4311 ixgbe_set_itr(q_vector);
4312 if (!test_bit(__IXGBE_DOWN, &adapter->state))
4313 ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx));
4314
4315 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004316}
4317
4318/**
4319 * ixgbe_tx_timeout - Respond to a Tx Hang
4320 * @netdev: network interface device structure
4321 **/
4322static void ixgbe_tx_timeout(struct net_device *netdev)
4323{
4324 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4325
4326 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004327 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004328}
4329
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004330/**
4331 * ixgbe_set_rss_queues: Allocate queues for RSS
4332 * @adapter: board private structure to initialize
4333 *
4334 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4335 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4336 *
4337 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004338static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4339{
4340 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004341 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004342
4343 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004344 f->mask = 0xF;
4345 adapter->num_rx_queues = f->indices;
4346 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004347 ret = true;
4348 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004349 ret = false;
4350 }
4351
4352 return ret;
4353}
4354
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004355/**
4356 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4357 * @adapter: board private structure to initialize
4358 *
4359 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4360 * to the original CPU that initiated the Tx session. This runs in addition
4361 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4362 * Rx load across CPUs using RSS.
4363 *
4364 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004365static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004366{
4367 bool ret = false;
4368 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4369
4370 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4371 f_fdir->mask = 0;
4372
4373 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004374 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4375 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004376 adapter->num_tx_queues = f_fdir->indices;
4377 adapter->num_rx_queues = f_fdir->indices;
4378 ret = true;
4379 } else {
4380 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004381 }
4382 return ret;
4383}
4384
Yi Zou0331a832009-05-17 12:33:52 +00004385#ifdef IXGBE_FCOE
4386/**
4387 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4388 * @adapter: board private structure to initialize
4389 *
4390 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4391 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4392 * rx queues out of the max number of rx queues, instead, it is used as the
4393 * index of the first rx queue used by FCoE.
4394 *
4395 **/
4396static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4397{
Yi Zou0331a832009-05-17 12:33:52 +00004398 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4399
John Fastabende5b64632011-03-08 03:44:52 +00004400 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4401 return false;
4402
John Fastabende901acd2011-04-26 07:26:08 +00004403 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004404
John Fastabende901acd2011-04-26 07:26:08 +00004405 adapter->num_rx_queues = 1;
4406 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004407
John Fastabende901acd2011-04-26 07:26:08 +00004408 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4409 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004410 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004411 ixgbe_set_fdir_queues(adapter);
4412 else
4413 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004414 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004415
John Fastabende901acd2011-04-26 07:26:08 +00004416 /* adding FCoE rx rings to the end */
4417 f->mask = adapter->num_rx_queues;
4418 adapter->num_rx_queues += f->indices;
4419 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004420
John Fastabende5b64632011-03-08 03:44:52 +00004421 return true;
4422}
4423#endif /* IXGBE_FCOE */
4424
John Fastabende901acd2011-04-26 07:26:08 +00004425/* Artificial max queue cap per traffic class in DCB mode */
4426#define DCB_QUEUE_CAP 8
4427
John Fastabende5b64632011-03-08 03:44:52 +00004428#ifdef CONFIG_IXGBE_DCB
4429static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4430{
John Fastabende901acd2011-04-26 07:26:08 +00004431 int per_tc_q, q, i, offset = 0;
4432 struct net_device *dev = adapter->netdev;
4433 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004434
John Fastabende901acd2011-04-26 07:26:08 +00004435 if (!tcs)
4436 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004437
John Fastabende901acd2011-04-26 07:26:08 +00004438 /* Map queue offset and counts onto allocated tx queues */
4439 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4440 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004441
John Fastabend8b1c0b22011-05-03 02:26:48 +00004442 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004443 netdev_set_tc_queue(dev, i, q, offset);
4444 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004445 }
4446
John Fastabende901acd2011-04-26 07:26:08 +00004447 adapter->num_tx_queues = q * tcs;
4448 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004449
4450#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004451 /* FCoE enabled queues require special configuration indexed
4452 * by feature specific indices and mask. Here we map FCoE
4453 * indices onto the DCB queue pairs allowing FCoE to own
4454 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004455 */
John Fastabende901acd2011-04-26 07:26:08 +00004456 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4457 int tc;
4458 struct ixgbe_ring_feature *f =
4459 &adapter->ring_feature[RING_F_FCOE];
4460
4461 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4462 f->indices = dev->tc_to_txq[tc].count;
4463 f->mask = dev->tc_to_txq[tc].offset;
4464 }
John Fastabende5b64632011-03-08 03:44:52 +00004465#endif
4466
John Fastabende901acd2011-04-26 07:26:08 +00004467 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004468}
John Fastabende5b64632011-03-08 03:44:52 +00004469#endif
Yi Zou0331a832009-05-17 12:33:52 +00004470
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004471/**
4472 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4473 * @adapter: board private structure to initialize
4474 *
4475 * IOV doesn't actually use anything, so just NAK the
4476 * request for now and let the other queue routines
4477 * figure out what to do.
4478 */
4479static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4480{
4481 return false;
4482}
4483
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004484/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004485 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004486 * @adapter: board private structure to initialize
4487 *
4488 * This is the top level queue allocation routine. The order here is very
4489 * important, starting with the "most" number of features turned on at once,
4490 * and ending with the smallest set of features. This way large combinations
4491 * can be allocated if they're turned on, and smaller combinations are the
4492 * fallthrough conditions.
4493 *
4494 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004495static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004496{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004497 /* Start with base case */
4498 adapter->num_rx_queues = 1;
4499 adapter->num_tx_queues = 1;
4500 adapter->num_rx_pools = adapter->num_rx_queues;
4501 adapter->num_rx_queues_per_pool = 1;
4502
4503 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004504 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004505
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004506#ifdef CONFIG_IXGBE_DCB
4507 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004508 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004509
4510#endif
John Fastabende5b64632011-03-08 03:44:52 +00004511#ifdef IXGBE_FCOE
4512 if (ixgbe_set_fcoe_queues(adapter))
4513 goto done;
4514
4515#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004516 if (ixgbe_set_fdir_queues(adapter))
4517 goto done;
4518
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004519 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004520 goto done;
4521
4522 /* fallback to base case */
4523 adapter->num_rx_queues = 1;
4524 adapter->num_tx_queues = 1;
4525
4526done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004527 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004528 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004529 return netif_set_real_num_rx_queues(adapter->netdev,
4530 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004531}
4532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004533static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004534 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004535{
4536 int err, vector_threshold;
4537
4538 /* We'll want at least 3 (vector_threshold):
4539 * 1) TxQ[0] Cleanup
4540 * 2) RxQ[0] Cleanup
4541 * 3) Other (Link Status Change, etc.)
4542 * 4) TCP Timer (optional)
4543 */
4544 vector_threshold = MIN_MSIX_COUNT;
4545
4546 /* The more we get, the more we will assign to Tx/Rx Cleanup
4547 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4548 * Right now, we simply care about how many we'll get; we'll
4549 * set them up later while requesting irq's.
4550 */
4551 while (vectors >= vector_threshold) {
4552 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004553 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554 if (!err) /* Success in acquiring all requested vectors. */
4555 break;
4556 else if (err < 0)
4557 vectors = 0; /* Nasty failure, quit now */
4558 else /* err == number of vectors we should try again with */
4559 vectors = err;
4560 }
4561
4562 if (vectors < vector_threshold) {
4563 /* Can't allocate enough MSI-X interrupts? Oh well.
4564 * This just means we'll go with either a single MSI
4565 * vector or fall back to legacy interrupts.
4566 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004567 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4568 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004569 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4570 kfree(adapter->msix_entries);
4571 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004572 } else {
4573 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004574 /*
4575 * Adjust for only the vectors we'll use, which is minimum
4576 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4577 * vectors we were allocated.
4578 */
4579 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004580 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004581 }
4582}
4583
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004584/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004585 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004586 * @adapter: board private structure to initialize
4587 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004588 * Cache the descriptor ring offsets for RSS to the assigned rings.
4589 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004590 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004591static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004592{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004593 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004594
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004595 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4596 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004597
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004598 for (i = 0; i < adapter->num_rx_queues; i++)
4599 adapter->rx_ring[i]->reg_idx = i;
4600 for (i = 0; i < adapter->num_tx_queues; i++)
4601 adapter->tx_ring[i]->reg_idx = i;
4602
4603 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004604}
4605
4606#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004607
4608/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004609static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4610 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004611{
4612 struct net_device *dev = adapter->netdev;
4613 struct ixgbe_hw *hw = &adapter->hw;
4614 u8 num_tcs = netdev_get_num_tc(dev);
4615
4616 *tx = 0;
4617 *rx = 0;
4618
4619 switch (hw->mac.type) {
4620 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004621 *tx = tc << 2;
4622 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004623 break;
4624 case ixgbe_mac_82599EB:
4625 case ixgbe_mac_X540:
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004626 if (num_tcs > 4) {
John Fastabende5b64632011-03-08 03:44:52 +00004627 if (tc < 3) {
4628 *tx = tc << 5;
4629 *rx = tc << 4;
4630 } else if (tc < 5) {
4631 *tx = ((tc + 2) << 4);
4632 *rx = tc << 4;
4633 } else if (tc < num_tcs) {
4634 *tx = ((tc + 8) << 3);
4635 *rx = tc << 4;
4636 }
John Fastabend4fa2e0e2011-07-18 22:38:25 +00004637 } else {
John Fastabende5b64632011-03-08 03:44:52 +00004638 *rx = tc << 5;
4639 switch (tc) {
4640 case 0:
4641 *tx = 0;
4642 break;
4643 case 1:
4644 *tx = 64;
4645 break;
4646 case 2:
4647 *tx = 96;
4648 break;
4649 case 3:
4650 *tx = 112;
4651 break;
4652 default:
4653 break;
4654 }
4655 }
4656 break;
4657 default:
4658 break;
4659 }
4660}
4661
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004662/**
4663 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4664 * @adapter: board private structure to initialize
4665 *
4666 * Cache the descriptor ring offsets for DCB to the assigned rings.
4667 *
4668 **/
4669static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4670{
John Fastabende5b64632011-03-08 03:44:52 +00004671 struct net_device *dev = adapter->netdev;
4672 int i, j, k;
4673 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004674
John Fastabend8b1c0b22011-05-03 02:26:48 +00004675 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004676 return false;
4677
John Fastabende5b64632011-03-08 03:44:52 +00004678 for (i = 0, k = 0; i < num_tcs; i++) {
4679 unsigned int tx_s, rx_s;
4680 u16 count = dev->tc_to_txq[i].count;
4681
4682 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4683 for (j = 0; j < count; j++, k++) {
4684 adapter->tx_ring[k]->reg_idx = tx_s + j;
4685 adapter->rx_ring[k]->reg_idx = rx_s + j;
4686 adapter->tx_ring[k]->dcb_tc = i;
4687 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004688 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004689 }
John Fastabende5b64632011-03-08 03:44:52 +00004690
4691 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004692}
4693#endif
4694
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004695/**
4696 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4697 * @adapter: board private structure to initialize
4698 *
4699 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4700 *
4701 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004702static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004703{
4704 int i;
4705 bool ret = false;
4706
Alexander Duyck03ecf912011-05-20 07:36:17 +00004707 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4708 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004709 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004710 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004711 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004712 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004713 ret = true;
4714 }
4715
4716 return ret;
4717}
4718
Yi Zou0331a832009-05-17 12:33:52 +00004719#ifdef IXGBE_FCOE
4720/**
4721 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4722 * @adapter: board private structure to initialize
4723 *
4724 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4725 *
4726 */
4727static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4728{
Yi Zou0331a832009-05-17 12:33:52 +00004729 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004730 int i;
4731 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004732
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004733 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4734 return false;
4735
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004736 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004737 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004738 ixgbe_cache_ring_fdir(adapter);
4739 else
4740 ixgbe_cache_ring_rss(adapter);
4741
4742 fcoe_rx_i = f->mask;
4743 fcoe_tx_i = f->mask;
4744 }
4745 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4746 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4747 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4748 }
4749 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004750}
4751
4752#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004753/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004754 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4755 * @adapter: board private structure to initialize
4756 *
4757 * SR-IOV doesn't use any descriptor rings but changes the default if
4758 * no other mapping is used.
4759 *
4760 */
4761static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4762{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004763 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4764 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004765 if (adapter->num_vfs)
4766 return true;
4767 else
4768 return false;
4769}
4770
4771/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004772 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4773 * @adapter: board private structure to initialize
4774 *
4775 * Once we know the feature-set enabled for the device, we'll cache
4776 * the register offset the descriptor ring is assigned to.
4777 *
4778 * Note, the order the various feature calls is important. It must start with
4779 * the "most" features enabled at the same time, then trickle down to the
4780 * least amount of features turned on at once.
4781 **/
4782static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4783{
4784 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004785 adapter->rx_ring[0]->reg_idx = 0;
4786 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004787
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004788 if (ixgbe_cache_ring_sriov(adapter))
4789 return;
4790
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004791#ifdef CONFIG_IXGBE_DCB
4792 if (ixgbe_cache_ring_dcb(adapter))
4793 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004794#endif
John Fastabende5b64632011-03-08 03:44:52 +00004795
4796#ifdef IXGBE_FCOE
4797 if (ixgbe_cache_ring_fcoe(adapter))
4798 return;
4799#endif /* IXGBE_FCOE */
4800
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004801 if (ixgbe_cache_ring_fdir(adapter))
4802 return;
4803
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004804 if (ixgbe_cache_ring_rss(adapter))
4805 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004806}
4807
Auke Kok9a799d72007-09-15 14:07:45 -07004808/**
4809 * ixgbe_alloc_queues - Allocate memory for all rings
4810 * @adapter: board private structure to initialize
4811 *
4812 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004813 * number of queues at compile-time. The polling_netdev array is
4814 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004815 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004816static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004817{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004818 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004819
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004820 if (nid < 0 || !node_online(nid))
4821 nid = first_online_node;
4822
4823 for (; tx < adapter->num_tx_queues; tx++) {
4824 struct ixgbe_ring *ring;
4825
4826 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004827 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004828 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004829 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004830 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004831 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004832 ring->queue_index = tx;
4833 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004834 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004835 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004836
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004837 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004838 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004839
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 for (; rx < adapter->num_rx_queues; rx++) {
4841 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004842
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004843 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004844 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004845 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004846 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004847 goto err_allocation;
4848 ring->count = adapter->rx_ring_count;
4849 ring->queue_index = rx;
4850 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004851 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004852 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004853
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004854 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004855 }
4856
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004857 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004858
4859 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004860
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004861err_allocation:
4862 while (tx)
4863 kfree(adapter->tx_ring[--tx]);
4864
4865 while (rx)
4866 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867 return -ENOMEM;
4868}
4869
4870/**
4871 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4872 * @adapter: board private structure to initialize
4873 *
4874 * Attempt to configure the interrupts using the best available
4875 * capabilities of the hardware and the kernel.
4876 **/
Al Virofeea6a52008-11-27 15:34:07 -08004877static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004878{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004879 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004880 int err = 0;
4881 int vector, v_budget;
4882
4883 /*
4884 * It's easy to be greedy for MSI-X vectors, but it really
4885 * doesn't do us much good if we have a lot more vectors
4886 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004887 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004888 */
4889 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004890 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004891
4892 /*
4893 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004894 * hw.mac->max_msix_vectors vectors. With features
4895 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4896 * descriptor queues supported by our device. Thus, we cap it off in
4897 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004898 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004899 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004900
4901 /* A failure in MSI-X entry allocation isn't fatal, but it does
4902 * mean we disable MSI-X capabilities of the adapter. */
4903 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004904 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004905 if (adapter->msix_entries) {
4906 for (vector = 0; vector < v_budget; vector++)
4907 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004908
Alexander Duyck7a921c92009-05-06 10:43:28 +00004909 ixgbe_acquire_msix_vectors(adapter, v_budget);
4910
4911 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4912 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004913 }
David S. Miller26d27842010-05-03 15:18:22 -07004914
Alexander Duyck7a921c92009-05-06 10:43:28 +00004915 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4916 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004917 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004918 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004919 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004920 "queues are disabled. Disabling Flow Director\n");
4921 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004922 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004923 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004924 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4925 ixgbe_disable_sriov(adapter);
4926
Ben Hutchings847f53f2010-09-27 08:28:56 +00004927 err = ixgbe_set_num_queues(adapter);
4928 if (err)
4929 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004930
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004931 err = pci_enable_msi(adapter->pdev);
4932 if (!err) {
4933 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4934 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004935 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4936 "Unable to allocate MSI interrupt, "
4937 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004938 /* reset err */
4939 err = 0;
4940 }
4941
4942out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004943 return err;
4944}
4945
Alexander Duyck7a921c92009-05-06 10:43:28 +00004946/**
4947 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4948 * @adapter: board private structure to initialize
4949 *
4950 * We allocate one q_vector per queue interrupt. If allocation fails we
4951 * return -ENOMEM.
4952 **/
4953static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4954{
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004955 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004956 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004957
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004958 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004959 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004960 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004961 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004962
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004963 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004964 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004965 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004966 if (!q_vector)
4967 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004968 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004969 if (!q_vector)
4970 goto err_out;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004971
Alexander Duyck7a921c92009-05-06 10:43:28 +00004972 q_vector->adapter = adapter;
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004973 q_vector->v_idx = v_idx;
4974
Alexander Duyck207867f2011-07-15 03:05:37 +00004975 /* Allocate the affinity_hint cpumask, configure the mask */
4976 if (!alloc_cpumask_var(&q_vector->affinity_mask, GFP_KERNEL))
4977 goto err_out;
4978 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004979 netif_napi_add(adapter->netdev, &q_vector->napi,
4980 ixgbe_poll, 64);
4981 adapter->q_vector[v_idx] = q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004982 }
4983
4984 return 0;
4985
4986err_out:
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004987 while (v_idx) {
4988 v_idx--;
4989 q_vector = adapter->q_vector[v_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004990 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00004991 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004992 kfree(q_vector);
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00004993 adapter->q_vector[v_idx] = NULL;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004994 }
4995 return -ENOMEM;
4996}
4997
4998/**
4999 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5000 * @adapter: board private structure to initialize
5001 *
5002 * This function frees the memory allocated to the q_vectors. In addition if
5003 * NAPI is enabled it will delete any references to the NAPI struct prior
5004 * to freeing the q_vector.
5005 **/
5006static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5007{
Alexander Duyck207867f2011-07-15 03:05:37 +00005008 int v_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005009
Alexander Duyck91281fd2009-06-04 16:00:27 +00005010 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005011 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005012 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005013 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005014
Alexander Duyck207867f2011-07-15 03:05:37 +00005015 for (v_idx = 0; v_idx < num_q_vectors; v_idx++) {
5016 struct ixgbe_q_vector *q_vector = adapter->q_vector[v_idx];
5017 adapter->q_vector[v_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005018 netif_napi_del(&q_vector->napi);
Alexander Duyck207867f2011-07-15 03:05:37 +00005019 free_cpumask_var(q_vector->affinity_mask);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005020 kfree(q_vector);
5021 }
5022}
5023
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005024static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005025{
5026 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5027 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5028 pci_disable_msix(adapter->pdev);
5029 kfree(adapter->msix_entries);
5030 adapter->msix_entries = NULL;
5031 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5032 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5033 pci_disable_msi(adapter->pdev);
5034 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005035}
5036
5037/**
5038 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5039 * @adapter: board private structure to initialize
5040 *
5041 * We determine which interrupt scheme to use based on...
5042 * - Kernel support (MSI, MSI-X)
5043 * - which can be user-defined (via MODULE_PARAM)
5044 * - Hardware queue count (num_*_queues)
5045 * - defined by miscellaneous hardware support/features (RSS, etc.)
5046 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005047int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005048{
5049 int err;
5050
5051 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005052 err = ixgbe_set_num_queues(adapter);
5053 if (err)
5054 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005055
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005056 err = ixgbe_set_interrupt_capability(adapter);
5057 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005058 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005059 goto err_set_interrupt;
5060 }
5061
Alexander Duyck7a921c92009-05-06 10:43:28 +00005062 err = ixgbe_alloc_q_vectors(adapter);
5063 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005064 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005065 goto err_alloc_q_vectors;
5066 }
5067
5068 err = ixgbe_alloc_queues(adapter);
5069 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005070 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005071 goto err_alloc_queues;
5072 }
5073
Emil Tantilov849c4542010-06-03 16:53:41 +00005074 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005075 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5076 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005077
5078 set_bit(__IXGBE_DOWN, &adapter->state);
5079
5080 return 0;
5081
Alexander Duyck7a921c92009-05-06 10:43:28 +00005082err_alloc_queues:
5083 ixgbe_free_q_vectors(adapter);
5084err_alloc_q_vectors:
5085 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005086err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005087 return err;
5088}
5089
5090/**
5091 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5092 * @adapter: board private structure to clear interrupt scheme on
5093 *
5094 * We go through and clear interrupt specific resources and reset the structure
5095 * to pre-load conditions
5096 **/
5097void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5098{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005099 int i;
5100
5101 for (i = 0; i < adapter->num_tx_queues; i++) {
5102 kfree(adapter->tx_ring[i]);
5103 adapter->tx_ring[i] = NULL;
5104 }
5105 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005106 struct ixgbe_ring *ring = adapter->rx_ring[i];
5107
5108 /* ixgbe_get_stats64() might access this ring, we must wait
5109 * a grace period before freeing it.
5110 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005111 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005112 adapter->rx_ring[i] = NULL;
5113 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005114
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005115 adapter->num_tx_queues = 0;
5116 adapter->num_rx_queues = 0;
5117
Alexander Duyck7a921c92009-05-06 10:43:28 +00005118 ixgbe_free_q_vectors(adapter);
5119 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005120}
5121
5122/**
5123 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5124 * @adapter: board private structure to initialize
5125 *
5126 * ixgbe_sw_init initializes the Adapter private data structure.
5127 * Fields are initialized based on PCI device information and
5128 * OS network device settings (MTU size).
5129 **/
5130static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5131{
5132 struct ixgbe_hw *hw = &adapter->hw;
5133 struct pci_dev *pdev = adapter->pdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005134 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005135#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005136 int j;
5137 struct tc_configuration *tc;
5138#endif
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005139
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005140 /* PCI config space info */
5141
5142 hw->vendor_id = pdev->vendor;
5143 hw->device_id = pdev->device;
5144 hw->revision_id = pdev->revision;
5145 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5146 hw->subsystem_device_id = pdev->subsystem_device;
5147
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005148 /* Set capability flags */
5149 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5150 adapter->ring_feature[RING_F_RSS].indices = rss;
5151 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005152 switch (hw->mac.type) {
5153 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005154 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5155 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005156 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005157 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005158 case ixgbe_mac_X540:
Jacob Keller4f51bf72011-08-20 04:49:45 +00005159 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
5160 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005161 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005162 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5163 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005164 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5165 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005166 /* Flow Director hash filters enabled */
5167 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5168 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005169 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005170 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005171 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005172#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005173 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5174 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5175 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005176#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005177 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005178 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005179#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005180#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005181 break;
5182 default:
5183 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005184 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005185
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005186 /* n-tuple support exists, always init our spinlock */
5187 spin_lock_init(&adapter->fdir_perfect_lock);
5188
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005189#ifdef CONFIG_IXGBE_DCB
John Fastabend4de2a022011-09-27 03:52:01 +00005190 switch (hw->mac.type) {
5191 case ixgbe_mac_X540:
5192 adapter->dcb_cfg.num_tcs.pg_tcs = X540_TRAFFIC_CLASS;
5193 adapter->dcb_cfg.num_tcs.pfc_tcs = X540_TRAFFIC_CLASS;
5194 break;
5195 default:
5196 adapter->dcb_cfg.num_tcs.pg_tcs = MAX_TRAFFIC_CLASS;
5197 adapter->dcb_cfg.num_tcs.pfc_tcs = MAX_TRAFFIC_CLASS;
5198 break;
5199 }
5200
Alexander Duyck2f90b862008-11-20 20:52:10 -08005201 /* Configure DCB traffic classes */
5202 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5203 tc = &adapter->dcb_cfg.tc_config[j];
5204 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5205 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5206 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5207 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5208 tc->dcb_pfc = pfc_disabled;
5209 }
John Fastabend4de2a022011-09-27 03:52:01 +00005210
5211 /* Initialize default user to priority mapping, UPx->TC0 */
5212 tc = &adapter->dcb_cfg.tc_config[0];
5213 tc->path[DCB_TX_CONFIG].up_to_tc_bitmap = 0xFF;
5214 tc->path[DCB_RX_CONFIG].up_to_tc_bitmap = 0xFF;
5215
Alexander Duyck2f90b862008-11-20 20:52:10 -08005216 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5217 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005218 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005219 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005220 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005221 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005222 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005223
5224#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005225
5226 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005227 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005228 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005229#ifdef CONFIG_DCB
5230 adapter->last_lfc_mode = hw->fc.current_mode;
5231#endif
John Fastabend9da712d2011-08-23 03:14:22 +00005232 ixgbe_pbthresh_setup(adapter);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005233 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5234 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005235 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005236
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005237 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005238 adapter->rx_itr_setting = 1;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005239 adapter->tx_itr_setting = 1;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005240
5241 /* set defaults for eitr in MegaBytes */
5242 adapter->eitr_low = 10;
5243 adapter->eitr_high = 20;
5244
5245 /* set default ring sizes */
5246 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5247 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5248
Alexander Duyckbd198052011-06-11 01:45:08 +00005249 /* set default work limits */
Alexander Duyck59224552011-08-31 00:01:06 +00005250 adapter->tx_work_limit = IXGBE_DEFAULT_TX_WORK;
Alexander Duyckbd198052011-06-11 01:45:08 +00005251
Auke Kok9a799d72007-09-15 14:07:45 -07005252 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005253 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005254 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005255 return -EIO;
5256 }
5257
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005258 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005259 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5260
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005261 /* get assigned NUMA node */
5262 adapter->node = dev_to_node(&pdev->dev);
5263
Auke Kok9a799d72007-09-15 14:07:45 -07005264 set_bit(__IXGBE_DOWN, &adapter->state);
5265
5266 return 0;
5267}
5268
5269/**
5270 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005271 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005272 *
5273 * Return 0 on success, negative on failure
5274 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005275int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005276{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005277 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005278 int size;
5279
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005280 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005281 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005282 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005283 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005284 if (!tx_ring->tx_buffer_info)
5285 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005286
5287 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005288 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005289 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005290
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005291 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005292 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005293 if (!tx_ring->desc)
5294 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005295
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005296 tx_ring->next_to_use = 0;
5297 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005298 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005299
5300err:
5301 vfree(tx_ring->tx_buffer_info);
5302 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005303 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005304 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005305}
5306
5307/**
Alexander Duyck69888672008-09-11 20:05:39 -07005308 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5309 * @adapter: board private structure
5310 *
5311 * If this function returns with an error, then it's possible one or
5312 * more of the rings is populated (while the rest are not). It is the
5313 * callers duty to clean those orphaned rings.
5314 *
5315 * Return 0 on success, negative on failure
5316 **/
5317static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5318{
5319 int i, err = 0;
5320
5321 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005323 if (!err)
5324 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005325 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005326 break;
5327 }
5328
5329 return err;
5330}
5331
5332/**
Auke Kok9a799d72007-09-15 14:07:45 -07005333 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005334 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005335 *
5336 * Returns 0 on success, negative on failure
5337 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005338int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005339{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005340 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005341 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005342
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005343 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005344 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005345 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005346 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005347 if (!rx_ring->rx_buffer_info)
5348 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005349
Auke Kok9a799d72007-09-15 14:07:45 -07005350 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005351 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5352 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005353
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005354 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005355 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005356
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005357 if (!rx_ring->desc)
5358 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005359
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005360 rx_ring->next_to_clean = 0;
5361 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005362
5363 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005364err:
5365 vfree(rx_ring->rx_buffer_info);
5366 rx_ring->rx_buffer_info = NULL;
5367 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005368 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005369}
5370
5371/**
Alexander Duyck69888672008-09-11 20:05:39 -07005372 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5373 * @adapter: board private structure
5374 *
5375 * If this function returns with an error, then it's possible one or
5376 * more of the rings is populated (while the rest are not). It is the
5377 * callers duty to clean those orphaned rings.
5378 *
5379 * Return 0 on success, negative on failure
5380 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005381static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5382{
5383 int i, err = 0;
5384
5385 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005387 if (!err)
5388 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005389 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005390 break;
5391 }
5392
5393 return err;
5394}
5395
5396/**
Auke Kok9a799d72007-09-15 14:07:45 -07005397 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005398 * @tx_ring: Tx descriptor ring for a specific queue
5399 *
5400 * Free all transmit software resources
5401 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005402void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005403{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005404 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005405
5406 vfree(tx_ring->tx_buffer_info);
5407 tx_ring->tx_buffer_info = NULL;
5408
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005409 /* if not set, then don't free */
5410 if (!tx_ring->desc)
5411 return;
5412
5413 dma_free_coherent(tx_ring->dev, tx_ring->size,
5414 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005415
5416 tx_ring->desc = NULL;
5417}
5418
5419/**
5420 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5421 * @adapter: board private structure
5422 *
5423 * Free all transmit software resources
5424 **/
5425static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5426{
5427 int i;
5428
5429 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005430 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005431 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005432}
5433
5434/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005435 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005436 * @rx_ring: ring to clean the resources from
5437 *
5438 * Free all receive software resources
5439 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005440void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005441{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005442 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005443
5444 vfree(rx_ring->rx_buffer_info);
5445 rx_ring->rx_buffer_info = NULL;
5446
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005447 /* if not set, then don't free */
5448 if (!rx_ring->desc)
5449 return;
5450
5451 dma_free_coherent(rx_ring->dev, rx_ring->size,
5452 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005453
5454 rx_ring->desc = NULL;
5455}
5456
5457/**
5458 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5459 * @adapter: board private structure
5460 *
5461 * Free all receive software resources
5462 **/
5463static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5464{
5465 int i;
5466
5467 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005468 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005469 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005470}
5471
5472/**
Auke Kok9a799d72007-09-15 14:07:45 -07005473 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5474 * @netdev: network interface device structure
5475 * @new_mtu: new value for maximum frame size
5476 *
5477 * Returns 0 on success, negative on failure
5478 **/
5479static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5480{
5481 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005482 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005483 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5484
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005485 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005486 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5487 hw->mac.type != ixgbe_mac_X540) {
5488 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5489 return -EINVAL;
5490 } else {
5491 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5492 return -EINVAL;
5493 }
Auke Kok9a799d72007-09-15 14:07:45 -07005494
Emil Tantilov396e7992010-07-01 20:05:12 +00005495 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005496 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005497 netdev->mtu = new_mtu;
5498
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005499 if (netif_running(netdev))
5500 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005501
5502 return 0;
5503}
5504
5505/**
5506 * ixgbe_open - Called when a network interface is made active
5507 * @netdev: network interface device structure
5508 *
5509 * Returns 0 on success, negative value on failure
5510 *
5511 * The open entry point is called when a network interface is made
5512 * active by the system (IFF_UP). At this point all resources needed
5513 * for transmit and receive operations are allocated, the interrupt
5514 * handler is registered with the OS, the watchdog timer is started,
5515 * and the stack is notified that the interface is ready.
5516 **/
5517static int ixgbe_open(struct net_device *netdev)
5518{
5519 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5520 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005521
Auke Kok4bebfaa2008-02-11 09:26:01 -08005522 /* disallow open during test */
5523 if (test_bit(__IXGBE_TESTING, &adapter->state))
5524 return -EBUSY;
5525
Jesse Brandeburg54386462009-04-17 20:44:27 +00005526 netif_carrier_off(netdev);
5527
Auke Kok9a799d72007-09-15 14:07:45 -07005528 /* allocate transmit descriptors */
5529 err = ixgbe_setup_all_tx_resources(adapter);
5530 if (err)
5531 goto err_setup_tx;
5532
Auke Kok9a799d72007-09-15 14:07:45 -07005533 /* allocate receive descriptors */
5534 err = ixgbe_setup_all_rx_resources(adapter);
5535 if (err)
5536 goto err_setup_rx;
5537
5538 ixgbe_configure(adapter);
5539
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005540 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005541 if (err)
5542 goto err_req_irq;
5543
Alexander Duyckc7ccde02011-07-21 00:40:40 +00005544 ixgbe_up_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005545
5546 return 0;
5547
Auke Kok9a799d72007-09-15 14:07:45 -07005548err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005549err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005550 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005551err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005552 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005553 ixgbe_reset(adapter);
5554
5555 return err;
5556}
5557
5558/**
5559 * ixgbe_close - Disables a network interface
5560 * @netdev: network interface device structure
5561 *
5562 * Returns 0, this is not allowed to fail
5563 *
5564 * The close entry point is called when an interface is de-activated
5565 * by the OS. The hardware is still under the drivers control, but
5566 * needs to be disabled. A global MAC reset is issued to stop the
5567 * hardware, and all transmit and receive resources are freed.
5568 **/
5569static int ixgbe_close(struct net_device *netdev)
5570{
5571 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005572
5573 ixgbe_down(adapter);
5574 ixgbe_free_irq(adapter);
5575
Alexander Duycke4911d52011-05-11 07:18:52 +00005576 ixgbe_fdir_filter_exit(adapter);
5577
Auke Kok9a799d72007-09-15 14:07:45 -07005578 ixgbe_free_all_tx_resources(adapter);
5579 ixgbe_free_all_rx_resources(adapter);
5580
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005581 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005582
5583 return 0;
5584}
5585
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005586#ifdef CONFIG_PM
5587static int ixgbe_resume(struct pci_dev *pdev)
5588{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005589 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5590 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005591 u32 err;
5592
5593 pci_set_power_state(pdev, PCI_D0);
5594 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005595 /*
5596 * pci_restore_state clears dev->state_saved so call
5597 * pci_save_state to restore it.
5598 */
5599 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005600
5601 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005602 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005603 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005604 return err;
5605 }
5606 pci_set_master(pdev);
5607
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005608 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005609
5610 err = ixgbe_init_interrupt_scheme(adapter);
5611 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005612 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005613 return err;
5614 }
5615
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005616 ixgbe_reset(adapter);
5617
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005618 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5619
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005620 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005621 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005622 if (err)
5623 return err;
5624 }
5625
5626 netif_device_attach(netdev);
5627
5628 return 0;
5629}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005630#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005631
5632static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005634 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5635 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005636 struct ixgbe_hw *hw = &adapter->hw;
5637 u32 ctrl, fctrl;
5638 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005639#ifdef CONFIG_PM
5640 int retval = 0;
5641#endif
5642
5643 netif_device_detach(netdev);
5644
5645 if (netif_running(netdev)) {
5646 ixgbe_down(adapter);
5647 ixgbe_free_irq(adapter);
5648 ixgbe_free_all_tx_resources(adapter);
5649 ixgbe_free_all_rx_resources(adapter);
5650 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005651
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005652 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005653#ifdef CONFIG_DCB
5654 kfree(adapter->ixgbe_ieee_pfc);
5655 kfree(adapter->ixgbe_ieee_ets);
5656#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005657
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005658#ifdef CONFIG_PM
5659 retval = pci_save_state(pdev);
5660 if (retval)
5661 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005662
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005663#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005664 if (wufc) {
5665 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005666
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005667 /* turn on all-multi mode if wake on multicast is enabled */
5668 if (wufc & IXGBE_WUFC_MC) {
5669 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5670 fctrl |= IXGBE_FCTRL_MPE;
5671 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5672 }
5673
5674 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5675 ctrl |= IXGBE_CTRL_GIO_DIS;
5676 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5677
5678 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5679 } else {
5680 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5681 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5682 }
5683
Alexander Duyckbd508172010-11-16 19:27:03 -08005684 switch (hw->mac.type) {
5685 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005686 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005687 break;
5688 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005689 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005690 pci_wake_from_d3(pdev, !!wufc);
5691 break;
5692 default:
5693 break;
5694 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005695
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005696 *enable_wake = !!wufc;
5697
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005698 ixgbe_release_hw_control(adapter);
5699
5700 pci_disable_device(pdev);
5701
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005702 return 0;
5703}
5704
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005705#ifdef CONFIG_PM
5706static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5707{
5708 int retval;
5709 bool wake;
5710
5711 retval = __ixgbe_shutdown(pdev, &wake);
5712 if (retval)
5713 return retval;
5714
5715 if (wake) {
5716 pci_prepare_to_sleep(pdev);
5717 } else {
5718 pci_wake_from_d3(pdev, false);
5719 pci_set_power_state(pdev, PCI_D3hot);
5720 }
5721
5722 return 0;
5723}
5724#endif /* CONFIG_PM */
5725
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005726static void ixgbe_shutdown(struct pci_dev *pdev)
5727{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005728 bool wake;
5729
5730 __ixgbe_shutdown(pdev, &wake);
5731
5732 if (system_state == SYSTEM_POWER_OFF) {
5733 pci_wake_from_d3(pdev, wake);
5734 pci_set_power_state(pdev, PCI_D3hot);
5735 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005736}
5737
5738/**
Auke Kok9a799d72007-09-15 14:07:45 -07005739 * ixgbe_update_stats - Update the board statistics counters.
5740 * @adapter: board private structure
5741 **/
5742void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5743{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005744 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005745 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005746 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005747 u64 total_mpc = 0;
5748 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005749 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5750 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5751 u64 bytes = 0, packets = 0;
Amir Hanania7b859eb2011-08-31 02:07:55 +00005752#ifdef IXGBE_FCOE
5753 struct ixgbe_fcoe *fcoe = &adapter->fcoe;
5754 unsigned int cpu;
5755 u64 fcoe_noddp_counts_sum = 0, fcoe_noddp_ext_buff_counts_sum = 0;
5756#endif /* IXGBE_FCOE */
Auke Kok9a799d72007-09-15 14:07:45 -07005757
Don Skidmored08935c2010-06-11 13:20:29 +00005758 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5759 test_bit(__IXGBE_RESETTING, &adapter->state))
5760 return;
5761
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005762 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005763 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005764 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005765 for (i = 0; i < 16; i++)
5766 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005767 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005768 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005769 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5770 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005771 }
5772 adapter->rsc_total_count = rsc_count;
5773 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005774 }
5775
Alexander Duyck5b7da512010-11-16 19:26:50 -08005776 for (i = 0; i < adapter->num_rx_queues; i++) {
5777 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5778 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5779 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5780 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5781 bytes += rx_ring->stats.bytes;
5782 packets += rx_ring->stats.packets;
5783 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005784 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005785 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5786 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5787 netdev->stats.rx_bytes = bytes;
5788 netdev->stats.rx_packets = packets;
5789
5790 bytes = 0;
5791 packets = 0;
5792 /* gather some stats to the adapter struct that are per queue */
5793 for (i = 0; i < adapter->num_tx_queues; i++) {
5794 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5795 restart_queue += tx_ring->tx_stats.restart_queue;
5796 tx_busy += tx_ring->tx_stats.tx_busy;
5797 bytes += tx_ring->stats.bytes;
5798 packets += tx_ring->stats.packets;
5799 }
5800 adapter->restart_queue = restart_queue;
5801 adapter->tx_busy = tx_busy;
5802 netdev->stats.tx_bytes = bytes;
5803 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005804
Joe Perches7ca647b2010-09-07 21:35:40 +00005805 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005806
5807 /* 8 register reads */
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005808 for (i = 0; i < 8; i++) {
5809 /* for packet buffers not used, the register should read 0 */
5810 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5811 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005812 hwstats->mpc[i] += mpc;
5813 total_mpc += hwstats->mpc[i];
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005814 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5815 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005816 switch (hw->mac.type) {
5817 case ixgbe_mac_82598EB:
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005818 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5819 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5820 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Joe Perches7ca647b2010-09-07 21:35:40 +00005821 hwstats->pxonrxc[i] +=
5822 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005823 break;
5824 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005825 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005826 hwstats->pxonrxc[i] +=
5827 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005828 break;
5829 default:
5830 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005831 }
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005832 }
Emil Tantilov1a70db4b2011-07-26 07:51:41 +00005833
5834 /*16 register reads */
5835 for (i = 0; i < 16; i++) {
5836 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5837 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5838 if ((hw->mac.type == ixgbe_mac_82599EB) ||
5839 (hw->mac.type == ixgbe_mac_X540)) {
5840 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC_L(i));
5841 IXGBE_READ_REG(hw, IXGBE_QBTC_H(i)); /* to clear */
5842 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC_L(i));
5843 IXGBE_READ_REG(hw, IXGBE_QBRC_H(i)); /* to clear */
5844 }
5845 }
5846
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005848 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005849 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005850
John Fastabendc84d3242010-11-16 19:27:12 -08005851 ixgbe_update_xoff_received(adapter);
5852
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005853 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005854 switch (hw->mac.type) {
5855 case ixgbe_mac_82598EB:
5856 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005857 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5858 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5859 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5860 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005861 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005862 /* OS2BMC stats are X540 only*/
5863 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5864 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5865 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5866 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5867 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005868 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005869 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005870 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005871 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005872 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005873 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005874 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005875 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5876 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005877#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005878 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5879 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5880 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5881 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5882 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5883 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Amir Hanania7b859eb2011-08-31 02:07:55 +00005884 /* Add up per cpu counters for total ddp aloc fail */
5885 if (fcoe->pcpu_noddp && fcoe->pcpu_noddp_ext_buff) {
5886 for_each_possible_cpu(cpu) {
5887 fcoe_noddp_counts_sum +=
5888 *per_cpu_ptr(fcoe->pcpu_noddp, cpu);
5889 fcoe_noddp_ext_buff_counts_sum +=
5890 *per_cpu_ptr(fcoe->
5891 pcpu_noddp_ext_buff, cpu);
5892 }
5893 }
5894 hwstats->fcoe_noddp = fcoe_noddp_counts_sum;
5895 hwstats->fcoe_noddp_ext_buff = fcoe_noddp_ext_buff_counts_sum;
Yi Zou6d455222009-05-13 13:12:16 +00005896#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005897 break;
5898 default:
5899 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005900 }
Auke Kok9a799d72007-09-15 14:07:45 -07005901 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005902 hwstats->bprc += bprc;
5903 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005904 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005905 hwstats->mprc -= bprc;
5906 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5907 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5908 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5909 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5910 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5911 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5912 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5913 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005914 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005915 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005916 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005917 hwstats->lxofftxc += lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005918 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5919 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005920 /*
5921 * 82598 errata - tx of flow control packets is included in tx counters
5922 */
5923 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->gptc -= xon_off_tot;
5925 hwstats->mptc -= xon_off_tot;
5926 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5927 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5928 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5929 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5930 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5931 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5932 hwstats->ptc64 -= xon_off_tot;
5933 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5934 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5935 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5936 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5937 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5938 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005939
5940 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005941 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005942
5943 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005944 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005945 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 netdev->stats.rx_length_errors = hwstats->rlec;
5947 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005948 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005949}
5950
5951/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005952 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5953 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005954 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005955static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005956{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005957 struct ixgbe_hw *hw = &adapter->hw;
5958 int i;
5959
Alexander Duyckd034acf2011-04-27 09:25:34 +00005960 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5961 return;
5962
5963 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5964
5965 /* if interface is down do nothing */
5966 if (test_bit(__IXGBE_DOWN, &adapter->state))
5967 return;
5968
5969 /* do nothing if we are not using signature filters */
5970 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5971 return;
5972
5973 adapter->fdir_overflow++;
5974
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005975 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5976 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005977 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005978 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005979 /* re-enable flow director interrupts */
5980 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005981 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005982 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005983 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005984 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005985}
5986
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005987/**
5988 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5989 * @adapter - pointer to the device adapter structure
5990 *
5991 * This function serves two purposes. First it strobes the interrupt lines
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005992 * in order to make certain interrupts are occurring. Secondly it sets the
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005993 * bits needed to check for TX hangs. As a result we should immediately
Stephen Hemminger52f33af2011-12-22 16:34:52 +00005994 * determine if a hang has occurred.
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005995 */
5996static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5997{
Auke Kok9a799d72007-09-15 14:07:45 -07005998 struct ixgbe_hw *hw = &adapter->hw;
5999 u64 eics = 0;
6000 int i;
6001
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006002 /* If we're down or resetting, just bail */
6003 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6004 test_bit(__IXGBE_RESETTING, &adapter->state))
6005 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006006
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006007 /* Force detection of hung controller */
6008 if (netif_carrier_ok(adapter->netdev)) {
6009 for (i = 0; i < adapter->num_tx_queues; i++)
6010 set_check_for_tx_hang(adapter->tx_ring[i]);
6011 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006012
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006013 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006014 /*
6015 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006016 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006017 * would set *both* EIMS and EICS for any bit in EIAM
6018 */
6019 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6020 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006021 } else {
6022 /* get one bit for every active tx/rx interrupt vector */
6023 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6024 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyckefe3d3c2011-07-15 03:05:21 +00006025 if (qv->rx.ring || qv->tx.ring)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006026 eics |= ((u64)1 << i);
6027 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006028 }
6029
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006030 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006031 ixgbe_irq_rearm_queues(adapter, eics);
6032
Alexander Duyckfe49f042009-06-04 16:00:09 +00006033}
6034
6035/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006036 * ixgbe_watchdog_update_link - update the link status
6037 * @adapter - pointer to the device adapter structure
6038 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006039 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006040static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006041{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006042 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006043 u32 link_speed = adapter->link_speed;
6044 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006045 int i;
6046
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006047 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6048 return;
6049
6050 if (hw->mac.ops.check_link) {
6051 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006052 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006053 /* always assume link is up, if no check link function */
6054 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6055 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006056 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006057 if (link_up) {
6058 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6059 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6060 hw->mac.ops.fc_enable(hw, i);
6061 } else {
6062 hw->mac.ops.fc_enable(hw, 0);
6063 }
6064 }
6065
6066 if (link_up ||
6067 time_after(jiffies, (adapter->link_check_timeout +
6068 IXGBE_TRY_LINK_TIMEOUT))) {
6069 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6070 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6071 IXGBE_WRITE_FLUSH(hw);
6072 }
6073
6074 adapter->link_up = link_up;
6075 adapter->link_speed = link_speed;
6076}
6077
6078/**
6079 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6080 * print link up message
6081 * @adapter - pointer to the device adapter structure
6082 **/
6083static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6084{
6085 struct net_device *netdev = adapter->netdev;
6086 struct ixgbe_hw *hw = &adapter->hw;
6087 u32 link_speed = adapter->link_speed;
6088 bool flow_rx, flow_tx;
6089
6090 /* only continue if link was previously down */
6091 if (netif_carrier_ok(netdev))
6092 return;
6093
6094 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6095
6096 switch (hw->mac.type) {
6097 case ixgbe_mac_82598EB: {
6098 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6099 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6100 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6101 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6102 }
6103 break;
6104 case ixgbe_mac_X540:
6105 case ixgbe_mac_82599EB: {
6106 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6107 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6108 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6109 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6110 }
6111 break;
6112 default:
6113 flow_tx = false;
6114 flow_rx = false;
6115 break;
6116 }
6117 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6118 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6119 "10 Gbps" :
6120 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6121 "1 Gbps" :
6122 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6123 "100 Mbps" :
6124 "unknown speed"))),
6125 ((flow_rx && flow_tx) ? "RX/TX" :
6126 (flow_rx ? "RX" :
6127 (flow_tx ? "TX" : "None"))));
6128
6129 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006130 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006131}
6132
6133/**
6134 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6135 * print link down message
6136 * @adapter - pointer to the adapter structure
6137 **/
6138static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6139{
6140 struct net_device *netdev = adapter->netdev;
6141 struct ixgbe_hw *hw = &adapter->hw;
6142
6143 adapter->link_up = false;
6144 adapter->link_speed = 0;
6145
6146 /* only continue if link was up previously */
6147 if (!netif_carrier_ok(netdev))
6148 return;
6149
6150 /* poll for SFP+ cable when link is down */
6151 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6152 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6153
6154 e_info(drv, "NIC Link is Down\n");
6155 netif_carrier_off(netdev);
6156}
6157
6158/**
6159 * ixgbe_watchdog_flush_tx - flush queues on link down
6160 * @adapter - pointer to the device adapter structure
6161 **/
6162static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6163{
6164 int i;
6165 int some_tx_pending = 0;
6166
6167 if (!netif_carrier_ok(adapter->netdev)) {
6168 for (i = 0; i < adapter->num_tx_queues; i++) {
6169 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6170 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6171 some_tx_pending = 1;
6172 break;
6173 }
6174 }
6175
6176 if (some_tx_pending) {
6177 /* We've lost link, so the controller stops DMA,
6178 * but we've got queued Tx work that's never going
6179 * to get done, so reset controller to flush Tx.
6180 * (Do the reset outside of interrupt context).
6181 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006182 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006183 }
6184 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006185}
6186
Greg Rosea985b6c32010-11-18 03:02:52 +00006187static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6188{
6189 u32 ssvpc;
6190
6191 /* Do not perform spoof check for 82598 */
6192 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6193 return;
6194
6195 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6196
6197 /*
6198 * ssvpc register is cleared on read, if zero then no
6199 * spoofed packets in the last interval.
6200 */
6201 if (!ssvpc)
6202 return;
6203
6204 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6205}
6206
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006207/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006208 * ixgbe_watchdog_subtask - check and bring link up
6209 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006210 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006211static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006212{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006213 /* if interface is down do nothing */
Emil Tantilov7edebf92011-08-27 07:18:37 +00006214 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6215 test_bit(__IXGBE_RESETTING, &adapter->state))
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006216 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006217
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006218 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006219
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006220 if (adapter->link_up)
6221 ixgbe_watchdog_link_is_up(adapter);
6222 else
6223 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006224
Greg Rosea985b6c32010-11-18 03:02:52 +00006225 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006226 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006227
6228 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006229}
6230
Alexander Duyck70864002011-04-27 09:13:56 +00006231/**
6232 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6233 * @adapter - the ixgbe adapter structure
6234 **/
6235static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6236{
6237 struct ixgbe_hw *hw = &adapter->hw;
6238 s32 err;
6239
6240 /* not searching for SFP so there is nothing to do here */
6241 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6242 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6243 return;
6244
6245 /* someone else is in init, wait until next service event */
6246 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6247 return;
6248
6249 err = hw->phy.ops.identify_sfp(hw);
6250 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6251 goto sfp_out;
6252
6253 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6254 /* If no cable is present, then we need to reset
6255 * the next time we find a good cable. */
6256 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6257 }
6258
6259 /* exit on error */
6260 if (err)
6261 goto sfp_out;
6262
6263 /* exit if reset not needed */
6264 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6265 goto sfp_out;
6266
6267 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6268
6269 /*
6270 * A module may be identified correctly, but the EEPROM may not have
6271 * support for that module. setup_sfp() will fail in that case, so
6272 * we should not allow that module to load.
6273 */
6274 if (hw->mac.type == ixgbe_mac_82598EB)
6275 err = hw->phy.ops.reset(hw);
6276 else
6277 err = hw->mac.ops.setup_sfp(hw);
6278
6279 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6280 goto sfp_out;
6281
6282 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6283 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6284
6285sfp_out:
6286 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6287
6288 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6289 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6290 e_dev_err("failed to initialize because an unsupported "
6291 "SFP+ module type was detected.\n");
6292 e_dev_err("Reload the driver after installing a "
6293 "supported module.\n");
6294 unregister_netdev(adapter->netdev);
6295 }
6296}
6297
6298/**
6299 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6300 * @adapter - the ixgbe adapter structure
6301 **/
6302static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6303{
6304 struct ixgbe_hw *hw = &adapter->hw;
6305 u32 autoneg;
6306 bool negotiation;
6307
6308 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6309 return;
6310
6311 /* someone else is in init, wait until next service event */
6312 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6313 return;
6314
6315 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6316
6317 autoneg = hw->phy.autoneg_advertised;
6318 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6319 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Alexander Duyck70864002011-04-27 09:13:56 +00006320 if (hw->mac.ops.setup_link)
6321 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6322
6323 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6324 adapter->link_check_timeout = jiffies;
6325 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6326}
6327
Greg Rose83c61fa2011-09-07 05:59:35 +00006328#ifdef CONFIG_PCI_IOV
6329static void ixgbe_check_for_bad_vf(struct ixgbe_adapter *adapter)
6330{
6331 int vf;
6332 struct ixgbe_hw *hw = &adapter->hw;
6333 struct net_device *netdev = adapter->netdev;
6334 u32 gpc;
6335 u32 ciaa, ciad;
6336
6337 gpc = IXGBE_READ_REG(hw, IXGBE_TXDGPC);
6338 if (gpc) /* If incrementing then no need for the check below */
6339 return;
6340 /*
6341 * Check to see if a bad DMA write target from an errant or
6342 * malicious VF has caused a PCIe error. If so then we can
6343 * issue a VFLR to the offending VF(s) and then resume without
6344 * requesting a full slot reset.
6345 */
6346
6347 for (vf = 0; vf < adapter->num_vfs; vf++) {
6348 ciaa = (vf << 16) | 0x80000000;
6349 /* 32 bit read so align, we really want status at offset 6 */
6350 ciaa |= PCI_COMMAND;
6351 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6352 ciad = IXGBE_READ_REG(hw, IXGBE_CIAD_82599);
6353 ciaa &= 0x7FFFFFFF;
6354 /* disable debug mode asap after reading data */
6355 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6356 /* Get the upper 16 bits which will be the PCI status reg */
6357 ciad >>= 16;
6358 if (ciad & PCI_STATUS_REC_MASTER_ABORT) {
6359 netdev_err(netdev, "VF %d Hung DMA\n", vf);
6360 /* Issue VFLR */
6361 ciaa = (vf << 16) | 0x80000000;
6362 ciaa |= 0xA8;
6363 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6364 ciad = 0x00008000; /* VFLR */
6365 IXGBE_WRITE_REG(hw, IXGBE_CIAD_82599, ciad);
6366 ciaa &= 0x7FFFFFFF;
6367 IXGBE_WRITE_REG(hw, IXGBE_CIAA_82599, ciaa);
6368 }
6369 }
6370}
6371
6372#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006373/**
6374 * ixgbe_service_timer - Timer Call-back
6375 * @data: pointer to adapter cast into an unsigned long
6376 **/
6377static void ixgbe_service_timer(unsigned long data)
6378{
6379 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6380 unsigned long next_event_offset;
Greg Rose83c61fa2011-09-07 05:59:35 +00006381 bool ready = true;
Alexander Duyck70864002011-04-27 09:13:56 +00006382
Greg Rose83c61fa2011-09-07 05:59:35 +00006383#ifdef CONFIG_PCI_IOV
6384 ready = false;
6385
6386 /*
6387 * don't bother with SR-IOV VF DMA hang check if there are
6388 * no VFs or the link is down
6389 */
6390 if (!adapter->num_vfs ||
6391 (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)) {
6392 ready = true;
6393 goto normal_timer_service;
6394 }
6395
6396 /* If we have VFs allocated then we must check for DMA hangs */
6397 ixgbe_check_for_bad_vf(adapter);
6398 next_event_offset = HZ / 50;
6399 adapter->timer_event_accumulator++;
6400
6401 if (adapter->timer_event_accumulator >= 100) {
6402 ready = true;
6403 adapter->timer_event_accumulator = 0;
6404 }
6405
6406 goto schedule_event;
6407
6408normal_timer_service:
6409#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006410 /* poll faster when waiting for link */
6411 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6412 next_event_offset = HZ / 10;
6413 else
6414 next_event_offset = HZ * 2;
6415
Greg Rose83c61fa2011-09-07 05:59:35 +00006416#ifdef CONFIG_PCI_IOV
6417schedule_event:
6418#endif
Alexander Duyck70864002011-04-27 09:13:56 +00006419 /* Reset the timer */
6420 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6421
Greg Rose83c61fa2011-09-07 05:59:35 +00006422 if (ready)
6423 ixgbe_service_event_schedule(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006424}
6425
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006426static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6427{
6428 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6429 return;
6430
6431 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6432
6433 /* If we're already down or resetting, just bail */
6434 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6435 test_bit(__IXGBE_RESETTING, &adapter->state))
6436 return;
6437
6438 ixgbe_dump(adapter);
6439 netdev_err(adapter->netdev, "Reset adapter\n");
6440 adapter->tx_timeout_count++;
6441
6442 ixgbe_reinit_locked(adapter);
6443}
6444
Alexander Duyck70864002011-04-27 09:13:56 +00006445/**
6446 * ixgbe_service_task - manages and runs subtasks
6447 * @work: pointer to work_struct containing our data
6448 **/
6449static void ixgbe_service_task(struct work_struct *work)
6450{
6451 struct ixgbe_adapter *adapter = container_of(work,
6452 struct ixgbe_adapter,
6453 service_task);
6454
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006455 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006456 ixgbe_sfp_detection_subtask(adapter);
6457 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006458 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006459 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006460 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006461 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006462
6463 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006464}
6465
Alexander Duyck897ab152011-05-27 05:31:47 +00006466void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6467 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006468{
6469 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006470 u16 i = tx_ring->next_to_use;
6471
6472 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6473
6474 i++;
6475 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6476
6477 /* set bits to identify this as an advanced context descriptor */
6478 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6479
6480 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6481 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6482 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6483 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6484}
6485
6486static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6487 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6488{
Auke Kok9a799d72007-09-15 14:07:45 -07006489 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006490 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006491 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006492
Alexander Duyck897ab152011-05-27 05:31:47 +00006493 if (!skb_is_gso(skb))
6494 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006495
Alexander Duyck897ab152011-05-27 05:31:47 +00006496 if (skb_header_cloned(skb)) {
6497 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6498 if (err)
6499 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006500 }
6501
Alexander Duyck897ab152011-05-27 05:31:47 +00006502 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6503 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6504
6505 if (protocol == __constant_htons(ETH_P_IP)) {
6506 struct iphdr *iph = ip_hdr(skb);
6507 iph->tot_len = 0;
6508 iph->check = 0;
6509 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6510 iph->daddr, 0,
6511 IPPROTO_TCP,
6512 0);
6513 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6514 } else if (skb_is_gso_v6(skb)) {
6515 ipv6_hdr(skb)->payload_len = 0;
6516 tcp_hdr(skb)->check =
6517 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6518 &ipv6_hdr(skb)->daddr,
6519 0, IPPROTO_TCP, 0);
6520 }
6521
6522 l4len = tcp_hdrlen(skb);
6523 *hdr_len = skb_transport_offset(skb) + l4len;
6524
6525 /* mss_l4len_id: use 1 as index for TSO */
6526 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6527 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6528 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6529
6530 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6531 vlan_macip_lens = skb_network_header_len(skb);
6532 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6533 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6534
6535 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6536 mss_l4len_idx);
6537
6538 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006539}
6540
Alexander Duyck897ab152011-05-27 05:31:47 +00006541static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006542 struct sk_buff *skb, u32 tx_flags,
6543 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006544{
Alexander Duyck897ab152011-05-27 05:31:47 +00006545 u32 vlan_macip_lens = 0;
6546 u32 mss_l4len_idx = 0;
6547 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006548
Alexander Duyck897ab152011-05-27 05:31:47 +00006549 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006550 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN) &&
6551 !(tx_flags & IXGBE_TX_FLAGS_TXSW))
Alexander Duyck897ab152011-05-27 05:31:47 +00006552 return false;
6553 } else {
6554 u8 l4_hdr = 0;
6555 switch (protocol) {
6556 case __constant_htons(ETH_P_IP):
6557 vlan_macip_lens |= skb_network_header_len(skb);
6558 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6559 l4_hdr = ip_hdr(skb)->protocol;
6560 break;
6561 case __constant_htons(ETH_P_IPV6):
6562 vlan_macip_lens |= skb_network_header_len(skb);
6563 l4_hdr = ipv6_hdr(skb)->nexthdr;
6564 break;
6565 default:
6566 if (unlikely(net_ratelimit())) {
6567 dev_warn(tx_ring->dev,
6568 "partial checksum but proto=%x!\n",
6569 skb->protocol);
6570 }
6571 break;
6572 }
Auke Kok9a799d72007-09-15 14:07:45 -07006573
Alexander Duyck897ab152011-05-27 05:31:47 +00006574 switch (l4_hdr) {
6575 case IPPROTO_TCP:
6576 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6577 mss_l4len_idx = tcp_hdrlen(skb) <<
6578 IXGBE_ADVTXD_L4LEN_SHIFT;
6579 break;
6580 case IPPROTO_SCTP:
6581 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6582 mss_l4len_idx = sizeof(struct sctphdr) <<
6583 IXGBE_ADVTXD_L4LEN_SHIFT;
6584 break;
6585 case IPPROTO_UDP:
6586 mss_l4len_idx = sizeof(struct udphdr) <<
6587 IXGBE_ADVTXD_L4LEN_SHIFT;
6588 break;
6589 default:
6590 if (unlikely(net_ratelimit())) {
6591 dev_warn(tx_ring->dev,
6592 "partial checksum but l4 proto=%x!\n",
6593 skb->protocol);
6594 }
6595 break;
6596 }
Auke Kok9a799d72007-09-15 14:07:45 -07006597 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006598
Alexander Duyck897ab152011-05-27 05:31:47 +00006599 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6600 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6601
6602 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6603 type_tucmd, mss_l4len_idx);
6604
6605 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006606}
6607
Alexander Duyckd3d00232011-07-15 02:31:25 +00006608static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6609{
6610 /* set type for advanced descriptor with frame checksum insertion */
6611 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6612 IXGBE_ADVTXD_DCMD_IFCS |
6613 IXGBE_ADVTXD_DCMD_DEXT);
6614
6615 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006616 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006617 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6618
6619 /* set segmentation enable bits for TSO/FSO */
6620#ifdef IXGBE_FCOE
6621 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6622#else
6623 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6624#endif
6625 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6626
6627 return cmd_type;
6628}
6629
6630static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6631{
6632 __le32 olinfo_status =
6633 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6634
6635 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6636 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6637 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6638 /* enble IPv4 checksum for TSO */
6639 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6640 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6641 }
6642
6643 /* enable L4 checksum for TSO and TX checksum offload */
6644 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6645 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6646
6647#ifdef IXGBE_FCOE
6648 /* use index 1 context for FCOE/FSO */
6649 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6650 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6651 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6652
6653#endif
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006654 /*
6655 * Check Context must be set if Tx switch is enabled, which it
6656 * always is for case where virtual functions are running
6657 */
6658 if (tx_flags & IXGBE_TX_FLAGS_TXSW)
6659 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC);
6660
Alexander Duyckd3d00232011-07-15 02:31:25 +00006661 return olinfo_status;
6662}
6663
6664#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6665 IXGBE_TXD_CMD_RS)
6666
6667static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6668 struct sk_buff *skb,
6669 struct ixgbe_tx_buffer *first,
6670 u32 tx_flags,
6671 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006672{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006673 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006674 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006675 union ixgbe_adv_tx_desc *tx_desc;
6676 dma_addr_t dma;
6677 __le32 cmd_type, olinfo_status;
6678 struct skb_frag_struct *frag;
6679 unsigned int f = 0;
6680 unsigned int data_len = skb->data_len;
6681 unsigned int size = skb_headlen(skb);
6682 u32 offset = 0;
6683 u32 paylen = skb->len - hdr_len;
6684 u16 i = tx_ring->next_to_use;
6685 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006686
Alexander Duyckd3d00232011-07-15 02:31:25 +00006687#ifdef IXGBE_FCOE
6688 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6689 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6690 data_len -= sizeof(struct fcoe_crc_eof);
6691 } else {
6692 size -= sizeof(struct fcoe_crc_eof) - data_len;
6693 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006694 }
Auke Kok9a799d72007-09-15 14:07:45 -07006695 }
6696
Alexander Duyckd3d00232011-07-15 02:31:25 +00006697#endif
6698 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6699 if (dma_mapping_error(dev, dma))
6700 goto dma_error;
6701
6702 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6703 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6704
6705 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6706
6707 for (;;) {
6708 while (size > IXGBE_MAX_DATA_PER_TXD) {
6709 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6710 tx_desc->read.cmd_type_len =
6711 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6712 tx_desc->read.olinfo_status = olinfo_status;
6713
6714 offset += IXGBE_MAX_DATA_PER_TXD;
6715 size -= IXGBE_MAX_DATA_PER_TXD;
6716
6717 tx_desc++;
6718 i++;
6719 if (i == tx_ring->count) {
6720 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6721 i = 0;
6722 }
6723 }
6724
6725 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6726 tx_buffer_info->length = offset + size;
6727 tx_buffer_info->tx_flags = tx_flags;
6728 tx_buffer_info->dma = dma;
6729
6730 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6731 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6732 tx_desc->read.olinfo_status = olinfo_status;
6733
6734 if (!data_len)
6735 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006736
6737 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006738#ifdef IXGBE_FCOE
Eric Dumazet9e903e02011-10-18 21:00:24 +00006739 size = min_t(unsigned int, data_len, skb_frag_size(frag));
Alexander Duyckd3d00232011-07-15 02:31:25 +00006740#else
Eric Dumazet9e903e02011-10-18 21:00:24 +00006741 size = skb_frag_size(frag);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006742#endif
6743 data_len -= size;
6744 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006745
Alexander Duyckd3d00232011-07-15 02:31:25 +00006746 offset = 0;
6747 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006748
Ian Campbell877749b2011-08-29 23:18:26 +00006749 dma = skb_frag_dma_map(dev, frag, 0, size, DMA_TO_DEVICE);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006750 if (dma_mapping_error(dev, dma))
6751 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006752
Alexander Duyckd3d00232011-07-15 02:31:25 +00006753 tx_desc++;
6754 i++;
6755 if (i == tx_ring->count) {
6756 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6757 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006758 }
6759 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006760
Alexander Duyckd3d00232011-07-15 02:31:25 +00006761 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6762
6763 i++;
6764 if (i == tx_ring->count)
6765 i = 0;
6766
6767 tx_ring->next_to_use = i;
6768
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006769 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6770 gso_segs = skb_shinfo(skb)->gso_segs;
6771#ifdef IXGBE_FCOE
6772 /* adjust for FCoE Sequence Offload */
6773 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6774 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6775 skb_shinfo(skb)->gso_size);
6776#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006777 else
6778 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006779
6780 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006781 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6782 tx_buffer_info->gso_segs = gso_segs;
6783 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006784
Alexander Duyckd3d00232011-07-15 02:31:25 +00006785 /* set the timestamp */
6786 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006787
6788 /*
6789 * Force memory writes to complete before letting h/w
6790 * know there are new descriptors to fetch. (Only
6791 * applicable for weak-ordered memory model archs,
6792 * such as IA-64).
6793 */
6794 wmb();
6795
Alexander Duyckd3d00232011-07-15 02:31:25 +00006796 /* set next_to_watch value indicating a packet is present */
6797 first->next_to_watch = tx_desc;
6798
6799 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006800 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006801
6802 return;
6803dma_error:
6804 dev_err(dev, "TX DMA map failed\n");
6805
6806 /* clear dma mappings for failed tx_buffer_info map */
6807 for (;;) {
6808 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6809 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6810 if (tx_buffer_info == first)
6811 break;
6812 if (i == 0)
6813 i = tx_ring->count;
6814 i--;
6815 }
6816
6817 dev_kfree_skb_any(skb);
6818
6819 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006820}
6821
Alexander Duyck69830522011-01-06 14:29:58 +00006822static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6823 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006824{
Alexander Duyck69830522011-01-06 14:29:58 +00006825 struct ixgbe_q_vector *q_vector = ring->q_vector;
6826 union ixgbe_atr_hash_dword input = { .dword = 0 };
6827 union ixgbe_atr_hash_dword common = { .dword = 0 };
6828 union {
6829 unsigned char *network;
6830 struct iphdr *ipv4;
6831 struct ipv6hdr *ipv6;
6832 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006833 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006834 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006835
Alexander Duyck69830522011-01-06 14:29:58 +00006836 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6837 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006838 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006839
Alexander Duyck69830522011-01-06 14:29:58 +00006840 /* do nothing if sampling is disabled */
6841 if (!ring->atr_sample_rate)
6842 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006843
Alexander Duyck69830522011-01-06 14:29:58 +00006844 ring->atr_count++;
6845
6846 /* snag network header to get L4 type and address */
6847 hdr.network = skb_network_header(skb);
6848
6849 /* Currently only IPv4/IPv6 with TCP is supported */
6850 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6851 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6852 (protocol != __constant_htons(ETH_P_IP) ||
6853 hdr.ipv4->protocol != IPPROTO_TCP))
6854 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006855
6856 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006857
Alexander Duyck66f32a82011-06-29 05:43:22 +00006858 /* skip this packet since it is invalid or the socket is closing */
6859 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006860 return;
6861
6862 /* sample on all syn packets or once every atr sample count */
6863 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6864 return;
6865
6866 /* reset sample count */
6867 ring->atr_count = 0;
6868
6869 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6870
6871 /*
6872 * src and dst are inverted, think how the receiver sees them
6873 *
6874 * The input is broken into two sections, a non-compressed section
6875 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6876 * is XORed together and stored in the compressed dword.
6877 */
6878 input.formatted.vlan_id = vlan_id;
6879
6880 /*
6881 * since src port and flex bytes occupy the same word XOR them together
6882 * and write the value to source port portion of compressed dword
6883 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006884 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006885 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6886 else
6887 common.port.src ^= th->dest ^ protocol;
6888 common.port.dst ^= th->source;
6889
6890 if (protocol == __constant_htons(ETH_P_IP)) {
6891 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6892 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6893 } else {
6894 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6895 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6896 hdr.ipv6->saddr.s6_addr32[1] ^
6897 hdr.ipv6->saddr.s6_addr32[2] ^
6898 hdr.ipv6->saddr.s6_addr32[3] ^
6899 hdr.ipv6->daddr.s6_addr32[0] ^
6900 hdr.ipv6->daddr.s6_addr32[1] ^
6901 hdr.ipv6->daddr.s6_addr32[2] ^
6902 hdr.ipv6->daddr.s6_addr32[3];
6903 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006904
6905 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006906 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6907 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006908}
6909
Alexander Duyck63544e92011-05-27 05:31:42 +00006910static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006911{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006912 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006913 /* Herbert's original patch had:
6914 * smp_mb__after_netif_stop_queue();
6915 * but since that doesn't exist yet, just open code it. */
6916 smp_mb();
6917
6918 /* We need to check again in a case another CPU has just
6919 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006920 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006921 return -EBUSY;
6922
6923 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006924 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006925 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006926 return 0;
6927}
6928
Alexander Duyck82d4e462011-06-11 01:44:58 +00006929static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006930{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006931 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006932 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006933 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006934}
6935
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006936static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6937{
6938 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006939 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6940 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006941#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006942 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006943
John Fastabende5b64632011-03-08 03:44:52 +00006944 if (((protocol == htons(ETH_P_FCOE)) ||
6945 (protocol == htons(ETH_P_FIP))) &&
6946 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6947 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6948 txq += adapter->ring_feature[RING_F_FCOE].mask;
6949 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006950 }
6951#endif
6952
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006953 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6954 while (unlikely(txq >= dev->real_num_tx_queues))
6955 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006956 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006957 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006958
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006959 return skb_tx_hash(dev, skb);
6960}
6961
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006962netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006963 struct ixgbe_adapter *adapter,
6964 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006965{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006966 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006967 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006968 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006969#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6970 unsigned short f;
6971#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006972 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006973 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006974 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006975
Alexander Duycka535c302011-05-27 05:31:52 +00006976 /*
6977 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6978 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6979 * + 2 desc gap to keep tail from touching head,
6980 * + 1 desc for context descriptor,
6981 * otherwise try next time
6982 */
6983#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6984 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6985 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6986#else
6987 count += skb_shinfo(skb)->nr_frags;
6988#endif
6989 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6990 tx_ring->tx_stats.tx_busy++;
6991 return NETDEV_TX_BUSY;
6992 }
6993
Alexander Duyck7f9643f2011-06-29 05:43:27 +00006994#ifdef CONFIG_PCI_IOV
6995 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
6996 tx_flags |= IXGBE_TX_FLAGS_TXSW;
6997
6998#endif
Alexander Duyck66f32a82011-06-29 05:43:22 +00006999 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00007000 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007001 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7002 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7003 /* else if it is a SW VLAN check the next protocol and store the tag */
7004 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
7005 struct vlan_hdr *vhdr, _vhdr;
7006 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
7007 if (!vhdr)
7008 goto out_drop;
7009
7010 protocol = vhdr->h_vlan_encapsulated_proto;
7011 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
7012 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07007013 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007014
John Fastabend32701dc2011-09-27 03:51:56 +00007015 /* DCB maps skb priorities 0-7 onto 3 bit PCP of VLAN tag. */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007016 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
Alexander Duyck09dca472011-07-20 00:09:10 +00007017 ((tx_flags & (IXGBE_TX_FLAGS_HW_VLAN | IXGBE_TX_FLAGS_SW_VLAN)) ||
7018 (skb->priority != TC_PRIO_CONTROL))) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00007019 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabend32701dc2011-09-27 03:51:56 +00007020 tx_flags |= (skb->priority & 0x7) <<
7021 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007022 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
7023 struct vlan_ethhdr *vhdr;
7024 if (skb_header_cloned(skb) &&
7025 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
7026 goto out_drop;
7027 vhdr = (struct vlan_ethhdr *)skb->data;
7028 vhdr->h_vlan_TCI = htons(tx_flags >>
7029 IXGBE_TX_FLAGS_VLAN_SHIFT);
7030 } else {
7031 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
7032 }
7033 }
Alexander Duycka535c302011-05-27 05:31:52 +00007034
Alexander Duycka535c302011-05-27 05:31:52 +00007035 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007036 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00007037
Yi Zoueacd73f2009-05-13 13:11:06 +00007038#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00007039 /* setup tx offload for FCoE */
7040 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
7041 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00007042 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
7043 if (tso < 0)
7044 goto out_drop;
7045 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00007046 tx_flags |= IXGBE_TX_FLAGS_FSO |
7047 IXGBE_TX_FLAGS_FCOE;
7048 else
7049 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07007050
Alexander Duyck66f32a82011-06-29 05:43:22 +00007051 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00007052 }
Auke Kok9a799d72007-09-15 14:07:45 -07007053
Auke Kok9a799d72007-09-15 14:07:45 -07007054#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00007055 /* setup IPv4/IPv6 offloads */
7056 if (protocol == __constant_htons(ETH_P_IP))
7057 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007058
Alexander Duyck66f32a82011-06-29 05:43:22 +00007059 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
7060 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07007061 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00007062 else if (tso)
7063 tx_flags |= IXGBE_TX_FLAGS_TSO;
7064 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
7065 tx_flags |= IXGBE_TX_FLAGS_CSUM;
7066
7067 /* add the ATR filter if ATR is on */
7068 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7069 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
7070
7071#ifdef IXGBE_FCOE
7072xmit_fcoe:
7073#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00007074 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
7075
7076 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007077
7078 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00007079
7080out_drop:
7081 dev_kfree_skb_any(skb);
7082 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07007083}
7084
7085static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7086{
7087 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7088 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007089
Auke Kok9a799d72007-09-15 14:07:45 -07007090 tx_ring = adapter->tx_ring[skb->queue_mapping];
7091 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
7092}
7093
7094/**
7095 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007096 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07007097 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007098 *
Auke Kok9a799d72007-09-15 14:07:45 -07007099 * Returns 0 on success, negative on failure
7100 **/
7101static int ixgbe_set_mac(struct net_device *netdev, void *p)
7102{
Ben Hutchings6b73e102009-04-29 08:08:58 +00007103 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7104 struct ixgbe_hw *hw = &adapter->hw;
7105 struct sockaddr *addr = p;
7106
7107 if (!is_valid_ether_addr(addr->sa_data))
7108 return -EADDRNOTAVAIL;
7109
7110 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
7111 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
7112
7113 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7114 IXGBE_RAH_AV);
7115
7116 return 0;
7117}
7118
7119static int
7120ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7121{
7122 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7123 struct ixgbe_hw *hw = &adapter->hw;
7124 u16 value;
7125 int rc;
7126
7127 if (prtad != hw->phy.mdio.prtad)
7128 return -EINVAL;
7129 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7130 if (!rc)
7131 rc = value;
7132 return rc;
7133}
7134
7135static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7136 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007137{
7138 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00007139 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007140
7141 if (prtad != hw->phy.mdio.prtad)
7142 return -EINVAL;
7143 return hw->phy.ops.write_reg(hw, addr, devad, value);
7144}
7145
7146static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7147{
7148 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7149
7150 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7151}
7152
7153/**
7154 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
7155 * netdev->dev_addrs
7156 * @netdev: network interface device structure
7157 *
7158 * Returns non-zero on failure
7159 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00007160static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007161{
7162 int err = 0;
7163 struct ixgbe_adapter *adapter = netdev_priv(dev);
7164 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7165
7166 if (is_valid_ether_addr(mac->san_addr)) {
7167 rtnl_lock();
7168 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7169 rtnl_unlock();
7170 }
7171 return err;
7172}
7173
7174/**
7175 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
7176 * netdev->dev_addrs
7177 * @netdev: network interface device structure
7178 *
Auke Kok9a799d72007-09-15 14:07:45 -07007179 * Returns non-zero on failure
7180 **/
7181static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7182{
7183 int err = 0;
7184 struct ixgbe_adapter *adapter = netdev_priv(dev);
7185 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7186
7187 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007188 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07007189 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007190 rtnl_unlock();
7191 }
7192 return err;
7193}
Auke Kok9a799d72007-09-15 14:07:45 -07007194
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007195#ifdef CONFIG_NET_POLL_CONTROLLER
7196/*
7197 * Polling 'interrupt' - used by things like netconsole to send skbs
7198 * without having to re-enable interrupts. It's not called while
7199 * the interrupt routine is executing.
7200 */
7201static void ixgbe_netpoll(struct net_device *netdev)
7202{
7203 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007204 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007205
7206 /* if interface is down do nothing */
7207 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007208 return;
7209
7210 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007211 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007212 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007213 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007214 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck4ff7fb12011-08-31 00:01:11 +00007215 ixgbe_msix_clean_rings(0, q_vector);
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007216 }
7217 } else {
7218 ixgbe_intr(adapter->pdev->irq, netdev);
7219 }
7220 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
7221}
7222#endif
7223
Eric Dumazetde1036b2010-10-20 23:00:04 +00007224static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7225 struct rtnl_link_stats64 *stats)
7226{
7227 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7228 int i;
7229
Eric Dumazet1a515022010-11-16 19:26:42 -08007230 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007231 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007232 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007233 u64 bytes, packets;
7234 unsigned int start;
7235
Eric Dumazet1a515022010-11-16 19:26:42 -08007236 if (ring) {
7237 do {
7238 start = u64_stats_fetch_begin_bh(&ring->syncp);
7239 packets = ring->stats.packets;
7240 bytes = ring->stats.bytes;
7241 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7242 stats->rx_packets += packets;
7243 stats->rx_bytes += bytes;
7244 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007245 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007246
7247 for (i = 0; i < adapter->num_tx_queues; i++) {
7248 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7249 u64 bytes, packets;
7250 unsigned int start;
7251
7252 if (ring) {
7253 do {
7254 start = u64_stats_fetch_begin_bh(&ring->syncp);
7255 packets = ring->stats.packets;
7256 bytes = ring->stats.bytes;
7257 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7258 stats->tx_packets += packets;
7259 stats->tx_bytes += bytes;
7260 }
7261 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007262 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007263 /* following stats updated by ixgbe_watchdog_task() */
7264 stats->multicast = netdev->stats.multicast;
7265 stats->rx_errors = netdev->stats.rx_errors;
7266 stats->rx_length_errors = netdev->stats.rx_length_errors;
7267 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7268 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7269 return stats;
7270}
7271
John Fastabend8b1c0b22011-05-03 02:26:48 +00007272/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7273 * #adapter: pointer to ixgbe_adapter
7274 * @tc: number of traffic classes currently enabled
7275 *
7276 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7277 * 802.1Q priority maps to a packet buffer that exists.
7278 */
7279static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7280{
7281 struct ixgbe_hw *hw = &adapter->hw;
7282 u32 reg, rsave;
7283 int i;
7284
7285 /* 82598 have a static priority to TC mapping that can not
7286 * be changed so no validation is needed.
7287 */
7288 if (hw->mac.type == ixgbe_mac_82598EB)
7289 return;
7290
7291 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7292 rsave = reg;
7293
7294 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7295 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7296
7297 /* If up2tc is out of bounds default to zero */
7298 if (up2tc > tc)
7299 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7300 }
7301
7302 if (reg != rsave)
7303 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7304
7305 return;
7306}
7307
7308
7309/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7310 * classes.
7311 *
7312 * @netdev: net device to configure
7313 * @tc: number of traffic classes to enable
7314 */
7315int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7316{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007317 struct ixgbe_adapter *adapter = netdev_priv(dev);
7318 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007319
John Fastabende7589ea2011-07-18 22:38:36 +00007320 /* Multiple traffic classes requires multiple queues */
7321 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
7322 e_err(drv, "Enable failed, needs MSI-X\n");
7323 return -EINVAL;
7324 }
John Fastabend8b1c0b22011-05-03 02:26:48 +00007325
7326 /* Hardware supports up to 8 traffic classes */
John Fastabend4de2a022011-09-27 03:52:01 +00007327 if (tc > adapter->dcb_cfg.num_tcs.pg_tcs ||
John Fastabend8b1c0b22011-05-03 02:26:48 +00007328 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7329 return -EINVAL;
7330
7331 /* Hardware has to reinitialize queues and interrupts to
Stephen Hemminger52f33af2011-12-22 16:34:52 +00007332 * match packet buffer alignment. Unfortunately, the
John Fastabend8b1c0b22011-05-03 02:26:48 +00007333 * hardware is not flexible enough to do this dynamically.
7334 */
7335 if (netif_running(dev))
7336 ixgbe_close(dev);
7337 ixgbe_clear_interrupt_scheme(adapter);
7338
John Fastabende7589ea2011-07-18 22:38:36 +00007339 if (tc) {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007340 netdev_set_num_tc(dev, tc);
John Fastabende7589ea2011-07-18 22:38:36 +00007341 adapter->last_lfc_mode = adapter->hw.fc.current_mode;
7342
7343 adapter->flags |= IXGBE_FLAG_DCB_ENABLED;
7344 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7345
7346 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
7347 adapter->hw.fc.requested_mode = ixgbe_fc_none;
7348 } else {
John Fastabend8b1c0b22011-05-03 02:26:48 +00007349 netdev_reset_tc(dev);
7350
John Fastabende7589ea2011-07-18 22:38:36 +00007351 adapter->hw.fc.requested_mode = adapter->last_lfc_mode;
7352
7353 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
7354 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7355
7356 adapter->temp_dcb_cfg.pfc_mode_enable = false;
7357 adapter->dcb_cfg.pfc_mode_enable = false;
7358 }
7359
John Fastabend8b1c0b22011-05-03 02:26:48 +00007360 ixgbe_init_interrupt_scheme(adapter);
7361 ixgbe_validate_rtr(adapter, tc);
7362 if (netif_running(dev))
7363 ixgbe_open(dev);
7364
7365 return 0;
7366}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007367
Don Skidmore082757a2011-07-21 05:55:00 +00007368void ixgbe_do_reset(struct net_device *netdev)
7369{
7370 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7371
7372 if (netif_running(netdev))
7373 ixgbe_reinit_locked(adapter);
7374 else
7375 ixgbe_reset(adapter);
7376}
7377
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007378static netdev_features_t ixgbe_fix_features(struct net_device *netdev,
7379 netdev_features_t data)
Don Skidmore082757a2011-07-21 05:55:00 +00007380{
7381 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7382
7383#ifdef CONFIG_DCB
7384 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7385 data &= ~NETIF_F_HW_VLAN_RX;
7386#endif
7387
7388 /* return error if RXHASH is being enabled when RSS is not supported */
7389 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7390 data &= ~NETIF_F_RXHASH;
7391
7392 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7393 if (!(data & NETIF_F_RXCSUM))
7394 data &= ~NETIF_F_LRO;
7395
7396 /* Turn off LRO if not RSC capable or invalid ITR settings */
7397 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7398 data &= ~NETIF_F_LRO;
7399 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7400 (adapter->rx_itr_setting != 1 &&
7401 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7402 data &= ~NETIF_F_LRO;
7403 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7404 }
7405
7406 return data;
7407}
7408
Michał Mirosławc8f44af2011-11-15 15:29:55 +00007409static int ixgbe_set_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 bool need_reset = false;
7414
7415 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7416 if (!(data & NETIF_F_RXCSUM))
7417 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7418 else
7419 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7420
7421 /* Make sure RSC matches LRO, reset if change */
7422 if (!!(data & NETIF_F_LRO) !=
7423 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7424 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7425 switch (adapter->hw.mac.type) {
7426 case ixgbe_mac_X540:
7427 case ixgbe_mac_82599EB:
7428 need_reset = true;
7429 break;
7430 default:
7431 break;
7432 }
7433 }
7434
7435 /*
7436 * Check if Flow Director n-tuple support was enabled or disabled. If
7437 * the state changed, we need to reset.
7438 */
7439 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7440 /* turn off ATR, enable perfect filters and reset */
7441 if (data & NETIF_F_NTUPLE) {
7442 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7443 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7444 need_reset = true;
7445 }
7446 } else if (!(data & NETIF_F_NTUPLE)) {
7447 /* turn off Flow Director, set ATR and reset */
7448 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7449 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7450 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7451 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7452 need_reset = true;
7453 }
7454
7455 if (need_reset)
7456 ixgbe_do_reset(netdev);
7457
7458 return 0;
7459
7460}
7461
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007462static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007463 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007464 .ndo_stop = ixgbe_close,
7465 .ndo_start_xmit = ixgbe_xmit_frame,
7466 .ndo_select_queue = ixgbe_select_queue,
7467 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007468 .ndo_validate_addr = eth_validate_addr,
7469 .ndo_set_mac_address = ixgbe_set_mac,
7470 .ndo_change_mtu = ixgbe_change_mtu,
7471 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007472 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7473 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007474 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007475 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7476 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7477 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
Greg Rosede4c7f62011-09-29 05:57:33 +00007478 .ndo_set_vf_spoofchk = ixgbe_ndo_set_vf_spoofchk,
Greg Rose7f016482010-05-04 22:12:06 +00007479 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007480 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007481 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007482#ifdef CONFIG_NET_POLL_CONTROLLER
7483 .ndo_poll_controller = ixgbe_netpoll,
7484#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007485#ifdef IXGBE_FCOE
7486 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007487 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007488 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007489 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7490 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007491 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Neerav Parikhea818752012-01-04 20:23:40 +00007492 .ndo_fcoe_get_hbainfo = ixgbe_fcoe_get_hbainfo,
Yi Zou332d4a72009-05-13 13:11:53 +00007493#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007494 .ndo_set_features = ixgbe_set_features,
7495 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007496};
7497
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007498static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7499 const struct ixgbe_info *ii)
7500{
7501#ifdef CONFIG_PCI_IOV
7502 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007503
Greg Rosec6bda302011-08-24 02:37:55 +00007504 if (hw->mac.type == ixgbe_mac_82598EB)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007505 return;
7506
7507 /* The 82599 supports up to 64 VFs per physical function
7508 * but this implementation limits allocation to 63 so that
7509 * basic networking resources are still available to the
7510 * physical function
7511 */
7512 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
Greg Rosec6bda302011-08-24 02:37:55 +00007513 ixgbe_enable_sriov(adapter, ii);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007514#endif /* CONFIG_PCI_IOV */
7515}
7516
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007517/**
Auke Kok9a799d72007-09-15 14:07:45 -07007518 * ixgbe_probe - Device Initialization Routine
7519 * @pdev: PCI device information struct
7520 * @ent: entry in ixgbe_pci_tbl
7521 *
7522 * Returns 0 on success, negative on failure
7523 *
7524 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7525 * The OS initialization, configuring of the adapter private structure,
7526 * and a hardware reset occur.
7527 **/
7528static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007529 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007530{
7531 struct net_device *netdev;
7532 struct ixgbe_adapter *adapter = NULL;
7533 struct ixgbe_hw *hw;
7534 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007535 static int cards_found;
7536 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007537 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007538 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007539#ifdef IXGBE_FCOE
7540 u16 device_caps;
7541#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007542 u32 eec;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007543 u16 wol_cap;
Auke Kok9a799d72007-09-15 14:07:45 -07007544
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007545 /* Catch broken hardware that put the wrong VF device ID in
7546 * the PCIe SR-IOV capability.
7547 */
7548 if (pdev->is_virtfn) {
7549 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7550 pci_name(pdev), pdev->vendor, pdev->device);
7551 return -EINVAL;
7552 }
7553
gouji-new9ce77662009-05-06 10:44:45 +00007554 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007555 if (err)
7556 return err;
7557
Nick Nunley1b507732010-04-27 13:10:27 +00007558 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7559 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007560 pci_using_dac = 1;
7561 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007562 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007563 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007564 err = dma_set_coherent_mask(&pdev->dev,
7565 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007566 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007567 dev_err(&pdev->dev,
7568 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007569 goto err_dma;
7570 }
7571 }
7572 pci_using_dac = 0;
7573 }
7574
gouji-new9ce77662009-05-06 10:44:45 +00007575 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007576 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007577 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007578 dev_err(&pdev->dev,
7579 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007580 goto err_pci_reg;
7581 }
7582
Frans Pop19d5afd2009-10-02 10:04:12 -07007583 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007584
Auke Kok9a799d72007-09-15 14:07:45 -07007585 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007586 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007587
John Fastabende901acd2011-04-26 07:26:08 +00007588#ifdef CONFIG_IXGBE_DCB
7589 indices *= MAX_TRAFFIC_CLASS;
7590#endif
7591
John Fastabendc85a2612010-02-25 23:15:21 +00007592 if (ii->mac == ixgbe_mac_82598EB)
7593 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7594 else
7595 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7596
John Fastabende901acd2011-04-26 07:26:08 +00007597#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007598 indices += min_t(unsigned int, num_possible_cpus(),
7599 IXGBE_MAX_FCOE_INDICES);
7600#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007601 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007602 if (!netdev) {
7603 err = -ENOMEM;
7604 goto err_alloc_etherdev;
7605 }
7606
Auke Kok9a799d72007-09-15 14:07:45 -07007607 SET_NETDEV_DEV(netdev, &pdev->dev);
7608
Auke Kok9a799d72007-09-15 14:07:45 -07007609 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007610 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007611
7612 adapter->netdev = netdev;
7613 adapter->pdev = pdev;
7614 hw = &adapter->hw;
7615 hw->back = adapter;
7616 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7617
Jeff Kirsher05857982008-09-11 19:57:00 -07007618 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007619 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007620 if (!hw->hw_addr) {
7621 err = -EIO;
7622 goto err_ioremap;
7623 }
7624
7625 for (i = 1; i <= 5; i++) {
7626 if (pci_resource_len(pdev, i) == 0)
7627 continue;
7628 }
7629
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007630 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007631 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007632 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007633 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007634
Auke Kok9a799d72007-09-15 14:07:45 -07007635 adapter->bd_number = cards_found;
7636
Auke Kok9a799d72007-09-15 14:07:45 -07007637 /* Setup hw api */
7638 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007639 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007640
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007641 /* EEPROM */
7642 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7643 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7644 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7645 if (!(eec & (1 << 8)))
7646 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7647
7648 /* PHY */
7649 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007650 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007651 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7652 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7653 hw->phy.mdio.mmds = 0;
7654 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7655 hw->phy.mdio.dev = netdev;
7656 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7657 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007658
Don Skidmore8ca783a2009-05-26 20:40:47 -07007659 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007660
7661 /* setup the private structure */
7662 err = ixgbe_sw_init(adapter);
7663 if (err)
7664 goto err_sw_init;
7665
Don Skidmoree86bff02010-02-11 04:14:08 +00007666 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007667 switch (adapter->hw.mac.type) {
7668 case ixgbe_mac_82599EB:
7669 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007670 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007671 break;
7672 default:
7673 break;
7674 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007675
Don Skidmorebf069c92009-05-07 10:39:54 +00007676 /*
7677 * If there is a fan on this device and it has failed log the
7678 * failure.
7679 */
7680 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7681 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7682 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007683 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007684 }
7685
Peter P Waskiewicz Jr8ef78ad2012-02-01 09:19:21 +00007686 if (allow_unsupported_sfp)
7687 hw->allow_unsupported_sfp = allow_unsupported_sfp;
7688
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007689 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007690 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007691 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007692 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007693 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7694 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007695 err = 0;
7696 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007697 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007698 "module type was detected.\n");
7699 e_dev_err("Reload the driver after installing a supported "
7700 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007701 goto err_sw_init;
7702 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007703 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007704 goto err_sw_init;
7705 }
7706
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007707 ixgbe_probe_vf(adapter, ii);
7708
Emil Tantilov396e7992010-07-01 20:05:12 +00007709 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007710 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007711 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007712 NETIF_F_HW_VLAN_TX |
7713 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007714 NETIF_F_HW_VLAN_FILTER |
7715 NETIF_F_TSO |
7716 NETIF_F_TSO6 |
Don Skidmore082757a2011-07-21 05:55:00 +00007717 NETIF_F_RXHASH |
7718 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007719
Don Skidmore082757a2011-07-21 05:55:00 +00007720 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007721
Don Skidmore58be7662011-04-12 09:42:11 +00007722 switch (adapter->hw.mac.type) {
7723 case ixgbe_mac_82599EB:
7724 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007725 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007726 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7727 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007728 break;
7729 default:
7730 break;
7731 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007732
Jeff Kirsherad31c402008-06-05 04:05:30 -07007733 netdev->vlan_features |= NETIF_F_TSO;
7734 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007735 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007736 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007737 netdev->vlan_features |= NETIF_F_SG;
7738
Jiri Pirko01789342011-08-16 06:29:00 +00007739 netdev->priv_flags |= IFF_UNICAST_FLT;
7740
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007741 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7742 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7743 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007744
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007745#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007746 netdev->dcbnl_ops = &dcbnl_ops;
7747#endif
7748
Yi Zoueacd73f2009-05-13 13:11:06 +00007749#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007750 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007751 if (hw->mac.ops.get_device_caps) {
7752 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007753 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7754 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007755 }
7756 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007757 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7758 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7759 netdev->vlan_features |= NETIF_F_FSO;
7760 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7761 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007762#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007763 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007764 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007765 netdev->vlan_features |= NETIF_F_HIGHDMA;
7766 }
Auke Kok9a799d72007-09-15 14:07:45 -07007767
Don Skidmore082757a2011-07-21 05:55:00 +00007768 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7769 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007770 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007771 netdev->features |= NETIF_F_LRO;
7772
Auke Kok9a799d72007-09-15 14:07:45 -07007773 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007774 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007775 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007776 err = -EIO;
7777 goto err_eeprom;
7778 }
7779
7780 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7781 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7782
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007783 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007784 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007785 err = -EIO;
7786 goto err_eeprom;
7787 }
7788
Alexander Duyck70864002011-04-27 09:13:56 +00007789 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7790 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007791
Alexander Duyck70864002011-04-27 09:13:56 +00007792 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7793 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007794
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007795 err = ixgbe_init_interrupt_scheme(adapter);
7796 if (err)
7797 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007798
Don Skidmore082757a2011-07-21 05:55:00 +00007799 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7800 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007801 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007802 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007803
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007804 /* WOL not supported for all but the following */
7805 adapter->wol = 0;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007806 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007807 case IXGBE_DEV_ID_82599_SFP:
Don Skidmore0e22d042011-12-10 06:49:43 +00007808 /* Only these subdevice supports WOL */
7809 switch (pdev->subsystem_device) {
7810 case IXGBE_SUBDEV_ID_82599_560FLR:
7811 /* only support first port */
7812 if (hw->bus.func != 0)
7813 break;
7814 case IXGBE_SUBDEV_ID_82599_SFP:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007815 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0e22d042011-12-10 06:49:43 +00007816 break;
7817 }
Don Skidmore0b077fe2010-12-03 03:32:13 +00007818 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007819 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7820 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007821 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007822 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007823 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007824 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007825 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007826 break;
Emil Tantilovc23f5b62011-08-16 07:34:18 +00007827 case IXGBE_DEV_ID_X540T:
7828 /* Check eeprom to see if it is enabled */
7829 hw->eeprom.ops.read(hw, 0x2c, &adapter->eeprom_cap);
7830 wol_cap = adapter->eeprom_cap & IXGBE_DEVICE_CAPS_WOL_MASK;
7831
7832 if ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0_1) ||
7833 ((wol_cap == IXGBE_DEVICE_CAPS_WOL_PORT0) &&
7834 (hw->bus.func == 0)))
7835 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007836 break;
7837 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007838 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7839
Emil Tantilov15e52092011-09-29 05:01:29 +00007840 /* save off EEPROM version number */
7841 hw->eeprom.ops.read(hw, 0x2e, &adapter->eeprom_verh);
7842 hw->eeprom.ops.read(hw, 0x2d, &adapter->eeprom_verl);
7843
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007844 /* pick up the PCI bus settings for reporting later */
7845 hw->mac.ops.get_bus_info(hw);
7846
Auke Kok9a799d72007-09-15 14:07:45 -07007847 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007848 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007849 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7850 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007851 "Unknown"),
7852 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7853 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7854 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7855 "Unknown"),
7856 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007857
7858 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7859 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007860 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007861 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007862 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007863 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007864 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007865 else
Don Skidmore289700db2010-12-03 03:32:58 +00007866 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7867 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007868
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007869 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007870 e_dev_warn("PCI-Express bandwidth available for this card is "
7871 "not sufficient for optimal performance.\n");
7872 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7873 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007874 }
7875
Auke Kok9a799d72007-09-15 14:07:45 -07007876 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007877 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007878
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007879 if (err == IXGBE_ERR_EEPROM_VERSION) {
7880 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007881 e_dev_warn("This device is a pre-production adapter/LOM. "
7882 "Please be aware there may be issues associated "
7883 "with your hardware. If you are experiencing "
7884 "problems please contact your Intel or hardware "
7885 "representative who provided you with this "
7886 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007887 }
Auke Kok9a799d72007-09-15 14:07:45 -07007888 strcpy(netdev->name, "eth%d");
7889 err = register_netdev(netdev);
7890 if (err)
7891 goto err_register;
7892
Emil Tantilov93d3ce82011-10-19 07:59:55 +00007893 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7894 if (hw->mac.ops.disable_tx_laser &&
7895 ((hw->phy.multispeed_fiber) ||
7896 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
7897 (hw->mac.type == ixgbe_mac_82599EB))))
7898 hw->mac.ops.disable_tx_laser(hw);
7899
Jesse Brandeburg54386462009-04-17 20:44:27 +00007900 /* carrier off reporting is important to ethtool even BEFORE open */
7901 netif_carrier_off(netdev);
7902
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007903#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007904 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007905 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007906 ixgbe_setup_dca(adapter);
7907 }
7908#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007909 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007910 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007911 for (i = 0; i < adapter->num_vfs; i++)
7912 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7913 }
7914
Jacob Keller2466dd92011-09-08 03:50:54 +00007915 /* firmware requires driver version to be 0xFFFFFFFF
7916 * since os does not support feature
7917 */
Emil Tantilov9612de92011-05-07 07:40:20 +00007918 if (hw->mac.ops.set_fw_drv_ver)
Jacob Keller2466dd92011-09-08 03:50:54 +00007919 hw->mac.ops.set_fw_drv_ver(hw, 0xFF, 0xFF, 0xFF,
7920 0xFF);
Emil Tantilov9612de92011-05-07 07:40:20 +00007921
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007922 /* add san mac addr to netdev */
7923 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007924
Neerav Parikhea818752012-01-04 20:23:40 +00007925 e_dev_info("%s\n", ixgbe_default_device_descr);
Auke Kok9a799d72007-09-15 14:07:45 -07007926 cards_found++;
7927 return 0;
7928
7929err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007930 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007931 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007932err_sw_init:
7933err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007934 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7935 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007936 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007937 iounmap(hw->hw_addr);
7938err_ioremap:
7939 free_netdev(netdev);
7940err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007941 pci_release_selected_regions(pdev,
7942 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007943err_pci_reg:
7944err_dma:
7945 pci_disable_device(pdev);
7946 return err;
7947}
7948
7949/**
7950 * ixgbe_remove - Device Removal Routine
7951 * @pdev: PCI device information struct
7952 *
7953 * ixgbe_remove is called by the PCI subsystem to alert the driver
7954 * that it should release a PCI device. The could be caused by a
7955 * Hot-Plug event, or because the driver is going to be removed from
7956 * memory.
7957 **/
7958static void __devexit ixgbe_remove(struct pci_dev *pdev)
7959{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007960 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7961 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007962
7963 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007964 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007965
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007966#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007967 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7968 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7969 dca_remove_requester(&pdev->dev);
7970 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7971 }
7972
7973#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007974#ifdef IXGBE_FCOE
7975 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7976 ixgbe_cleanup_fcoe(adapter);
7977
7978#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007979
7980 /* remove the added san mac */
7981 ixgbe_del_sanmac_netdev(netdev);
7982
Donald Skidmorec4900be2008-11-20 21:11:42 -08007983 if (netdev->reg_state == NETREG_REGISTERED)
7984 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007985
Greg Rosec6bda302011-08-24 02:37:55 +00007986 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
7987 if (!(ixgbe_check_vf_assignment(adapter)))
7988 ixgbe_disable_sriov(adapter);
7989 else
7990 e_dev_warn("Unloading driver while VFs are assigned "
7991 "- VFs will not be deallocated\n");
7992 }
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007993
Alexander Duyck7a921c92009-05-06 10:43:28 +00007994 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007995
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007996 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007997
7998 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007999 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008000 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07008001
Emil Tantilov849c4542010-06-03 16:53:41 +00008002 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08008003
Auke Kok9a799d72007-09-15 14:07:45 -07008004 free_netdev(netdev);
8005
Frans Pop19d5afd2009-10-02 10:04:12 -07008006 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008007
Auke Kok9a799d72007-09-15 14:07:45 -07008008 pci_disable_device(pdev);
8009}
8010
8011/**
8012 * ixgbe_io_error_detected - called when PCI error is detected
8013 * @pdev: Pointer to PCI device
8014 * @state: The current pci connection state
8015 *
8016 * This function is called after a PCI bus error affecting
8017 * this device has been detected.
8018 */
8019static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00008020 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07008021{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008022 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8023 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008024
Greg Rose83c61fa2011-09-07 05:59:35 +00008025#ifdef CONFIG_PCI_IOV
8026 struct pci_dev *bdev, *vfdev;
8027 u32 dw0, dw1, dw2, dw3;
8028 int vf, pos;
8029 u16 req_id, pf_func;
8030
8031 if (adapter->hw.mac.type == ixgbe_mac_82598EB ||
8032 adapter->num_vfs == 0)
8033 goto skip_bad_vf_detection;
8034
8035 bdev = pdev->bus->self;
8036 while (bdev && (bdev->pcie_type != PCI_EXP_TYPE_ROOT_PORT))
8037 bdev = bdev->bus->self;
8038
8039 if (!bdev)
8040 goto skip_bad_vf_detection;
8041
8042 pos = pci_find_ext_capability(bdev, PCI_EXT_CAP_ID_ERR);
8043 if (!pos)
8044 goto skip_bad_vf_detection;
8045
8046 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG, &dw0);
8047 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 4, &dw1);
8048 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 8, &dw2);
8049 pci_read_config_dword(bdev, pos + PCI_ERR_HEADER_LOG + 12, &dw3);
8050
8051 req_id = dw1 >> 16;
8052 /* On the 82599 if bit 7 of the requestor ID is set then it's a VF */
8053 if (!(req_id & 0x0080))
8054 goto skip_bad_vf_detection;
8055
8056 pf_func = req_id & 0x01;
8057 if ((pf_func & 1) == (pdev->devfn & 1)) {
8058 unsigned int device_id;
8059
8060 vf = (req_id & 0x7F) >> 1;
8061 e_dev_err("VF %d has caused a PCIe error\n", vf);
8062 e_dev_err("TLP: dw0: %8.8x\tdw1: %8.8x\tdw2: "
8063 "%8.8x\tdw3: %8.8x\n",
8064 dw0, dw1, dw2, dw3);
8065 switch (adapter->hw.mac.type) {
8066 case ixgbe_mac_82599EB:
8067 device_id = IXGBE_82599_VF_DEVICE_ID;
8068 break;
8069 case ixgbe_mac_X540:
8070 device_id = IXGBE_X540_VF_DEVICE_ID;
8071 break;
8072 default:
8073 device_id = 0;
8074 break;
8075 }
8076
8077 /* Find the pci device of the offending VF */
8078 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID, device_id, NULL);
8079 while (vfdev) {
8080 if (vfdev->devfn == (req_id & 0xFF))
8081 break;
8082 vfdev = pci_get_device(IXGBE_INTEL_VENDOR_ID,
8083 device_id, vfdev);
8084 }
8085 /*
8086 * There's a slim chance the VF could have been hot plugged,
8087 * so if it is no longer present we don't need to issue the
8088 * VFLR. Just clean up the AER in that case.
8089 */
8090 if (vfdev) {
8091 e_dev_err("Issuing VFLR to VF %d\n", vf);
8092 pci_write_config_dword(vfdev, 0xA8, 0x00008000);
8093 }
8094
8095 pci_cleanup_aer_uncorrect_error_status(pdev);
8096 }
8097
8098 /*
8099 * Even though the error may have occurred on the other port
8100 * we still need to increment the vf error reference count for
8101 * both ports because the I/O resume function will be called
8102 * for both of them.
8103 */
8104 adapter->vferr_refcount++;
8105
8106 return PCI_ERS_RESULT_RECOVERED;
8107
8108skip_bad_vf_detection:
8109#endif /* CONFIG_PCI_IOV */
Auke Kok9a799d72007-09-15 14:07:45 -07008110 netif_device_detach(netdev);
8111
Breno Leitao3044b8d2009-05-06 10:44:26 +00008112 if (state == pci_channel_io_perm_failure)
8113 return PCI_ERS_RESULT_DISCONNECT;
8114
Auke Kok9a799d72007-09-15 14:07:45 -07008115 if (netif_running(netdev))
8116 ixgbe_down(adapter);
8117 pci_disable_device(pdev);
8118
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008119 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07008120 return PCI_ERS_RESULT_NEED_RESET;
8121}
8122
8123/**
8124 * ixgbe_io_slot_reset - called after the pci bus has been reset.
8125 * @pdev: Pointer to PCI device
8126 *
8127 * Restart the card from scratch, as if from a cold-boot.
8128 */
8129static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
8130{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008131 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008132 pci_ers_result_t result;
8133 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07008134
gouji-new9ce77662009-05-06 10:44:45 +00008135 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00008136 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008137 result = PCI_ERS_RESULT_DISCONNECT;
8138 } else {
8139 pci_set_master(pdev);
8140 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00008141 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008142
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07008143 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008144
8145 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00008146 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008147 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07008148 }
Auke Kok9a799d72007-09-15 14:07:45 -07008149
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008150 err = pci_cleanup_aer_uncorrect_error_status(pdev);
8151 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00008152 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
8153 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008154 /* non-fatal, continue */
8155 }
Auke Kok9a799d72007-09-15 14:07:45 -07008156
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08008157 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07008158}
8159
8160/**
8161 * ixgbe_io_resume - called when traffic can start flowing again.
8162 * @pdev: Pointer to PCI device
8163 *
8164 * This callback is called when the error recovery driver tells us that
8165 * its OK to resume normal operation.
8166 */
8167static void ixgbe_io_resume(struct pci_dev *pdev)
8168{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08008169 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
8170 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07008171
Greg Rose83c61fa2011-09-07 05:59:35 +00008172#ifdef CONFIG_PCI_IOV
8173 if (adapter->vferr_refcount) {
8174 e_info(drv, "Resuming after VF err\n");
8175 adapter->vferr_refcount--;
8176 return;
8177 }
8178
8179#endif
Alexander Duyckc7ccde02011-07-21 00:40:40 +00008180 if (netif_running(netdev))
8181 ixgbe_up(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07008182
8183 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07008184}
8185
8186static struct pci_error_handlers ixgbe_err_handler = {
8187 .error_detected = ixgbe_io_error_detected,
8188 .slot_reset = ixgbe_io_slot_reset,
8189 .resume = ixgbe_io_resume,
8190};
8191
8192static struct pci_driver ixgbe_driver = {
8193 .name = ixgbe_driver_name,
8194 .id_table = ixgbe_pci_tbl,
8195 .probe = ixgbe_probe,
8196 .remove = __devexit_p(ixgbe_remove),
8197#ifdef CONFIG_PM
8198 .suspend = ixgbe_suspend,
8199 .resume = ixgbe_resume,
8200#endif
8201 .shutdown = ixgbe_shutdown,
8202 .err_handler = &ixgbe_err_handler
8203};
8204
8205/**
8206 * ixgbe_init_module - Driver Registration Routine
8207 *
8208 * ixgbe_init_module is the first routine called when the driver is
8209 * loaded. All it does is register with the PCI subsystem.
8210 **/
8211static int __init ixgbe_init_module(void)
8212{
8213 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00008214 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00008215 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07008216
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008217#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008218 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008219#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008220
Auke Kok9a799d72007-09-15 14:07:45 -07008221 ret = pci_register_driver(&ixgbe_driver);
8222 return ret;
8223}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07008224
Auke Kok9a799d72007-09-15 14:07:45 -07008225module_init(ixgbe_init_module);
8226
8227/**
8228 * ixgbe_exit_module - Driver Exit Cleanup Routine
8229 *
8230 * ixgbe_exit_module is called just before the driver is removed
8231 * from memory.
8232 **/
8233static void __exit ixgbe_exit_module(void)
8234{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008235#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008236 dca_unregister_notify(&dca_notifier);
8237#endif
Auke Kok9a799d72007-09-15 14:07:45 -07008238 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08008239 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07008240}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008241
Jeff Garzik5dd2d332008-10-16 05:09:31 -04008242#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008243static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008244 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008245{
8246 int ret_val;
8247
8248 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00008249 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008250
8251 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
8252}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08008253
Alexander Duyckb4533682009-03-31 21:32:42 +00008254#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00008255
Auke Kok9a799d72007-09-15 14:07:45 -07008256module_exit(ixgbe_exit_module);
8257
8258/* ixgbe_main.c */