blob: 2dce3d0381881887d3adafed71c50bdb8e34bdc6 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 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>
35#include <linux/ip.h>
36#include <linux/tcp.h>
Lucy Liu60127862009-07-22 14:07:33 +000037#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070038#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090039#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <net/checksum.h>
41#include <net/ip6_checksum.h>
42#include <linux/ethtool.h>
43#include <linux/if_vlan.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000044#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070045
46#include "ixgbe.h"
47#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000048#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000049#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070050
51char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070052static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000053 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000054#define MAJ 3
Don Skidmorec89c7112011-04-14 07:40:11 +000055#define MIN 3
56#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000057#define KFIX 2
58#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
59 __stringify(BUILD) "-k" __stringify(KFIX)
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070060const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000061static const char ixgbe_copyright[] =
62 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070063
64static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070065 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000066 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080067 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070068};
69
70/* ixgbe_pci_tbl - PCI Device ID Table
71 *
72 * Wildcard entries (PCI_ANY_ID) should come last
73 * Last entry must be all 0s
74 *
75 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
76 * Class, Class Mask, private data (not used) }
77 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000078static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
80 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070082 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
86 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
88 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070090 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
92 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
94 board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
96 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070097 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
98 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
100 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
102 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
104 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
106 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
108 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
110 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
112 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
114 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
116 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
118 board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
120 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
122 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
124 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000126 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
128 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
130 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700131
132 /* required last entry */
133 {0, }
134};
135MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
136
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400137#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800138static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000139 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800140static struct notifier_block dca_notifier = {
141 .notifier_call = ixgbe_notify_dca,
142 .next = NULL,
143 .priority = 0
144};
145#endif
146
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000147#ifdef CONFIG_PCI_IOV
148static unsigned int max_vfs;
149module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000150MODULE_PARM_DESC(max_vfs,
151 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000152#endif /* CONFIG_PCI_IOV */
153
Auke Kok9a799d72007-09-15 14:07:45 -0700154MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
155MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
156MODULE_LICENSE("GPL");
157MODULE_VERSION(DRV_VERSION);
158
159#define DEFAULT_DEBUG_LEVEL_SHIFT 3
160
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000161static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
162{
163 struct ixgbe_hw *hw = &adapter->hw;
164 u32 gcr;
165 u32 gpie;
166 u32 vmdctl;
167
168#ifdef CONFIG_PCI_IOV
169 /* disable iov and allow time for transactions to clear */
170 pci_disable_sriov(adapter->pdev);
171#endif
172
173 /* turn off device IOV mode */
174 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
175 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
176 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
177 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
178 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
179 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
180
181 /* set default pool back to 0 */
182 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
183 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
184 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
185
186 /* take a breather then clean up driver data */
187 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000188
189 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000190 adapter->vfinfo = NULL;
191
192 adapter->num_vfs = 0;
193 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
194}
195
Alexander Duyck70864002011-04-27 09:13:56 +0000196static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
197{
198 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
199 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
200 schedule_work(&adapter->service_task);
201}
202
203static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
204{
205 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
206
207 /* flush memory to make sure state is correct before next watchog */
208 smp_mb__before_clear_bit();
209 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
210}
211
Taku Izumidcd79ae2010-04-27 14:39:53 +0000212struct ixgbe_reg_info {
213 u32 ofs;
214 char *name;
215};
216
217static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
218
219 /* General Registers */
220 {IXGBE_CTRL, "CTRL"},
221 {IXGBE_STATUS, "STATUS"},
222 {IXGBE_CTRL_EXT, "CTRL_EXT"},
223
224 /* Interrupt Registers */
225 {IXGBE_EICR, "EICR"},
226
227 /* RX Registers */
228 {IXGBE_SRRCTL(0), "SRRCTL"},
229 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
230 {IXGBE_RDLEN(0), "RDLEN"},
231 {IXGBE_RDH(0), "RDH"},
232 {IXGBE_RDT(0), "RDT"},
233 {IXGBE_RXDCTL(0), "RXDCTL"},
234 {IXGBE_RDBAL(0), "RDBAL"},
235 {IXGBE_RDBAH(0), "RDBAH"},
236
237 /* TX Registers */
238 {IXGBE_TDBAL(0), "TDBAL"},
239 {IXGBE_TDBAH(0), "TDBAH"},
240 {IXGBE_TDLEN(0), "TDLEN"},
241 {IXGBE_TDH(0), "TDH"},
242 {IXGBE_TDT(0), "TDT"},
243 {IXGBE_TXDCTL(0), "TXDCTL"},
244
245 /* List Terminator */
246 {}
247};
248
249
250/*
251 * ixgbe_regdump - register printout routine
252 */
253static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
254{
255 int i = 0, j = 0;
256 char rname[16];
257 u32 regs[64];
258
259 switch (reginfo->ofs) {
260 case IXGBE_SRRCTL(0):
261 for (i = 0; i < 64; i++)
262 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
263 break;
264 case IXGBE_DCA_RXCTRL(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
267 break;
268 case IXGBE_RDLEN(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
271 break;
272 case IXGBE_RDH(0):
273 for (i = 0; i < 64; i++)
274 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
275 break;
276 case IXGBE_RDT(0):
277 for (i = 0; i < 64; i++)
278 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
279 break;
280 case IXGBE_RXDCTL(0):
281 for (i = 0; i < 64; i++)
282 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
283 break;
284 case IXGBE_RDBAL(0):
285 for (i = 0; i < 64; i++)
286 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
287 break;
288 case IXGBE_RDBAH(0):
289 for (i = 0; i < 64; i++)
290 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
291 break;
292 case IXGBE_TDBAL(0):
293 for (i = 0; i < 64; i++)
294 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
295 break;
296 case IXGBE_TDBAH(0):
297 for (i = 0; i < 64; i++)
298 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
299 break;
300 case IXGBE_TDLEN(0):
301 for (i = 0; i < 64; i++)
302 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
303 break;
304 case IXGBE_TDH(0):
305 for (i = 0; i < 64; i++)
306 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
307 break;
308 case IXGBE_TDT(0):
309 for (i = 0; i < 64; i++)
310 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
311 break;
312 case IXGBE_TXDCTL(0):
313 for (i = 0; i < 64; i++)
314 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
315 break;
316 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000317 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000318 IXGBE_READ_REG(hw, reginfo->ofs));
319 return;
320 }
321
322 for (i = 0; i < 8; i++) {
323 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000324 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000325 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000326 pr_cont(" %08x", regs[i*8+j]);
327 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000328 }
329
330}
331
332/*
333 * ixgbe_dump - Print registers, tx-rings and rx-rings
334 */
335static void ixgbe_dump(struct ixgbe_adapter *adapter)
336{
337 struct net_device *netdev = adapter->netdev;
338 struct ixgbe_hw *hw = &adapter->hw;
339 struct ixgbe_reg_info *reginfo;
340 int n = 0;
341 struct ixgbe_ring *tx_ring;
342 struct ixgbe_tx_buffer *tx_buffer_info;
343 union ixgbe_adv_tx_desc *tx_desc;
344 struct my_u0 { u64 a; u64 b; } *u0;
345 struct ixgbe_ring *rx_ring;
346 union ixgbe_adv_rx_desc *rx_desc;
347 struct ixgbe_rx_buffer *rx_buffer_info;
348 u32 staterr;
349 int i = 0;
350
351 if (!netif_msg_hw(adapter))
352 return;
353
354 /* Print netdevice Info */
355 if (netdev) {
356 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000357 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000358 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000359 pr_info("%-15s %016lX %016lX %016lX\n",
360 netdev->name,
361 netdev->state,
362 netdev->trans_start,
363 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000364 }
365
366 /* Print Registers */
367 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000368 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000369 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
370 reginfo->name; reginfo++) {
371 ixgbe_regdump(hw, reginfo);
372 }
373
374 /* Print TX Ring Summary */
375 if (!netdev || !netif_running(netdev))
376 goto exit;
377
378 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000379 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000380 for (n = 0; n < adapter->num_tx_queues; n++) {
381 tx_ring = adapter->tx_ring[n];
382 tx_buffer_info =
383 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000384 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000385 n, tx_ring->next_to_use, tx_ring->next_to_clean,
386 (u64)tx_buffer_info->dma,
387 tx_buffer_info->length,
388 tx_buffer_info->next_to_watch,
389 (u64)tx_buffer_info->time_stamp);
390 }
391
392 /* Print TX Rings */
393 if (!netif_msg_tx_done(adapter))
394 goto rx_ring_summary;
395
396 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
397
398 /* Transmit Descriptor Formats
399 *
400 * Advanced Transmit Descriptor
401 * +--------------------------------------------------------------+
402 * 0 | Buffer Address [63:0] |
403 * +--------------------------------------------------------------+
404 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
405 * +--------------------------------------------------------------+
406 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
407 */
408
409 for (n = 0; n < adapter->num_tx_queues; n++) {
410 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000411 pr_info("------------------------------------\n");
412 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
413 pr_info("------------------------------------\n");
414 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000415 "[PlPOIdStDDt Ln] [bi->dma ] "
416 "leng ntw timestamp bi->skb\n");
417
418 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000419 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000420 tx_buffer_info = &tx_ring->tx_buffer_info[i];
421 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000422 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000423 " %04X %3X %016llX %p", i,
424 le64_to_cpu(u0->a),
425 le64_to_cpu(u0->b),
426 (u64)tx_buffer_info->dma,
427 tx_buffer_info->length,
428 tx_buffer_info->next_to_watch,
429 (u64)tx_buffer_info->time_stamp,
430 tx_buffer_info->skb);
431 if (i == tx_ring->next_to_use &&
432 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000433 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000434 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000435 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000437 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000438 else
Joe Perchesc7689572010-09-07 21:35:17 +0000439 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000440
441 if (netif_msg_pktdata(adapter) &&
442 tx_buffer_info->dma != 0)
443 print_hex_dump(KERN_INFO, "",
444 DUMP_PREFIX_ADDRESS, 16, 1,
445 phys_to_virt(tx_buffer_info->dma),
446 tx_buffer_info->length, true);
447 }
448 }
449
450 /* Print RX Rings Summary */
451rx_ring_summary:
452 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000453 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000454 for (n = 0; n < adapter->num_rx_queues; n++) {
455 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000456 pr_info("%5d %5X %5X\n",
457 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000458 }
459
460 /* Print RX Rings */
461 if (!netif_msg_rx_status(adapter))
462 goto exit;
463
464 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
465
466 /* Advanced Receive Descriptor (Read) Format
467 * 63 1 0
468 * +-----------------------------------------------------+
469 * 0 | Packet Buffer Address [63:1] |A0/NSE|
470 * +----------------------------------------------+------+
471 * 8 | Header Buffer Address [63:1] | DD |
472 * +-----------------------------------------------------+
473 *
474 *
475 * Advanced Receive Descriptor (Write-Back) Format
476 *
477 * 63 48 47 32 31 30 21 20 16 15 4 3 0
478 * +------------------------------------------------------+
479 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
480 * | Checksum Ident | | | | Type | Type |
481 * +------------------------------------------------------+
482 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
483 * +------------------------------------------------------+
484 * 63 48 47 32 31 20 19 0
485 */
486 for (n = 0; n < adapter->num_rx_queues; n++) {
487 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000488 pr_info("------------------------------------\n");
489 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
490 pr_info("------------------------------------\n");
491 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000492 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
493 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000494 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000495 "[vl er S cks ln] ---------------- [bi->skb] "
496 "<-- Adv Rx Write-Back format\n");
497
498 for (i = 0; i < rx_ring->count; i++) {
499 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000500 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000501 u0 = (struct my_u0 *)rx_desc;
502 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
503 if (staterr & IXGBE_RXD_STAT_DD) {
504 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000505 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000506 "%016llX ---------------- %p", i,
507 le64_to_cpu(u0->a),
508 le64_to_cpu(u0->b),
509 rx_buffer_info->skb);
510 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000511 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000512 "%016llX %016llX %p", i,
513 le64_to_cpu(u0->a),
514 le64_to_cpu(u0->b),
515 (u64)rx_buffer_info->dma,
516 rx_buffer_info->skb);
517
518 if (netif_msg_pktdata(adapter)) {
519 print_hex_dump(KERN_INFO, "",
520 DUMP_PREFIX_ADDRESS, 16, 1,
521 phys_to_virt(rx_buffer_info->dma),
522 rx_ring->rx_buf_len, true);
523
524 if (rx_ring->rx_buf_len
525 < IXGBE_RXBUFFER_2048)
526 print_hex_dump(KERN_INFO, "",
527 DUMP_PREFIX_ADDRESS, 16, 1,
528 phys_to_virt(
529 rx_buffer_info->page_dma +
530 rx_buffer_info->page_offset
531 ),
532 PAGE_SIZE/2, true);
533 }
534 }
535
536 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000537 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000538 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000539 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 else
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542
543 }
544 }
545
546exit:
547 return;
548}
549
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800550static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
551{
552 u32 ctrl_ext;
553
554 /* Let firmware take over control of h/w */
555 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
556 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000557 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800558}
559
560static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
561{
562 u32 ctrl_ext;
563
564 /* Let firmware know the driver has taken over */
565 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
566 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000567 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800568}
Auke Kok9a799d72007-09-15 14:07:45 -0700569
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000570/*
571 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
572 * @adapter: pointer to adapter struct
573 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
574 * @queue: queue to map the corresponding interrupt to
575 * @msix_vector: the vector to map to the corresponding queue
576 *
577 */
578static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000579 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700580{
581 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000582 struct ixgbe_hw *hw = &adapter->hw;
583 switch (hw->mac.type) {
584 case ixgbe_mac_82598EB:
585 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
586 if (direction == -1)
587 direction = 0;
588 index = (((direction * 64) + queue) >> 2) & 0x1F;
589 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
590 ivar &= ~(0xFF << (8 * (queue & 0x3)));
591 ivar |= (msix_vector << (8 * (queue & 0x3)));
592 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
593 break;
594 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800595 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000596 if (direction == -1) {
597 /* other causes */
598 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
599 index = ((queue & 1) * 8);
600 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
601 ivar &= ~(0xFF << index);
602 ivar |= (msix_vector << index);
603 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
604 break;
605 } else {
606 /* tx or rx causes */
607 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
608 index = ((16 * (queue & 1)) + (8 * direction));
609 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
610 ivar &= ~(0xFF << index);
611 ivar |= (msix_vector << index);
612 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
613 break;
614 }
615 default:
616 break;
617 }
Auke Kok9a799d72007-09-15 14:07:45 -0700618}
619
Alexander Duyckfe49f042009-06-04 16:00:09 +0000620static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000621 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000622{
623 u32 mask;
624
Alexander Duyckbd508172010-11-16 19:27:03 -0800625 switch (adapter->hw.mac.type) {
626 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000627 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800629 break;
630 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800631 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000632 mask = (qmask & 0xFFFFFFFF);
633 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
634 mask = (qmask >> 32);
635 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800636 break;
637 default:
638 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000639 }
640}
641
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800642void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
643 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700644{
Alexander Duycke5a43542009-12-02 16:46:56 +0000645 if (tx_buffer_info->dma) {
646 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800647 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000648 tx_buffer_info->dma,
649 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000650 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000651 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800652 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000653 tx_buffer_info->dma,
654 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000655 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000656 tx_buffer_info->dma = 0;
657 }
Auke Kok9a799d72007-09-15 14:07:45 -0700658 if (tx_buffer_info->skb) {
659 dev_kfree_skb_any(tx_buffer_info->skb);
660 tx_buffer_info->skb = NULL;
661 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000662 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700663 /* tx_buffer_info must be completely set up in the transmit path */
664}
665
Yi Zou26f23d82009-11-06 12:56:00 +0000666/**
John Fastabendc84d3242010-11-16 19:27:12 -0800667 * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class
668 * @adapter: driver private struct
669 * @index: reg idx of queue to query (0-127)
Yi Zou26f23d82009-11-06 12:56:00 +0000670 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300671 * Helper function to determine the traffic index for a particular
John Fastabendc84d3242010-11-16 19:27:12 -0800672 * register index.
Yi Zou26f23d82009-11-06 12:56:00 +0000673 *
John Fastabendc84d3242010-11-16 19:27:12 -0800674 * Returns : a tc index for use in range 0-7, or 0-3
Yi Zou26f23d82009-11-06 12:56:00 +0000675 */
Don Skidmore3b2ee942011-01-28 02:28:26 +0000676static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx)
Yi Zou26f23d82009-11-06 12:56:00 +0000677{
John Fastabendc84d3242010-11-16 19:27:12 -0800678 int tc = -1;
John Fastabende5b64632011-03-08 03:44:52 +0000679 int dcb_i = netdev_get_num_tc(adapter->netdev);
Yi Zou26f23d82009-11-06 12:56:00 +0000680
John Fastabendc84d3242010-11-16 19:27:12 -0800681 /* if DCB is not enabled the queues have no TC */
682 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
683 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000684
John Fastabendc84d3242010-11-16 19:27:12 -0800685 /* check valid range */
686 if (reg_idx >= adapter->hw.mac.max_tx_queues)
687 return tc;
688
689 switch (adapter->hw.mac.type) {
690 case ixgbe_mac_82598EB:
691 tc = reg_idx >> 2;
692 break;
693 default:
694 if (dcb_i != 4 && dcb_i != 8)
PJ Waskiewicz6837e892010-01-06 17:50:29 +0000695 break;
John Fastabendc84d3242010-11-16 19:27:12 -0800696
697 /* if VMDq is enabled the lowest order bits determine TC */
698 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
699 IXGBE_FLAG_VMDQ_ENABLED)) {
700 tc = reg_idx & (dcb_i - 1);
Alexander Duyckbd508172010-11-16 19:27:03 -0800701 break;
Yi Zou26f23d82009-11-06 12:56:00 +0000702 }
John Fastabendc84d3242010-11-16 19:27:12 -0800703
704 /*
705 * Convert the reg_idx into the correct TC. This bitmask
706 * targets the last full 32 ring traffic class and assigns
707 * it a value of 1. From there the rest of the rings are
708 * based on shifting the mask further up to include the
709 * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i
710 * will only ever be 8 or 4 and that reg_idx will never
711 * be greater then 128. The code without the power of 2
712 * optimizations would be:
713 * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32)
714 */
715 tc = ((reg_idx & 0X1F) + 0x20) * dcb_i;
716 tc >>= 9 - (reg_idx >> 5);
Yi Zou26f23d82009-11-06 12:56:00 +0000717 }
John Fastabendc84d3242010-11-16 19:27:12 -0800718
719 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000720}
721
John Fastabendc84d3242010-11-16 19:27:12 -0800722static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700723{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700724 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800725 struct ixgbe_hw_stats *hwstats = &adapter->stats;
726 u32 data = 0;
727 u32 xoff[8] = {0};
728 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700729
John Fastabendc84d3242010-11-16 19:27:12 -0800730 if ((hw->fc.current_mode == ixgbe_fc_full) ||
731 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
732 switch (hw->mac.type) {
733 case ixgbe_mac_82598EB:
734 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
735 break;
736 default:
737 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
738 }
739 hwstats->lxoffrxc += data;
740
741 /* refill credits (no tx hang) if we received xoff */
742 if (!data)
743 return;
744
745 for (i = 0; i < adapter->num_tx_queues; i++)
746 clear_bit(__IXGBE_HANG_CHECK_ARMED,
747 &adapter->tx_ring[i]->state);
748 return;
749 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
750 return;
751
752 /* update stats for each tc, only valid with PFC enabled */
753 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
754 switch (hw->mac.type) {
755 case ixgbe_mac_82598EB:
756 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
757 break;
758 default:
759 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
760 }
761 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700762 }
763
John Fastabendc84d3242010-11-16 19:27:12 -0800764 /* disarm tx queues that have received xoff frames */
765 for (i = 0; i < adapter->num_tx_queues; i++) {
766 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
767 u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx);
768
769 if (xoff[tc])
770 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
771 }
772}
773
774static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
775{
776 return ring->tx_stats.completed;
777}
778
779static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
780{
781 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
782 struct ixgbe_hw *hw = &adapter->hw;
783
784 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
785 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
786
787 if (head != tail)
788 return (head < tail) ?
789 tail - head : (tail + ring->count - head);
790
791 return 0;
792}
793
794static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
795{
796 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
797 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
798 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
799 bool ret = false;
800
801 clear_check_for_tx_hang(tx_ring);
802
803 /*
804 * Check for a hung queue, but be thorough. This verifies
805 * that a transmit has been completed since the previous
806 * check AND there is at least one packet pending. The
807 * ARMED bit is set to indicate a potential hang. The
808 * bit is cleared if a pause frame is received to remove
809 * false hang detection due to PFC or 802.3x frames. By
810 * requiring this to fail twice we avoid races with
811 * pfc clearing the ARMED bit and conditions where we
812 * run the check_tx_hang logic with a transmit completion
813 * pending but without time to complete it yet.
814 */
815 if ((tx_done_old == tx_done) && tx_pending) {
816 /* make sure it is true for two checks in a row */
817 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
818 &tx_ring->state);
819 } else {
820 /* update completed stats and continue */
821 tx_ring->tx_stats.tx_done_old = tx_done;
822 /* reset the countdown */
823 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
824 }
825
826 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700827}
828
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700829#define IXGBE_MAX_TXD_PWR 14
830#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800831
832/* Tx Descriptors needed, worst case */
833#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
834 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
835#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700836 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800837
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000838/**
839 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
840 * @adapter: driver private struct
841 **/
842static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
843{
844
845 /* Do the reset outside of interrupt context */
846 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
847 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
848 ixgbe_service_event_schedule(adapter);
849 }
850}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700851
Auke Kok9a799d72007-09-15 14:07:45 -0700852/**
853 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000854 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700855 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700856 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000857static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000858 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700859{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000860 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800861 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
862 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700863 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800864 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700865
866 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800867 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000868 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800869
870 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000871 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800872 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000873 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800874 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000875 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700876 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700877
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800878 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800879 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800880
Auke Kok9a799d72007-09-15 14:07:45 -0700881 i++;
882 if (i == tx_ring->count)
883 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800884
885 if (cleaned && tx_buffer_info->skb) {
886 total_bytes += tx_buffer_info->bytecount;
887 total_packets += tx_buffer_info->gso_segs;
888 }
889
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800890 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800891 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700892 }
893
John Fastabendc84d3242010-11-16 19:27:12 -0800894 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800895 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000896 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800897 }
898
Auke Kok9a799d72007-09-15 14:07:45 -0700899 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800900 tx_ring->total_bytes += total_bytes;
901 tx_ring->total_packets += total_packets;
902 u64_stats_update_begin(&tx_ring->syncp);
903 tx_ring->stats.packets += total_packets;
904 tx_ring->stats.bytes += total_bytes;
905 u64_stats_update_end(&tx_ring->syncp);
906
John Fastabendc84d3242010-11-16 19:27:12 -0800907 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800908 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800909 struct ixgbe_hw *hw = &adapter->hw;
910 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
911 e_err(drv, "Detected Tx Unit Hang\n"
912 " Tx Queue <%d>\n"
913 " TDH, TDT <%x>, <%x>\n"
914 " next_to_use <%x>\n"
915 " next_to_clean <%x>\n"
916 "tx_buffer_info[next_to_clean]\n"
917 " time_stamp <%lx>\n"
918 " jiffies <%lx>\n",
919 tx_ring->queue_index,
920 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
921 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
922 tx_ring->next_to_use, eop,
923 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
924
925 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
926
927 e_info(probe,
928 "tx hang %d detected on queue %d, resetting adapter\n",
929 adapter->tx_timeout_count + 1, tx_ring->queue_index);
930
931 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000932 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800933
934 /* the adapter is about to reset, no point in enabling stuff */
935 return true;
936 }
Auke Kok9a799d72007-09-15 14:07:45 -0700937
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800938#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800939 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Joe Perchese8e9f692010-09-07 21:34:53 +0000940 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800941 /* Make sure that anybody stopping the queue after this
942 * sees the new next_to_clean.
943 */
944 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800945 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800946 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800947 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800948 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800949 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800950 }
Auke Kok9a799d72007-09-15 14:07:45 -0700951
Eric Dumazet807540b2010-09-23 05:40:09 +0000952 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700953}
954
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400955#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800956static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800957 struct ixgbe_ring *rx_ring,
958 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800959{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800960 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800961 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800963
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800964 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
965 switch (hw->mac.type) {
966 case ixgbe_mac_82598EB:
967 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
968 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
969 break;
970 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800971 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800972 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
973 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
974 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
975 break;
976 default:
977 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800978 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800979 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
980 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
981 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800982 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800983}
984
985static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800986 struct ixgbe_ring *tx_ring,
987 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800988{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000989 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800990 u32 txctrl;
991 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800992
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800993 switch (hw->mac.type) {
994 case ixgbe_mac_82598EB:
995 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
996 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
997 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
998 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800999 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
1000 break;
1001 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001002 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001003 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
1004 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
1005 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
1006 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
1007 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001008 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
1009 break;
1010 default:
1011 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001012 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001013}
1014
1015static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1016{
1017 struct ixgbe_adapter *adapter = q_vector->adapter;
1018 int cpu = get_cpu();
1019 long r_idx;
1020 int i;
1021
1022 if (q_vector->cpu == cpu)
1023 goto out_no_update;
1024
1025 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1026 for (i = 0; i < q_vector->txr_count; i++) {
1027 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
1028 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1029 r_idx + 1);
1030 }
1031
1032 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1033 for (i = 0; i < q_vector->rxr_count; i++) {
1034 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1035 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1036 r_idx + 1);
1037 }
1038
1039 q_vector->cpu = cpu;
1040out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001041 put_cpu();
1042}
1043
1044static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1045{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001046 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001047 int i;
1048
1049 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1050 return;
1051
Alexander Duycke35ec122009-05-21 13:07:12 +00001052 /* always use CB2 mode, difference is masked in the CB driver */
1053 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1054
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001055 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1056 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1057 else
1058 num_q_vectors = 1;
1059
1060 for (i = 0; i < num_q_vectors; i++) {
1061 adapter->q_vector[i]->cpu = -1;
1062 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001063 }
1064}
1065
1066static int __ixgbe_notify_dca(struct device *dev, void *data)
1067{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001068 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001069 unsigned long event = *(unsigned long *)data;
1070
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001071 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1072 return 0;
1073
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001074 switch (event) {
1075 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001076 /* if we're already enabled, don't do it again */
1077 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1078 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001079 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001080 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001081 ixgbe_setup_dca(adapter);
1082 break;
1083 }
1084 /* Fall Through since DCA is disabled. */
1085 case DCA_PROVIDER_REMOVE:
1086 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1087 dca_remove_requester(dev);
1088 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1089 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1090 }
1091 break;
1092 }
1093
Denis V. Lunev652f0932008-03-27 14:39:17 +03001094 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001095}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001096#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001097
1098static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1099 struct sk_buff *skb)
1100{
1101 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1102}
1103
Auke Kok9a799d72007-09-15 14:07:45 -07001104/**
1105 * ixgbe_receive_skb - Send a completed packet up the stack
1106 * @adapter: board private structure
1107 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001108 * @status: hardware indication of status of receive
1109 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1110 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001111 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001112static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001113 struct sk_buff *skb, u8 status,
1114 struct ixgbe_ring *ring,
1115 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001116{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001117 struct ixgbe_adapter *adapter = q_vector->adapter;
1118 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001119 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1120 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001121
Jesse Grossf62bbb52010-10-20 13:56:10 +00001122 if (is_vlan && (tag & VLAN_VID_MASK))
1123 __vlan_hwaccel_put_tag(skb, tag);
1124
1125 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1126 napi_gro_receive(napi, skb);
1127 else
1128 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001129}
1130
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001131/**
1132 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1133 * @adapter: address of board private structure
1134 * @status_err: hardware indication of status of receive
1135 * @skb: skb currently being received and modified
1136 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001137static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001138 union ixgbe_adv_rx_desc *rx_desc,
1139 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001140{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001141 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1142
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001143 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001144
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001145 /* Rx csum disabled */
1146 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001147 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001148
1149 /* if IP and error */
1150 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1151 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001152 adapter->hw_csum_rx_error++;
1153 return;
1154 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001155
1156 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1157 return;
1158
1159 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001160 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1161
1162 /*
1163 * 82599 errata, UDP frames with a 0 checksum can be marked as
1164 * checksum errors.
1165 */
1166 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1167 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1168 return;
1169
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001170 adapter->hw_csum_rx_error++;
1171 return;
1172 }
1173
Auke Kok9a799d72007-09-15 14:07:45 -07001174 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001175 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001176}
1177
Alexander Duyck84ea2592010-11-16 19:26:49 -08001178static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001179{
1180 /*
1181 * Force memory writes to complete before letting h/w
1182 * know there are new descriptors to fetch. (Only
1183 * applicable for weak-ordered memory model archs,
1184 * such as IA-64).
1185 */
1186 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001187 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001188}
1189
Auke Kok9a799d72007-09-15 14:07:45 -07001190/**
1191 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001192 * @rx_ring: ring to place buffers on
1193 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001194 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001195void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001196{
Auke Kok9a799d72007-09-15 14:07:45 -07001197 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001198 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001199 struct sk_buff *skb;
1200 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001201
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001202 /* do nothing if no valid netdev defined */
1203 if (!rx_ring->netdev)
1204 return;
1205
Auke Kok9a799d72007-09-15 14:07:45 -07001206 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001207 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001208 bi = &rx_ring->rx_buffer_info[i];
1209 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001210
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001211 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001212 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001213 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001214 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001215 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001216 goto no_buffers;
1217 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001218 /* initialize queue mapping */
1219 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001220 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001221 }
Auke Kok9a799d72007-09-15 14:07:45 -07001222
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001223 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001224 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001225 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001226 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001227 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001228 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001229 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001230 bi->dma = 0;
1231 goto no_buffers;
1232 }
Auke Kok9a799d72007-09-15 14:07:45 -07001233 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001234
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001235 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001236 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001237 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001238 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001239 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001240 goto no_buffers;
1241 }
1242 }
1243
1244 if (!bi->page_dma) {
1245 /* use a half page if we're re-using */
1246 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001247 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001248 bi->page,
1249 bi->page_offset,
1250 PAGE_SIZE / 2,
1251 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001252 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001253 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001254 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001255 bi->page_dma = 0;
1256 goto no_buffers;
1257 }
1258 }
1259
1260 /* Refresh the desc even if buffer_addrs didn't change
1261 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001262 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1263 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001264 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001265 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001266 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001267 }
1268
1269 i++;
1270 if (i == rx_ring->count)
1271 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001272 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001273
Auke Kok9a799d72007-09-15 14:07:45 -07001274no_buffers:
1275 if (rx_ring->next_to_use != i) {
1276 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001277 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001278 }
1279}
1280
Alexander Duyckc267fc12010-11-16 19:27:00 -08001281static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001282{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001283 /* HW will not DMA in data larger than the given buffer, even if it
1284 * parses the (NFS, of course) header to be larger. In that case, it
1285 * fills the header buffer and spills the rest into the page.
1286 */
1287 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1288 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1289 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1290 if (hlen > IXGBE_RX_HDR_SIZE)
1291 hlen = IXGBE_RX_HDR_SIZE;
1292 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001293}
1294
Alexander Duyckf8212f92009-04-27 22:42:37 +00001295/**
1296 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1297 * @skb: pointer to the last skb in the rsc queue
1298 *
1299 * This function changes a queue full of hw rsc buffers into a completed
1300 * packet. It uses the ->prev pointers to find the first packet and then
1301 * turns it into the frag list owner.
1302 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001303static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001304{
1305 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001306 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001307
1308 while (skb->prev) {
1309 struct sk_buff *prev = skb->prev;
1310 frag_list_size += skb->len;
1311 skb->prev = NULL;
1312 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001313 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001314 }
1315
1316 skb_shinfo(skb)->frag_list = skb->next;
1317 skb->next = NULL;
1318 skb->len += frag_list_size;
1319 skb->data_len += frag_list_size;
1320 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001321 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1322
Alexander Duyckf8212f92009-04-27 22:42:37 +00001323 return skb;
1324}
1325
Alexander Duyckaa801752010-11-16 19:27:02 -08001326static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1327{
1328 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1329 IXGBE_RXDADV_RSCCNT_MASK);
1330}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001331
Alexander Duyckc267fc12010-11-16 19:27:00 -08001332static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001333 struct ixgbe_ring *rx_ring,
1334 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001335{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001336 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001337 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1338 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1339 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001340 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001341 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001342#ifdef IXGBE_FCOE
1343 int ddp_bytes = 0;
1344#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001345 u32 staterr;
1346 u16 i;
1347 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001348 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001349
1350 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001351 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001352 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001353
1354 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001355 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001356
Milton Miller3c945e52010-02-19 17:44:42 +00001357 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001358
Alexander Duyckc267fc12010-11-16 19:27:00 -08001359 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1360
Auke Kok9a799d72007-09-15 14:07:45 -07001361 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001362 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001363 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001364
Alexander Duyckc267fc12010-11-16 19:27:00 -08001365 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001366 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001367
1368 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001369 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001370 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001371 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001372 !(staterr & IXGBE_RXD_STAT_EOP) &&
1373 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001374 /*
1375 * When HWRSC is enabled, delay unmapping
1376 * of the first packet. It carries the
1377 * header information, HW may still
1378 * access the header after the writeback.
1379 * Only unmap it when EOP is reached
1380 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001381 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001382 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001383 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001384 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001385 rx_buffer_info->dma,
1386 rx_ring->rx_buf_len,
1387 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001388 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001389 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001390
1391 if (ring_is_ps_enabled(rx_ring)) {
1392 hlen = ixgbe_get_hlen(rx_desc);
1393 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1394 } else {
1395 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1396 }
1397
1398 skb_put(skb, hlen);
1399 } else {
1400 /* assume packet split since header is unmapped */
1401 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001402 }
1403
1404 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001405 dma_unmap_page(rx_ring->dev,
1406 rx_buffer_info->page_dma,
1407 PAGE_SIZE / 2,
1408 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001409 rx_buffer_info->page_dma = 0;
1410 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001411 rx_buffer_info->page,
1412 rx_buffer_info->page_offset,
1413 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001414
Alexander Duyckc267fc12010-11-16 19:27:00 -08001415 if ((page_count(rx_buffer_info->page) == 1) &&
1416 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001417 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001418 else
1419 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001420
1421 skb->len += upper_len;
1422 skb->data_len += upper_len;
1423 skb->truesize += upper_len;
1424 }
1425
1426 i++;
1427 if (i == rx_ring->count)
1428 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001429
Alexander Duyck31f05a22010-08-19 13:40:31 +00001430 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001431 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001432 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001433
Alexander Duyckaa801752010-11-16 19:27:02 -08001434 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001435 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1436 IXGBE_RXDADV_NEXTP_SHIFT;
1437 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001438 } else {
1439 next_buffer = &rx_ring->rx_buffer_info[i];
1440 }
1441
Alexander Duyckc267fc12010-11-16 19:27:00 -08001442 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001443 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001444 rx_buffer_info->skb = next_buffer->skb;
1445 rx_buffer_info->dma = next_buffer->dma;
1446 next_buffer->skb = skb;
1447 next_buffer->dma = 0;
1448 } else {
1449 skb->next = next_buffer->skb;
1450 skb->next->prev = skb;
1451 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001452 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001453 goto next_desc;
1454 }
1455
Alexander Duyckaa801752010-11-16 19:27:02 -08001456 if (skb->prev) {
1457 skb = ixgbe_transform_rsc_queue(skb);
1458 /* if we got here without RSC the packet is invalid */
1459 if (!pkt_is_rsc) {
1460 __pskb_trim(skb, 0);
1461 rx_buffer_info->skb = skb;
1462 goto next_desc;
1463 }
1464 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001465
1466 if (ring_is_rsc_enabled(rx_ring)) {
1467 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1468 dma_unmap_single(rx_ring->dev,
1469 IXGBE_RSC_CB(skb)->dma,
1470 rx_ring->rx_buf_len,
1471 DMA_FROM_DEVICE);
1472 IXGBE_RSC_CB(skb)->dma = 0;
1473 IXGBE_RSC_CB(skb)->delay_unmap = false;
1474 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001475 }
1476 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001477 if (ring_is_ps_enabled(rx_ring))
1478 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001479 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001480 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001481 rx_ring->rx_stats.rsc_count +=
1482 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001483 rx_ring->rx_stats.rsc_flush++;
1484 }
1485
1486 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001487 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001488 /* trim packet back to size 0 and recycle it */
1489 __pskb_trim(skb, 0);
1490 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001491 goto next_desc;
1492 }
1493
Don Skidmore8bae1b22009-07-23 18:00:39 +00001494 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001495 if (adapter->netdev->features & NETIF_F_RXHASH)
1496 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001497
1498 /* probably a little skewed due to removing CRC */
1499 total_rx_bytes += skb->len;
1500 total_rx_packets++;
1501
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001502 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001503#ifdef IXGBE_FCOE
1504 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001505 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1506 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1507 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001508 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001509 }
Yi Zou332d4a72009-05-13 13:11:53 +00001510#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001511 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001512
1513next_desc:
1514 rx_desc->wb.upper.status_error = 0;
1515
Alexander Duyckc267fc12010-11-16 19:27:00 -08001516 (*work_done)++;
1517 if (*work_done >= work_to_do)
1518 break;
1519
Auke Kok9a799d72007-09-15 14:07:45 -07001520 /* return some buffers to hardware, one at a time is too slow */
1521 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001522 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001523 cleaned_count = 0;
1524 }
1525
1526 /* use prefetched values */
1527 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001528 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001529 }
1530
Auke Kok9a799d72007-09-15 14:07:45 -07001531 rx_ring->next_to_clean = i;
1532 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1533
1534 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001535 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001536
Yi Zou3d8fd382009-06-08 14:38:44 +00001537#ifdef IXGBE_FCOE
1538 /* include DDPed FCoE data */
1539 if (ddp_bytes > 0) {
1540 unsigned int mss;
1541
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001542 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001543 sizeof(struct fc_frame_header) -
1544 sizeof(struct fcoe_crc_eof);
1545 if (mss > 512)
1546 mss &= ~511;
1547 total_rx_bytes += ddp_bytes;
1548 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1549 }
1550#endif /* IXGBE_FCOE */
1551
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001552 rx_ring->total_packets += total_rx_packets;
1553 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001554 u64_stats_update_begin(&rx_ring->syncp);
1555 rx_ring->stats.packets += total_rx_packets;
1556 rx_ring->stats.bytes += total_rx_bytes;
1557 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001558}
1559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001560static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001561/**
1562 * ixgbe_configure_msix - Configure MSI-X hardware
1563 * @adapter: board private structure
1564 *
1565 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1566 * interrupts.
1567 **/
1568static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1569{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001570 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001571 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001572 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001573
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001574 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1575
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001576 /*
1577 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001578 * corresponding register.
1579 */
1580 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001581 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001582 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001583 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001584 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001585
1586 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001587 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1588 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001589 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001590 adapter->num_rx_queues,
1591 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001592 }
1593 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001594 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001595
1596 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001597 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1598 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001599 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001600 adapter->num_tx_queues,
1601 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001602 }
1603
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001604 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001605 /* tx only */
1606 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001607 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001608 /* rx or mixed */
1609 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001610
Alexander Duyckfe49f042009-06-04 16:00:09 +00001611 ixgbe_write_eitr(q_vector);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001612 /* If Flow Director is enabled, set interrupt affinity */
1613 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1614 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1615 /*
1616 * Allocate the affinity_hint cpumask, assign the mask
1617 * for this vector, and set our affinity_hint for
1618 * this irq.
1619 */
1620 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1621 GFP_KERNEL))
1622 return;
1623 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1624 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1625 q_vector->affinity_mask);
1626 }
Auke Kok9a799d72007-09-15 14:07:45 -07001627 }
1628
Alexander Duyckbd508172010-11-16 19:27:03 -08001629 switch (adapter->hw.mac.type) {
1630 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001631 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001632 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001633 break;
1634 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001635 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001636 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001637 break;
1638
1639 default:
1640 break;
1641 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001642 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001643
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001644 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001645 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001646 if (adapter->num_vfs)
1647 mask &= ~(IXGBE_EIMS_OTHER |
1648 IXGBE_EIMS_MAILBOX |
1649 IXGBE_EIMS_LSC);
1650 else
1651 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001652 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001653}
1654
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001655enum latency_range {
1656 lowest_latency = 0,
1657 low_latency = 1,
1658 bulk_latency = 2,
1659 latency_invalid = 255
1660};
1661
1662/**
1663 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1664 * @adapter: pointer to adapter
1665 * @eitr: eitr setting (ints per sec) to give last timeslice
1666 * @itr_setting: current throttle rate in ints/second
1667 * @packets: the number of packets during this measurement interval
1668 * @bytes: the number of bytes during this measurement interval
1669 *
1670 * Stores a new ITR value based on packets and byte
1671 * counts during the last interrupt. The advantage of per interrupt
1672 * computation is faster updates and more accurate ITR for the current
1673 * traffic pattern. Constants in this function were computed
1674 * based on theoretical maximum wire speed and thresholds were set based
1675 * on testing data as well as attempting to minimize response time
1676 * while increasing bulk throughput.
1677 * this functionality is controlled by the InterruptThrottleRate module
1678 * parameter (see ixgbe_param.c)
1679 **/
1680static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001681 u32 eitr, u8 itr_setting,
1682 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001683{
1684 unsigned int retval = itr_setting;
1685 u32 timepassed_us;
1686 u64 bytes_perint;
1687
1688 if (packets == 0)
1689 goto update_itr_done;
1690
1691
1692 /* simple throttlerate management
1693 * 0-20MB/s lowest (100000 ints/s)
1694 * 20-100MB/s low (20000 ints/s)
1695 * 100-1249MB/s bulk (8000 ints/s)
1696 */
1697 /* what was last interrupt timeslice? */
1698 timepassed_us = 1000000/eitr;
1699 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1700
1701 switch (itr_setting) {
1702 case lowest_latency:
1703 if (bytes_perint > adapter->eitr_low)
1704 retval = low_latency;
1705 break;
1706 case low_latency:
1707 if (bytes_perint > adapter->eitr_high)
1708 retval = bulk_latency;
1709 else if (bytes_perint <= adapter->eitr_low)
1710 retval = lowest_latency;
1711 break;
1712 case bulk_latency:
1713 if (bytes_perint <= adapter->eitr_high)
1714 retval = low_latency;
1715 break;
1716 }
1717
1718update_itr_done:
1719 return retval;
1720}
1721
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001722/**
1723 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001724 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001725 *
1726 * This function is made to be called by ethtool and by the driver
1727 * when it needs to update EITR registers at runtime. Hardware
1728 * specific quirks/differences are taken care of here.
1729 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001730void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001731{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001732 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001733 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001734 int v_idx = q_vector->v_idx;
1735 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1736
Alexander Duyckbd508172010-11-16 19:27:03 -08001737 switch (adapter->hw.mac.type) {
1738 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001739 /* must write high and low 16 bits to reset counter */
1740 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001741 break;
1742 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001743 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001744 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001745 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001746 * max interrupt rate, but there is an errata where it can
1747 * not be zero with RSC
1748 */
1749 if (itr_reg == 8 &&
1750 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1751 itr_reg = 0;
1752
1753 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001754 * set the WDIS bit to not clear the timer bits and cause an
1755 * immediate assertion of the interrupt
1756 */
1757 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001758 break;
1759 default:
1760 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001761 }
1762 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1763}
1764
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001765static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1766{
1767 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001768 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001769 u32 new_itr;
1770 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771
1772 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1773 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001774 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001775 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001776 q_vector->tx_itr,
1777 tx_ring->total_packets,
1778 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001779 /* if the result for this queue would decrease interrupt
1780 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001781 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001782 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001783 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001784 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001785 }
1786
1787 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1788 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001789 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001790 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001791 q_vector->rx_itr,
1792 rx_ring->total_packets,
1793 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001794 /* if the result for this queue would decrease interrupt
1795 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001796 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001797 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001798 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001799 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001800 }
1801
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001802 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001803
1804 switch (current_itr) {
1805 /* counts and packets in update_itr are dependent on these numbers */
1806 case lowest_latency:
1807 new_itr = 100000;
1808 break;
1809 case low_latency:
1810 new_itr = 20000; /* aka hwitr = ~200 */
1811 break;
1812 case bulk_latency:
1813 default:
1814 new_itr = 8000;
1815 break;
1816 }
1817
1818 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001819 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001820 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001821
1822 /* save the algorithm value here, not the smoothed one */
1823 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001824
1825 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001826 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001827}
1828
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001829/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001830 * ixgbe_check_overtemp_subtask - check for over tempurature
1831 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001832 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001833static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001834{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001835 struct ixgbe_hw *hw = &adapter->hw;
1836 u32 eicr = adapter->interrupt_event;
1837
Alexander Duyckf0f97782011-04-22 04:08:09 +00001838 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001839 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001840
Alexander Duyckf0f97782011-04-22 04:08:09 +00001841 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1842 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1843 return;
1844
1845 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1846
Joe Perches7ca647b2010-09-07 21:35:40 +00001847 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001848 case IXGBE_DEV_ID_82599_T3_LOM:
1849 /*
1850 * Since the warning interrupt is for both ports
1851 * we don't have to check if:
1852 * - This interrupt wasn't for our port.
1853 * - We may have missed the interrupt so always have to
1854 * check if we got a LSC
1855 */
1856 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1857 !(eicr & IXGBE_EICR_LSC))
1858 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001859
Alexander Duyckf0f97782011-04-22 04:08:09 +00001860 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1861 u32 autoneg;
1862 bool link_up = false;
1863
Joe Perches7ca647b2010-09-07 21:35:40 +00001864 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1865
Alexander Duyckf0f97782011-04-22 04:08:09 +00001866 if (link_up)
1867 return;
1868 }
1869
1870 /* Check if this is not due to overtemp */
1871 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1872 return;
1873
1874 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001875 default:
1876 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1877 return;
1878 break;
1879 }
1880 e_crit(drv,
1881 "Network adapter has been stopped because it has over heated. "
1882 "Restart the computer. If the problem persists, "
1883 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001884
1885 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001886}
1887
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001888static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1889{
1890 struct ixgbe_hw *hw = &adapter->hw;
1891
1892 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1893 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001894 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001895 /* write to clear the interrupt */
1896 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1897 }
1898}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001899
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001900static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1901{
1902 struct ixgbe_hw *hw = &adapter->hw;
1903
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001904 if (eicr & IXGBE_EICR_GPI_SDP2) {
1905 /* Clear the interrupt */
1906 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001907 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1908 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1909 ixgbe_service_event_schedule(adapter);
1910 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001911 }
1912
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001913 if (eicr & IXGBE_EICR_GPI_SDP1) {
1914 /* Clear the interrupt */
1915 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001916 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1917 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1918 ixgbe_service_event_schedule(adapter);
1919 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001920 }
1921}
1922
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001923static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1924{
1925 struct ixgbe_hw *hw = &adapter->hw;
1926
1927 adapter->lsc_int++;
1928 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1929 adapter->link_check_timeout = jiffies;
1930 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1931 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001932 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001933 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001934 }
1935}
1936
Auke Kok9a799d72007-09-15 14:07:45 -07001937static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1938{
1939 struct net_device *netdev = data;
1940 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1941 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001942 u32 eicr;
1943
1944 /*
1945 * Workaround for Silicon errata. Use clear-by-write instead
1946 * of clear-by-read. Reading with EICS will return the
1947 * interrupt causes without clearing, which later be done
1948 * with the write to EICR.
1949 */
1950 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1951 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001952
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001953 if (eicr & IXGBE_EICR_LSC)
1954 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001955
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001956 if (eicr & IXGBE_EICR_MAILBOX)
1957 ixgbe_msg_task(adapter);
1958
Alexander Duyckbd508172010-11-16 19:27:03 -08001959 switch (hw->mac.type) {
1960 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001961 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001962 /* Handle Flow Director Full threshold interrupt */
1963 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001964 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001965 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001966 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001967 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001968 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001969 &ring->state))
1970 reinit_count++;
1971 }
1972 if (reinit_count) {
1973 /* no more flow director interrupts until after init */
1974 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1975 eicr &= ~IXGBE_EICR_FLOW_DIR;
1976 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1977 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001978 }
1979 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001980 ixgbe_check_sfp_event(adapter, eicr);
1981 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1982 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1983 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1984 adapter->interrupt_event = eicr;
1985 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1986 ixgbe_service_event_schedule(adapter);
1987 }
1988 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001989 break;
1990 default:
1991 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001992 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001993
1994 ixgbe_check_fan_failure(adapter, eicr);
1995
Alexander Duyck70864002011-04-27 09:13:56 +00001996 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001997 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001998 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1999 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07002000
2001 return IRQ_HANDLED;
2002}
2003
Alexander Duyckfe49f042009-06-04 16:00:09 +00002004static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2005 u64 qmask)
2006{
2007 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002008 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002009
Alexander Duyckbd508172010-11-16 19:27:03 -08002010 switch (hw->mac.type) {
2011 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002012 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002013 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2014 break;
2015 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002016 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002017 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002018 if (mask)
2019 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002020 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002021 if (mask)
2022 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2023 break;
2024 default:
2025 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002026 }
2027 /* skip the flush */
2028}
2029
2030static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002031 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002032{
2033 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002034 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002035
Alexander Duyckbd508172010-11-16 19:27:03 -08002036 switch (hw->mac.type) {
2037 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002038 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002039 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2040 break;
2041 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002042 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002043 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002044 if (mask)
2045 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002046 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002047 if (mask)
2048 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2049 break;
2050 default:
2051 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002052 }
2053 /* skip the flush */
2054}
2055
Auke Kok9a799d72007-09-15 14:07:45 -07002056static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2057{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002058 struct ixgbe_q_vector *q_vector = data;
2059 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002060 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002061 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002062
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063 if (!q_vector->txr_count)
2064 return IRQ_HANDLED;
2065
2066 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2067 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002068 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002069 tx_ring->total_bytes = 0;
2070 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002071 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002072 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002073 }
2074
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002075 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002076 napi_schedule(&q_vector->napi);
2077
Auke Kok9a799d72007-09-15 14:07:45 -07002078 return IRQ_HANDLED;
2079}
2080
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002081/**
2082 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2083 * @irq: unused
2084 * @data: pointer to our q_vector struct for this interrupt vector
2085 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002086static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2087{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002088 struct ixgbe_q_vector *q_vector = data;
2089 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002090 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002091 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002092 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002093
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002094#ifdef CONFIG_IXGBE_DCA
2095 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2096 ixgbe_update_dca(q_vector);
2097#endif
2098
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002099 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002100 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002101 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002102 rx_ring->total_bytes = 0;
2103 rx_ring->total_packets = 0;
2104 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002105 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002106 }
2107
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002108 if (!q_vector->rxr_count)
2109 return IRQ_HANDLED;
2110
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002111 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002112 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002113
Auke Kok9a799d72007-09-15 14:07:45 -07002114 return IRQ_HANDLED;
2115}
2116
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002117static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2118{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002119 struct ixgbe_q_vector *q_vector = data;
2120 struct ixgbe_adapter *adapter = q_vector->adapter;
2121 struct ixgbe_ring *ring;
2122 int r_idx;
2123 int i;
2124
2125 if (!q_vector->txr_count && !q_vector->rxr_count)
2126 return IRQ_HANDLED;
2127
2128 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2129 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002130 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002131 ring->total_bytes = 0;
2132 ring->total_packets = 0;
2133 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002134 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002135 }
2136
2137 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2138 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002139 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002140 ring->total_bytes = 0;
2141 ring->total_packets = 0;
2142 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002143 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002144 }
2145
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002146 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002147 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002148
2149 return IRQ_HANDLED;
2150}
2151
2152/**
2153 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2154 * @napi: napi struct with our devices info in it
2155 * @budget: amount of work driver is allowed to do this pass, in packets
2156 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002157 * This function is optimized for cleaning one queue only on a single
2158 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002159 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002160static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2161{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002162 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002163 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002164 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002165 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002166 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002167 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002168
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002169#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002170 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002171 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002172#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002173
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002174 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2175 rx_ring = adapter->rx_ring[r_idx];
2176
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002177 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002178
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002179 /* If all Rx work done, exit the polling mode */
2180 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002181 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002182 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002183 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002184 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002185 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002186 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002187 }
2188
2189 return work_done;
2190}
2191
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002192/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002193 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002194 * @napi: napi struct with our devices info in it
2195 * @budget: amount of work driver is allowed to do this pass, in packets
2196 *
2197 * This function will clean more than one rx queue associated with a
2198 * q_vector.
2199 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002200static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002201{
2202 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002203 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002204 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002205 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002206 int work_done = 0, i;
2207 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002208 bool tx_clean_complete = true;
2209
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002210#ifdef CONFIG_IXGBE_DCA
2211 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2212 ixgbe_update_dca(q_vector);
2213#endif
2214
Alexander Duyck91281fd2009-06-04 16:00:27 +00002215 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2216 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002217 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002218 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2219 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002220 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002221 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002222
2223 /* attempt to distribute budget to each queue fairly, but don't allow
2224 * the budget to go below 1 because we'll exit polling */
2225 budget /= (q_vector->rxr_count ?: 1);
2226 budget = max(budget, 1);
2227 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2228 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002229 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002230 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002231 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002232 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002233 }
2234
2235 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002236 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002237 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002238 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002239 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002240 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002241 ixgbe_set_itr_msix(q_vector);
2242 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002243 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002244 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002245 return 0;
2246 }
2247
2248 return work_done;
2249}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002250
2251/**
2252 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2253 * @napi: napi struct with our devices info in it
2254 * @budget: amount of work driver is allowed to do this pass, in packets
2255 *
2256 * This function is optimized for cleaning one queue only on a single
2257 * q_vector!!!
2258 **/
2259static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2260{
2261 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002262 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002263 struct ixgbe_adapter *adapter = q_vector->adapter;
2264 struct ixgbe_ring *tx_ring = NULL;
2265 int work_done = 0;
2266 long r_idx;
2267
Alexander Duyck91281fd2009-06-04 16:00:27 +00002268#ifdef CONFIG_IXGBE_DCA
2269 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002270 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002271#endif
2272
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002273 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2274 tx_ring = adapter->tx_ring[r_idx];
2275
Alexander Duyck91281fd2009-06-04 16:00:27 +00002276 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2277 work_done = budget;
2278
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002279 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002280 if (work_done < budget) {
2281 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002282 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002283 ixgbe_set_itr_msix(q_vector);
2284 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002285 ixgbe_irq_enable_queues(adapter,
2286 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002287 }
2288
2289 return work_done;
2290}
2291
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002292static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002293 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002294{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002295 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002296 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002297
2298 set_bit(r_idx, q_vector->rxr_idx);
2299 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002300 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301}
Auke Kok9a799d72007-09-15 14:07:45 -07002302
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002303static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002304 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002306 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002307 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002308
2309 set_bit(t_idx, q_vector->txr_idx);
2310 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002311 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312}
Auke Kok9a799d72007-09-15 14:07:45 -07002313
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314/**
2315 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2316 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002317 *
2318 * This function maps descriptor rings to the queue-specific vectors
2319 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2320 * one vector per ring/queue, but on a constrained vector budget, we
2321 * group the rings as "efficiently" as possible. You would add new
2322 * mapping configurations in here.
2323 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002324static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002326 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 int v_start = 0;
2328 int rxr_idx = 0, txr_idx = 0;
2329 int rxr_remaining = adapter->num_rx_queues;
2330 int txr_remaining = adapter->num_tx_queues;
2331 int i, j;
2332 int rqpv, tqpv;
2333 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002334
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335 /* No mapping required if MSI-X is disabled. */
2336 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002337 goto out;
2338
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002339 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2340
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341 /*
2342 * The ideal configuration...
2343 * We have enough vectors to map one per queue.
2344 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002345 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2347 map_vector_to_rxq(adapter, v_start, rxr_idx);
2348
2349 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2350 map_vector_to_txq(adapter, v_start, txr_idx);
2351
2352 goto out;
2353 }
2354
2355 /*
2356 * If we don't have enough vectors for a 1-to-1
2357 * mapping, we'll have to group them so there are
2358 * multiple queues per vector.
2359 */
2360 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002361 for (i = v_start; i < q_vectors; i++) {
2362 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002363 for (j = 0; j < rqpv; j++) {
2364 map_vector_to_rxq(adapter, i, rxr_idx);
2365 rxr_idx++;
2366 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002367 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002368 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 for (j = 0; j < tqpv; j++) {
2370 map_vector_to_txq(adapter, i, txr_idx);
2371 txr_idx++;
2372 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002373 }
Auke Kok9a799d72007-09-15 14:07:45 -07002374 }
Auke Kok9a799d72007-09-15 14:07:45 -07002375out:
Auke Kok9a799d72007-09-15 14:07:45 -07002376 return err;
2377}
2378
2379/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002380 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2381 * @adapter: board private structure
2382 *
2383 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2384 * interrupts from the kernel.
2385 **/
2386static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2387{
2388 struct net_device *netdev = adapter->netdev;
2389 irqreturn_t (*handler)(int, void *);
2390 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002391 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002392
2393 /* Decrement for Other and TCP Timer vectors */
2394 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2395
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002396 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002397 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002398 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002399
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002400#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2401 ? &ixgbe_msix_clean_many : \
2402 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2403 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2404 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002405 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002406 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2407 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002408
Joe Perchese8e9f692010-09-07 21:34:53 +00002409 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002410 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2411 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002412 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002413 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2414 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002415 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002416 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2417 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002418 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002419 } else {
2420 /* skip this unused q_vector */
2421 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002422 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002423 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002424 handler, 0, q_vector->name,
2425 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002426 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002427 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002428 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002429 goto free_queue_irqs;
2430 }
2431 }
2432
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002433 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002434 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002435 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002436 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002437 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002438 goto free_queue_irqs;
2439 }
2440
2441 return 0;
2442
2443free_queue_irqs:
2444 for (i = vector - 1; i >= 0; i--)
2445 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002446 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002447 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2448 pci_disable_msix(adapter->pdev);
2449 kfree(adapter->msix_entries);
2450 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451 return err;
2452}
2453
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002454static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2455{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002456 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002457 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2458 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002459 u32 new_itr = q_vector->eitr;
2460 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002461
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002462 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002463 q_vector->tx_itr,
2464 tx_ring->total_packets,
2465 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002466 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002467 q_vector->rx_itr,
2468 rx_ring->total_packets,
2469 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002470
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002471 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002472
2473 switch (current_itr) {
2474 /* counts and packets in update_itr are dependent on these numbers */
2475 case lowest_latency:
2476 new_itr = 100000;
2477 break;
2478 case low_latency:
2479 new_itr = 20000; /* aka hwitr = ~200 */
2480 break;
2481 case bulk_latency:
2482 new_itr = 8000;
2483 break;
2484 default:
2485 break;
2486 }
2487
2488 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002489 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002490 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002491
Alexander Duyck125601b2010-11-16 19:27:08 -08002492 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002493 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002494
2495 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002496 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002497}
2498
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002499/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002500 * ixgbe_irq_enable - Enable default interrupt generation settings
2501 * @adapter: board private structure
2502 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002503static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2504 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002505{
2506 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002507
2508 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002509 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2510 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002511 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2512 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002513 switch (adapter->hw.mac.type) {
2514 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002515 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002516 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002517 mask |= IXGBE_EIMS_GPI_SDP1;
2518 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002519 if (adapter->num_vfs)
2520 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002521 break;
2522 default:
2523 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002524 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002525 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2526 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2527 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002528
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002529 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002530 if (queues)
2531 ixgbe_irq_enable_queues(adapter, ~0);
2532 if (flush)
2533 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002534
2535 if (adapter->num_vfs > 32) {
2536 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2537 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2538 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002539}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002540
2541/**
2542 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002543 * @irq: interrupt number
2544 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002545 **/
2546static irqreturn_t ixgbe_intr(int irq, void *data)
2547{
2548 struct net_device *netdev = data;
2549 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2550 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002551 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002552 u32 eicr;
2553
Don Skidmore54037502009-02-21 15:42:56 -08002554 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002555 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002556 * before the read of EICR.
2557 */
2558 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002560 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2561 * therefore no explict interrupt disable is necessary */
2562 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002563 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002564 /*
2565 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002566 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002567 * have disabled interrupts due to EIAM
2568 * finish the workaround of silicon errata on 82598. Unmask
2569 * the interrupt that we masked before the EICR read.
2570 */
2571 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2572 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002573 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002574 }
Auke Kok9a799d72007-09-15 14:07:45 -07002575
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002576 if (eicr & IXGBE_EICR_LSC)
2577 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002578
Alexander Duyckbd508172010-11-16 19:27:03 -08002579 switch (hw->mac.type) {
2580 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002581 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002582 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2583 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002584 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2585 adapter->interrupt_event = eicr;
2586 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2587 ixgbe_service_event_schedule(adapter);
2588 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002589 }
2590 break;
2591 default:
2592 break;
2593 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002594
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002595 ixgbe_check_fan_failure(adapter, eicr);
2596
Alexander Duyck7a921c92009-05-06 10:43:28 +00002597 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002598 adapter->tx_ring[0]->total_packets = 0;
2599 adapter->tx_ring[0]->total_bytes = 0;
2600 adapter->rx_ring[0]->total_packets = 0;
2601 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002602 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002603 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002604 }
2605
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002606 /*
2607 * re-enable link(maybe) and non-queue interrupts, no flush.
2608 * ixgbe_poll will re-enable the queue interrupts
2609 */
2610
2611 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2612 ixgbe_irq_enable(adapter, false, false);
2613
Auke Kok9a799d72007-09-15 14:07:45 -07002614 return IRQ_HANDLED;
2615}
2616
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002617static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2618{
2619 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2620
2621 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002622 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002623 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2624 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2625 q_vector->rxr_count = 0;
2626 q_vector->txr_count = 0;
2627 }
2628}
2629
Auke Kok9a799d72007-09-15 14:07:45 -07002630/**
2631 * ixgbe_request_irq - initialize interrupts
2632 * @adapter: board private structure
2633 *
2634 * Attempts to configure interrupts using the best available
2635 * capabilities of the hardware and kernel.
2636 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002637static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002638{
2639 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002640 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002641
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002642 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2643 err = ixgbe_request_msix_irqs(adapter);
2644 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002645 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Joe Perchese8e9f692010-09-07 21:34:53 +00002646 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002647 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002648 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Joe Perchese8e9f692010-09-07 21:34:53 +00002649 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002650 }
2651
Auke Kok9a799d72007-09-15 14:07:45 -07002652 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002653 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002654
Auke Kok9a799d72007-09-15 14:07:45 -07002655 return err;
2656}
2657
2658static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2659{
2660 struct net_device *netdev = adapter->netdev;
2661
2662 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002663 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002664
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665 q_vectors = adapter->num_msix_vectors;
2666
2667 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002668 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002669
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002670 i--;
2671 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002672 /* free only the irqs that were actually requested */
2673 if (!adapter->q_vector[i]->rxr_count &&
2674 !adapter->q_vector[i]->txr_count)
2675 continue;
2676
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002677 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002678 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002679 }
2680
2681 ixgbe_reset_q_vectors(adapter);
2682 } else {
2683 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002684 }
2685}
2686
2687/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002688 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2689 * @adapter: board private structure
2690 **/
2691static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2692{
Alexander Duyckbd508172010-11-16 19:27:03 -08002693 switch (adapter->hw.mac.type) {
2694 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002695 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002696 break;
2697 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002698 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002699 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2700 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002701 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002702 if (adapter->num_vfs > 32)
2703 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002704 break;
2705 default:
2706 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002707 }
2708 IXGBE_WRITE_FLUSH(&adapter->hw);
2709 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2710 int i;
2711 for (i = 0; i < adapter->num_msix_vectors; i++)
2712 synchronize_irq(adapter->msix_entries[i].vector);
2713 } else {
2714 synchronize_irq(adapter->pdev->irq);
2715 }
2716}
2717
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002718/**
Auke Kok9a799d72007-09-15 14:07:45 -07002719 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2720 *
2721 **/
2722static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2723{
Auke Kok9a799d72007-09-15 14:07:45 -07002724 struct ixgbe_hw *hw = &adapter->hw;
2725
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002726 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002727 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002728
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002729 ixgbe_set_ivar(adapter, 0, 0, 0);
2730 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002731
2732 map_vector_to_rxq(adapter, 0, 0);
2733 map_vector_to_txq(adapter, 0, 0);
2734
Emil Tantilov396e7992010-07-01 20:05:12 +00002735 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002736}
2737
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002738/**
2739 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2740 * @adapter: board private structure
2741 * @ring: structure containing ring specific data
2742 *
2743 * Configure the Tx descriptor ring after a reset.
2744 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002745void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2746 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002747{
2748 struct ixgbe_hw *hw = &adapter->hw;
2749 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002750 int wait_loop = 10;
2751 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002752 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002753
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002754 /* disable queue to avoid issues while updating state */
2755 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2756 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2757 txdctl & ~IXGBE_TXDCTL_ENABLE);
2758 IXGBE_WRITE_FLUSH(hw);
2759
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002760 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002761 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002762 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2763 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2764 ring->count * sizeof(union ixgbe_adv_tx_desc));
2765 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2766 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002767 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002768
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002769 /* configure fetching thresholds */
2770 if (adapter->rx_itr_setting == 0) {
2771 /* cannot set wthresh when itr==0 */
2772 txdctl &= ~0x007F0000;
2773 } else {
2774 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2775 txdctl |= (8 << 16);
2776 }
2777 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2778 /* PThresh workaround for Tx hang with DFP enabled. */
2779 txdctl |= 32;
2780 }
2781
2782 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002783 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2784 adapter->atr_sample_rate) {
2785 ring->atr_sample_rate = adapter->atr_sample_rate;
2786 ring->atr_count = 0;
2787 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2788 } else {
2789 ring->atr_sample_rate = 0;
2790 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002791
John Fastabendc84d3242010-11-16 19:27:12 -08002792 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2793
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002794 /* enable queue */
2795 txdctl |= IXGBE_TXDCTL_ENABLE;
2796 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2797
2798 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2799 if (hw->mac.type == ixgbe_mac_82598EB &&
2800 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2801 return;
2802
2803 /* poll to verify queue is enabled */
2804 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002805 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002806 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2807 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2808 if (!wait_loop)
2809 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002810}
2811
Alexander Duyck120ff942010-08-19 13:34:50 +00002812static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2813{
2814 struct ixgbe_hw *hw = &adapter->hw;
2815 u32 rttdcs;
2816 u32 mask;
2817
2818 if (hw->mac.type == ixgbe_mac_82598EB)
2819 return;
2820
2821 /* disable the arbiter while setting MTQC */
2822 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2823 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2824 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2825
2826 /* set transmit pool layout */
2827 mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
2828 switch (adapter->flags & mask) {
2829
2830 case (IXGBE_FLAG_SRIOV_ENABLED):
2831 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2832 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2833 break;
2834
2835 case (IXGBE_FLAG_DCB_ENABLED):
2836 /* We enable 8 traffic classes, DCB only */
2837 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2838 (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
2839 break;
2840
2841 default:
2842 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2843 break;
2844 }
2845
2846 /* re-enable the arbiter */
2847 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2848 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2849}
2850
Auke Kok9a799d72007-09-15 14:07:45 -07002851/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002852 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002853 * @adapter: board private structure
2854 *
2855 * Configure the Tx unit of the MAC after a reset.
2856 **/
2857static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2858{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002859 struct ixgbe_hw *hw = &adapter->hw;
2860 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002861 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002862
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002863 ixgbe_setup_mtqc(adapter);
2864
2865 if (hw->mac.type != ixgbe_mac_82598EB) {
2866 /* DMATXCTL.EN must be before Tx queues are enabled */
2867 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2868 dmatxctl |= IXGBE_DMATXCTL_TE;
2869 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2870 }
2871
Auke Kok9a799d72007-09-15 14:07:45 -07002872 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002873 for (i = 0; i < adapter->num_tx_queues; i++)
2874 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002875}
2876
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002877#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002878
Yi Zoua6616b42009-08-06 13:05:23 +00002879static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002880 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002881{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002882 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002883 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002884
Alexander Duyckbd508172010-11-16 19:27:03 -08002885 switch (adapter->hw.mac.type) {
2886 case ixgbe_mac_82598EB: {
2887 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2888 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002889 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002890 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002891 break;
2892 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002893 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002894 default:
2895 break;
2896 }
2897
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002898 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002899
2900 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2901 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002902 if (adapter->num_vfs)
2903 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002904
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002905 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2906 IXGBE_SRRCTL_BSIZEHDR_MASK;
2907
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002908 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002909#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2910 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2911#else
2912 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2913#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002914 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002915 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002916 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2917 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002918 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002919 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002920
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002921 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002922}
2923
Alexander Duyck05abb122010-08-19 13:35:41 +00002924static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002925{
Alexander Duyck05abb122010-08-19 13:35:41 +00002926 struct ixgbe_hw *hw = &adapter->hw;
2927 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002928 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2929 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002930 u32 mrqc = 0, reta = 0;
2931 u32 rxcsum;
2932 int i, j;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002933 int mask;
2934
Alexander Duyck05abb122010-08-19 13:35:41 +00002935 /* Fill out hash function seeds */
2936 for (i = 0; i < 10; i++)
2937 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002938
Alexander Duyck05abb122010-08-19 13:35:41 +00002939 /* Fill out redirection table */
2940 for (i = 0, j = 0; i < 128; i++, j++) {
2941 if (j == adapter->ring_feature[RING_F_RSS].indices)
2942 j = 0;
2943 /* reta = 4-byte sliding window of
2944 * 0x00..(indices-1)(indices-1)00..etc. */
2945 reta = (reta << 8) | (j * 0x11);
2946 if ((i & 3) == 3)
2947 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2948 }
2949
2950 /* Disable indicating checksum in descriptor, enables RSS hash */
2951 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2952 rxcsum |= IXGBE_RXCSUM_PCSD;
2953 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2954
2955 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2956 mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
2957 else
2958 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002959#ifdef CONFIG_IXGBE_DCB
Alexander Duyck05abb122010-08-19 13:35:41 +00002960 | IXGBE_FLAG_DCB_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002961#endif
Alexander Duyck05abb122010-08-19 13:35:41 +00002962 | IXGBE_FLAG_SRIOV_ENABLED
2963 );
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002964
2965 switch (mask) {
John Fastabend8187cd42011-02-23 05:58:08 +00002966#ifdef CONFIG_IXGBE_DCB
2967 case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED):
2968 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2969 break;
2970 case (IXGBE_FLAG_DCB_ENABLED):
2971 mrqc = IXGBE_MRQC_RT8TCEN;
2972 break;
2973#endif /* CONFIG_IXGBE_DCB */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002974 case (IXGBE_FLAG_RSS_ENABLED):
2975 mrqc = IXGBE_MRQC_RSSEN;
2976 break;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002977 case (IXGBE_FLAG_SRIOV_ENABLED):
2978 mrqc = IXGBE_MRQC_VMDQEN;
2979 break;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002980 default:
2981 break;
2982 }
2983
Alexander Duyck05abb122010-08-19 13:35:41 +00002984 /* Perform hash on these packet types */
2985 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2986 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2987 | IXGBE_MRQC_RSS_FIELD_IPV6
2988 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2989
2990 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002991}
2992
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002993/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002994 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2995 * @adapter: address of board private structure
2996 * @ring: structure containing ring specific data
2997 **/
2998void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2999 struct ixgbe_ring *ring)
3000{
3001 struct ixgbe_hw *hw = &adapter->hw;
3002 u32 rscctrl;
3003 u8 reg_idx = ring->reg_idx;
3004
3005 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3006 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
3007 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3008}
3009
3010/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003011 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3012 * @adapter: address of board private structure
3013 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003014 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08003015void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003016 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003017{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003018 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003019 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08003020 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003021 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003022
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003023 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003024 return;
3025
3026 rx_buf_len = ring->rx_buf_len;
3027 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003028 rscctrl |= IXGBE_RSCCTL_RSCEN;
3029 /*
3030 * we must limit the number of descriptors so that the
3031 * total size of max desc * buf_len is not greater
3032 * than 65535
3033 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003034 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003035#if (MAX_SKB_FRAGS > 16)
3036 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3037#elif (MAX_SKB_FRAGS > 8)
3038 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3039#elif (MAX_SKB_FRAGS > 4)
3040 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3041#else
3042 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3043#endif
3044 } else {
3045 if (rx_buf_len < IXGBE_RXBUFFER_4096)
3046 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3047 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
3048 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3049 else
3050 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3051 }
Alexander Duyck73670962010-08-19 13:38:34 +00003052 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003053}
3054
Alexander Duyck9e10e042010-08-19 13:40:06 +00003055/**
3056 * ixgbe_set_uta - Set unicast filter table address
3057 * @adapter: board private structure
3058 *
3059 * The unicast table address is a register array of 32-bit registers.
3060 * The table is meant to be used in a way similar to how the MTA is used
3061 * however due to certain limitations in the hardware it is necessary to
3062 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3063 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3064 **/
3065static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3066{
3067 struct ixgbe_hw *hw = &adapter->hw;
3068 int i;
3069
3070 /* The UTA table only exists on 82599 hardware and newer */
3071 if (hw->mac.type < ixgbe_mac_82599EB)
3072 return;
3073
3074 /* we only need to do this if VMDq is enabled */
3075 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3076 return;
3077
3078 for (i = 0; i < 128; i++)
3079 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3080}
3081
3082#define IXGBE_MAX_RX_DESC_POLL 10
3083static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3084 struct ixgbe_ring *ring)
3085{
3086 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003087 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3088 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003089 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003090
3091 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3092 if (hw->mac.type == ixgbe_mac_82598EB &&
3093 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3094 return;
3095
3096 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003097 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003098 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3099 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3100
3101 if (!wait_loop) {
3102 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3103 "the polling period\n", reg_idx);
3104 }
3105}
3106
Yi Zou2d39d572011-01-06 14:29:56 +00003107void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3108 struct ixgbe_ring *ring)
3109{
3110 struct ixgbe_hw *hw = &adapter->hw;
3111 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3112 u32 rxdctl;
3113 u8 reg_idx = ring->reg_idx;
3114
3115 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3116 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3117
3118 /* write value back with RXDCTL.ENABLE bit cleared */
3119 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3120
3121 if (hw->mac.type == ixgbe_mac_82598EB &&
3122 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3123 return;
3124
3125 /* the hardware may take up to 100us to really disable the rx queue */
3126 do {
3127 udelay(10);
3128 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3129 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3130
3131 if (!wait_loop) {
3132 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3133 "the polling period\n", reg_idx);
3134 }
3135}
3136
Alexander Duyck84418e32010-08-19 13:40:54 +00003137void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3138 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003139{
3140 struct ixgbe_hw *hw = &adapter->hw;
3141 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003142 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003143 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003144
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145 /* disable queue to avoid issues while updating state */
3146 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003147 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003148
Alexander Duyckacd37172010-08-19 13:36:05 +00003149 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3150 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3151 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3152 ring->count * sizeof(union ixgbe_adv_rx_desc));
3153 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3154 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003155 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003156
3157 ixgbe_configure_srrctl(adapter, ring);
3158 ixgbe_configure_rscctl(adapter, ring);
3159
Greg Rosee9f98072011-01-26 01:06:07 +00003160 /* If operating in IOV mode set RLPML for X540 */
3161 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3162 hw->mac.type == ixgbe_mac_X540) {
3163 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3164 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3165 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3166 }
3167
Alexander Duyck9e10e042010-08-19 13:40:06 +00003168 if (hw->mac.type == ixgbe_mac_82598EB) {
3169 /*
3170 * enable cache line friendly hardware writes:
3171 * PTHRESH=32 descriptors (half the internal cache),
3172 * this also removes ugly rx_no_buffer_count increment
3173 * HTHRESH=4 descriptors (to minimize latency on fetch)
3174 * WTHRESH=8 burst writeback up to two cache lines
3175 */
3176 rxdctl &= ~0x3FFFFF;
3177 rxdctl |= 0x080420;
3178 }
3179
3180 /* enable receive descriptor ring */
3181 rxdctl |= IXGBE_RXDCTL_ENABLE;
3182 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3183
3184 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08003185 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003186}
3187
Alexander Duyck48654522010-08-19 13:36:27 +00003188static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3189{
3190 struct ixgbe_hw *hw = &adapter->hw;
3191 int p;
3192
3193 /* PSRTYPE must be initialized in non 82598 adapters */
3194 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003195 IXGBE_PSRTYPE_UDPHDR |
3196 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003197 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003198 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003199
3200 if (hw->mac.type == ixgbe_mac_82598EB)
3201 return;
3202
3203 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3204 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3205
3206 for (p = 0; p < adapter->num_rx_pools; p++)
3207 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3208 psrtype);
3209}
3210
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003211static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3212{
3213 struct ixgbe_hw *hw = &adapter->hw;
3214 u32 gcr_ext;
3215 u32 vt_reg_bits;
3216 u32 reg_offset, vf_shift;
3217 u32 vmdctl;
3218
3219 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3220 return;
3221
3222 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3223 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3224 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3225 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3226
3227 vf_shift = adapter->num_vfs % 32;
3228 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3229
3230 /* Enable only the PF's pool for Tx/Rx */
3231 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3232 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3233 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3234 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3235 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3236
3237 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3238 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3239
3240 /*
3241 * Set up VF register offsets for selected VT Mode,
3242 * i.e. 32 or 64 VFs for SR-IOV
3243 */
3244 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3245 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3246 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3247 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3248
3249 /* enable Tx loopback for VF/PF communication */
3250 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003251 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003252 hw->mac.ops.set_mac_anti_spoofing(hw,
3253 (adapter->antispoofing_enabled =
3254 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003255 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003256}
3257
Alexander Duyck477de6e2010-08-19 13:38:11 +00003258static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003259{
Auke Kok9a799d72007-09-15 14:07:45 -07003260 struct ixgbe_hw *hw = &adapter->hw;
3261 struct net_device *netdev = adapter->netdev;
3262 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003263 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003264 struct ixgbe_ring *rx_ring;
3265 int i;
3266 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003267
Auke Kok9a799d72007-09-15 14:07:45 -07003268 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003269 /* On by default */
3270 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3271
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003272 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003273 if (adapter->num_vfs)
3274 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3275
3276 /* Disable packet split due to 82599 erratum #45 */
3277 if (hw->mac.type == ixgbe_mac_82599EB)
3278 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003279
3280 /* Set the RX buffer length according to the mode */
3281 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003282 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003283 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003284 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003285 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003286 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003287 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003288 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3289 }
3290
3291#ifdef IXGBE_FCOE
3292 /* adjust max frame to be able to do baby jumbo for FCoE */
3293 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3294 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3295 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3296
3297#endif /* IXGBE_FCOE */
3298 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3299 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3300 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3301 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3302
3303 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003304 }
3305
Auke Kok9a799d72007-09-15 14:07:45 -07003306 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003307 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3308 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003309 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3310
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003311 /*
3312 * Setup the HW Rx Head and Tail Descriptor Pointers and
3313 * the Base and Length of the Rx Descriptor Ring
3314 */
Auke Kok9a799d72007-09-15 14:07:45 -07003315 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003316 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003317 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003318
Yi Zou6e455b892009-08-06 13:05:44 +00003319 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003320 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003321 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003322 clear_ring_ps_enabled(rx_ring);
3323
3324 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3325 set_ring_rsc_enabled(rx_ring);
3326 else
3327 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003328
Yi Zou63f39bd2009-05-17 12:34:35 +00003329#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003330 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003331 struct ixgbe_ring_feature *f;
3332 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003333 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003334 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003335 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3336 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003337 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003338 } else if (!ring_is_rsc_enabled(rx_ring) &&
3339 !ring_is_ps_enabled(rx_ring)) {
3340 rx_ring->rx_buf_len =
3341 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003342 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003343 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003344#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003345 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003346}
3347
Alexander Duyck73670962010-08-19 13:38:34 +00003348static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3349{
3350 struct ixgbe_hw *hw = &adapter->hw;
3351 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3352
3353 switch (hw->mac.type) {
3354 case ixgbe_mac_82598EB:
3355 /*
3356 * For VMDq support of different descriptor types or
3357 * buffer sizes through the use of multiple SRRCTL
3358 * registers, RDRXCTL.MVMEN must be set to 1
3359 *
3360 * also, the manual doesn't mention it clearly but DCA hints
3361 * will only use queue 0's tags unless this bit is set. Side
3362 * effects of setting this bit are only that SRRCTL must be
3363 * fully programmed [0..15]
3364 */
3365 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3366 break;
3367 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003368 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003369 /* Disable RSC for ACK packets */
3370 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3371 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3372 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3373 /* hardware requires some bits to be set by default */
3374 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3375 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3376 break;
3377 default:
3378 /* We should do nothing since we don't know this hardware */
3379 return;
3380 }
3381
3382 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3383}
3384
Alexander Duyck477de6e2010-08-19 13:38:11 +00003385/**
3386 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3387 * @adapter: board private structure
3388 *
3389 * Configure the Rx unit of the MAC after a reset.
3390 **/
3391static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3392{
3393 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003394 int i;
3395 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003396
3397 /* disable receives while setting up the descriptors */
3398 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3399 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3400
3401 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003402 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003403
Alexander Duyck9e10e042010-08-19 13:40:06 +00003404 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003405 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003406
Alexander Duyck9e10e042010-08-19 13:40:06 +00003407 ixgbe_set_uta(adapter);
3408
Alexander Duyck477de6e2010-08-19 13:38:11 +00003409 /* set_rx_buffer_len must be called before ring initialization */
3410 ixgbe_set_rx_buffer_len(adapter);
3411
3412 /*
3413 * Setup the HW Rx Head and Tail Descriptor Pointers and
3414 * the Base and Length of the Rx Descriptor Ring
3415 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003416 for (i = 0; i < adapter->num_rx_queues; i++)
3417 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003418
Alexander Duyck9e10e042010-08-19 13:40:06 +00003419 /* disable drop enable for 82598 parts */
3420 if (hw->mac.type == ixgbe_mac_82598EB)
3421 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3422
3423 /* enable all receives */
3424 rxctrl |= IXGBE_RXCTRL_RXEN;
3425 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003426}
3427
Auke Kok9a799d72007-09-15 14:07:45 -07003428static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3429{
3430 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003431 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003432 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003433
3434 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003435 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003436 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003437}
3438
3439static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3440{
3441 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003442 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003443 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003444
Auke Kok9a799d72007-09-15 14:07:45 -07003445 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003446 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003447 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003448}
3449
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003450/**
3451 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3452 * @adapter: driver data
3453 */
3454static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3455{
3456 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003457 u32 vlnctrl;
3458
3459 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3460 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3461 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3462}
3463
3464/**
3465 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3466 * @adapter: driver data
3467 */
3468static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3469{
3470 struct ixgbe_hw *hw = &adapter->hw;
3471 u32 vlnctrl;
3472
3473 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3474 vlnctrl |= IXGBE_VLNCTRL_VFE;
3475 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3476 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3477}
3478
3479/**
3480 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3481 * @adapter: driver data
3482 */
3483static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3484{
3485 struct ixgbe_hw *hw = &adapter->hw;
3486 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003487 int i, j;
3488
3489 switch (hw->mac.type) {
3490 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003491 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3492 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003493 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3494 break;
3495 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003496 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003497 for (i = 0; i < adapter->num_rx_queues; i++) {
3498 j = adapter->rx_ring[i]->reg_idx;
3499 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3500 vlnctrl &= ~IXGBE_RXDCTL_VME;
3501 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3502 }
3503 break;
3504 default:
3505 break;
3506 }
3507}
3508
3509/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003510 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003511 * @adapter: driver data
3512 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003513static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003514{
3515 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003516 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003517 int i, j;
3518
3519 switch (hw->mac.type) {
3520 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003521 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3522 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003523 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3524 break;
3525 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003526 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003527 for (i = 0; i < adapter->num_rx_queues; i++) {
3528 j = adapter->rx_ring[i]->reg_idx;
3529 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3530 vlnctrl |= IXGBE_RXDCTL_VME;
3531 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3532 }
3533 break;
3534 default:
3535 break;
3536 }
3537}
3538
Auke Kok9a799d72007-09-15 14:07:45 -07003539static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3540{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003541 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003542
Jesse Grossf62bbb52010-10-20 13:56:10 +00003543 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3544
3545 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3546 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003547}
3548
3549/**
Alexander Duyck28500622010-06-15 09:25:48 +00003550 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3551 * @netdev: network interface device structure
3552 *
3553 * Writes unicast address list to the RAR table.
3554 * Returns: -ENOMEM on failure/insufficient address space
3555 * 0 on no addresses written
3556 * X on writing X addresses to the RAR table
3557 **/
3558static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3559{
3560 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3561 struct ixgbe_hw *hw = &adapter->hw;
3562 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003563 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003564 int count = 0;
3565
3566 /* return ENOMEM indicating insufficient memory for addresses */
3567 if (netdev_uc_count(netdev) > rar_entries)
3568 return -ENOMEM;
3569
3570 if (!netdev_uc_empty(netdev) && rar_entries) {
3571 struct netdev_hw_addr *ha;
3572 /* return error if we do not support writing to RAR table */
3573 if (!hw->mac.ops.set_rar)
3574 return -ENOMEM;
3575
3576 netdev_for_each_uc_addr(ha, netdev) {
3577 if (!rar_entries)
3578 break;
3579 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3580 vfn, IXGBE_RAH_AV);
3581 count++;
3582 }
3583 }
3584 /* write the addresses in reverse order to avoid write combining */
3585 for (; rar_entries > 0 ; rar_entries--)
3586 hw->mac.ops.clear_rar(hw, rar_entries);
3587
3588 return count;
3589}
3590
3591/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003592 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003593 * @netdev: network interface device structure
3594 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003595 * The set_rx_method entry point is called whenever the unicast/multicast
3596 * address list or the network interface flags are updated. This routine is
3597 * responsible for configuring the hardware for proper unicast, multicast and
3598 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003599 **/
Greg Rose7f870472010-01-09 02:25:29 +00003600void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003601{
3602 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3603 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003604 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3605 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003606
3607 /* Check for Promiscuous and All Multicast modes */
3608
3609 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3610
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003611 /* set all bits that we expect to always be set */
3612 fctrl |= IXGBE_FCTRL_BAM;
3613 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3614 fctrl |= IXGBE_FCTRL_PMCF;
3615
Alexander Duyck28500622010-06-15 09:25:48 +00003616 /* clear the bits we are changing the status of */
3617 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3618
Auke Kok9a799d72007-09-15 14:07:45 -07003619 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003620 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003621 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003622 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003623 /* don't hardware filter vlans in promisc mode */
3624 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003625 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003626 if (netdev->flags & IFF_ALLMULTI) {
3627 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003628 vmolr |= IXGBE_VMOLR_MPE;
3629 } else {
3630 /*
3631 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003632 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003633 * that we can at least receive multicast traffic
3634 */
3635 hw->mac.ops.update_mc_addr_list(hw, netdev);
3636 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003637 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003638 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003639 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003640 /*
3641 * Write addresses to available RAR registers, if there is not
3642 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003643 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003644 */
3645 count = ixgbe_write_uc_addr_list(netdev);
3646 if (count < 0) {
3647 fctrl |= IXGBE_FCTRL_UPE;
3648 vmolr |= IXGBE_VMOLR_ROPE;
3649 }
3650 }
3651
3652 if (adapter->num_vfs) {
3653 ixgbe_restore_vf_multicasts(adapter);
3654 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3655 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3656 IXGBE_VMOLR_ROPE);
3657 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003658 }
3659
3660 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003661
3662 if (netdev->features & NETIF_F_HW_VLAN_RX)
3663 ixgbe_vlan_strip_enable(adapter);
3664 else
3665 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003666}
3667
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003668static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3669{
3670 int q_idx;
3671 struct ixgbe_q_vector *q_vector;
3672 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3673
3674 /* legacy and MSI only use one vector */
3675 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3676 q_vectors = 1;
3677
3678 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003679 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003680 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003681 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003682 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3683 if (!q_vector->rxr_count || !q_vector->txr_count) {
3684 if (q_vector->txr_count == 1)
3685 napi->poll = &ixgbe_clean_txonly;
3686 else if (q_vector->rxr_count == 1)
3687 napi->poll = &ixgbe_clean_rxonly;
3688 }
3689 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003690
3691 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003692 }
3693}
3694
3695static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3696{
3697 int q_idx;
3698 struct ixgbe_q_vector *q_vector;
3699 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3700
3701 /* legacy and MSI only use one vector */
3702 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3703 q_vectors = 1;
3704
3705 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003706 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003707 napi_disable(&q_vector->napi);
3708 }
3709}
3710
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003711#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003712/*
3713 * ixgbe_configure_dcb - Configure DCB hardware
3714 * @adapter: ixgbe adapter struct
3715 *
3716 * This is called by the driver on open to configure the DCB hardware.
3717 * This is also called by the gennetlink interface when reconfiguring
3718 * the DCB state.
3719 */
3720static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3721{
3722 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003723 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003724
Alexander Duyck67ebd792010-08-19 13:34:04 +00003725 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3726 if (hw->mac.type == ixgbe_mac_82598EB)
3727 netif_set_gso_max_size(adapter->netdev, 65536);
3728 return;
3729 }
3730
3731 if (hw->mac.type == ixgbe_mac_82598EB)
3732 netif_set_gso_max_size(adapter->netdev, 32768);
3733
Alexander Duyck2f90b862008-11-20 20:52:10 -08003734
Alexander Duyck2f90b862008-11-20 20:52:10 -08003735 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003736 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003737
Alexander Duyck2f90b862008-11-20 20:52:10 -08003738 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003739
3740 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003741 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3742#ifdef CONFIG_FCOE
3743 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3744 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3745#endif
3746 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3747 DCB_TX_CONFIG);
3748 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3749 DCB_RX_CONFIG);
3750 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3751 } else {
3752 struct net_device *dev = adapter->netdev;
3753
3754 if (adapter->ixgbe_ieee_ets)
3755 dev->dcbnl_ops->ieee_setets(dev,
3756 adapter->ixgbe_ieee_ets);
3757 if (adapter->ixgbe_ieee_pfc)
3758 dev->dcbnl_ops->ieee_setpfc(dev,
3759 adapter->ixgbe_ieee_pfc);
3760 }
John Fastabend8187cd42011-02-23 05:58:08 +00003761
3762 /* Enable RSS Hash per TC */
3763 if (hw->mac.type != ixgbe_mac_82598EB) {
3764 int i;
3765 u32 reg = 0;
3766
3767 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3768 u8 msb = 0;
3769 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3770
3771 while (cnt >>= 1)
3772 msb++;
3773
3774 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3775 }
3776 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3777 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003778}
3779
3780#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003781static void ixgbe_configure(struct ixgbe_adapter *adapter)
3782{
3783 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003784 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003785 int i;
3786
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003787#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003788 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003789#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003790
Jesse Grossf62bbb52010-10-20 13:56:10 +00003791 ixgbe_set_rx_mode(netdev);
3792 ixgbe_restore_vlan(adapter);
3793
Yi Zoueacd73f2009-05-13 13:11:06 +00003794#ifdef IXGBE_FCOE
3795 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3796 ixgbe_configure_fcoe(adapter);
3797
3798#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003799 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3800 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003801 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003802 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003803 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3804 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3805 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3806 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003807 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003808
Auke Kok9a799d72007-09-15 14:07:45 -07003809 ixgbe_configure_tx(adapter);
3810 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003811}
3812
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003813static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3814{
3815 switch (hw->phy.type) {
3816 case ixgbe_phy_sfp_avago:
3817 case ixgbe_phy_sfp_ftl:
3818 case ixgbe_phy_sfp_intel:
3819 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003820 case ixgbe_phy_sfp_passive_tyco:
3821 case ixgbe_phy_sfp_passive_unknown:
3822 case ixgbe_phy_sfp_active_unknown:
3823 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003824 return true;
3825 default:
3826 return false;
3827 }
3828}
3829
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003830/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003831 * ixgbe_sfp_link_config - set up SFP+ link
3832 * @adapter: pointer to private adapter struct
3833 **/
3834static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3835{
Alexander Duyck70864002011-04-27 09:13:56 +00003836 /*
3837 * We are assuming the worst case scenerio here, and that
3838 * is that an SFP was inserted/removed after the reset
3839 * but before SFP detection was enabled. As such the best
3840 * solution is to just start searching as soon as we start
3841 */
3842 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3843 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003844
Alexander Duyck70864002011-04-27 09:13:56 +00003845 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003846}
3847
3848/**
3849 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003850 * @hw: pointer to private hardware struct
3851 *
3852 * Returns 0 on success, negative on failure
3853 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003854static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003855{
3856 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003857 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003858 u32 ret = IXGBE_ERR_LINK_SETUP;
3859
3860 if (hw->mac.ops.check_link)
3861 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3862
3863 if (ret)
3864 goto link_cfg_out;
3865
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003866 autoneg = hw->phy.autoneg_advertised;
3867 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003868 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3869 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003870 if (ret)
3871 goto link_cfg_out;
3872
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003873 if (hw->mac.ops.setup_link)
3874 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003875link_cfg_out:
3876 return ret;
3877}
3878
Alexander Duycka34bcff2010-08-19 13:39:20 +00003879static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003880{
Auke Kok9a799d72007-09-15 14:07:45 -07003881 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003882 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003883
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003884 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003885 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3886 IXGBE_GPIE_OCD;
3887 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003888 /*
3889 * use EIAM to auto-mask when MSI-X interrupt is asserted
3890 * this saves a register write for every interrupt
3891 */
3892 switch (hw->mac.type) {
3893 case ixgbe_mac_82598EB:
3894 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3895 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003896 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003897 case ixgbe_mac_X540:
3898 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003899 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3900 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3901 break;
3902 }
3903 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003904 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3905 * specifically only auto mask tx and rx interrupts */
3906 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003907 }
3908
Alexander Duycka34bcff2010-08-19 13:39:20 +00003909 /* XXX: to interrupt immediately for EICS writes, enable this */
3910 /* gpie |= IXGBE_GPIE_EIMEN; */
3911
3912 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3913 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3914 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003915 }
3916
Alexander Duycka34bcff2010-08-19 13:39:20 +00003917 /* Enable fan failure interrupt */
3918 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003919 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003920
Don Skidmore2698b202011-04-13 07:01:52 +00003921 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003922 gpie |= IXGBE_SDP1_GPIEN;
3923 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003924 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003925
3926 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3927}
3928
3929static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3930{
3931 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003932 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003933 u32 ctrl_ext;
3934
3935 ixgbe_get_hw_control(adapter);
3936 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003937
Auke Kok9a799d72007-09-15 14:07:45 -07003938 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3939 ixgbe_configure_msix(adapter);
3940 else
3941 ixgbe_configure_msi_and_legacy(adapter);
3942
Don Skidmorec6ecf392010-12-03 03:31:51 +00003943 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3944 if (hw->mac.ops.enable_tx_laser &&
3945 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003946 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003947 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003948 hw->mac.ops.enable_tx_laser(hw);
3949
Auke Kok9a799d72007-09-15 14:07:45 -07003950 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003951 ixgbe_napi_enable_all(adapter);
3952
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003953 if (ixgbe_is_sfp(hw)) {
3954 ixgbe_sfp_link_config(adapter);
3955 } else {
3956 err = ixgbe_non_sfp_link_config(hw);
3957 if (err)
3958 e_err(probe, "link_config FAILED %d\n", err);
3959 }
3960
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003961 /* clear any pending interrupts, may auto mask */
3962 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003963 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003964
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003965 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003966 * If this adapter has a fan, check to see if we had a failure
3967 * before we enabled the interrupt.
3968 */
3969 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3970 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3971 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003972 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003973 }
3974
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003975 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003976 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003977
Auke Kok9a799d72007-09-15 14:07:45 -07003978 /* bring the link up in the watchdog, this could race with our first
3979 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003980 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3981 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003982 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003983
3984 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3985 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3986 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3987 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3988
Auke Kok9a799d72007-09-15 14:07:45 -07003989 return 0;
3990}
3991
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003992void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3993{
3994 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003995 /* put off any impending NetWatchDogTimeout */
3996 adapter->netdev->trans_start = jiffies;
3997
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003998 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003999 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004000 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004001 /*
4002 * If SR-IOV enabled then wait a bit before bringing the adapter
4003 * back up to give the VFs time to respond to the reset. The
4004 * two second wait is based upon the watchdog timer cycle in
4005 * the VF driver.
4006 */
4007 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4008 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004009 ixgbe_up(adapter);
4010 clear_bit(__IXGBE_RESETTING, &adapter->state);
4011}
4012
Auke Kok9a799d72007-09-15 14:07:45 -07004013int ixgbe_up(struct ixgbe_adapter *adapter)
4014{
4015 /* hardware has been reset, we need to reload some things */
4016 ixgbe_configure(adapter);
4017
4018 return ixgbe_up_complete(adapter);
4019}
4020
4021void ixgbe_reset(struct ixgbe_adapter *adapter)
4022{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004023 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004024 int err;
4025
Alexander Duyck70864002011-04-27 09:13:56 +00004026 /* lock SFP init bit to prevent race conditions with the watchdog */
4027 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4028 usleep_range(1000, 2000);
4029
4030 /* clear all SFP and link config related flags while holding SFP_INIT */
4031 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4032 IXGBE_FLAG2_SFP_NEEDS_RESET);
4033 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4034
Don Skidmore8ca783a2009-05-26 20:40:47 -07004035 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004036 switch (err) {
4037 case 0:
4038 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004039 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004040 break;
4041 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004042 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004043 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004044 case IXGBE_ERR_EEPROM_VERSION:
4045 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004046 e_dev_warn("This device is a pre-production adapter/LOM. "
4047 "Please be aware there may be issuesassociated with "
4048 "your hardware. If you are experiencing problems "
4049 "please contact your Intel or hardware "
4050 "representative who provided you with this "
4051 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004052 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004053 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004054 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004055 }
Auke Kok9a799d72007-09-15 14:07:45 -07004056
Alexander Duyck70864002011-04-27 09:13:56 +00004057 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4058
Auke Kok9a799d72007-09-15 14:07:45 -07004059 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004060 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4061 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004062}
4063
Auke Kok9a799d72007-09-15 14:07:45 -07004064/**
4065 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004066 * @rx_ring: ring to free buffers from
4067 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004068static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004069{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004070 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004071 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004072 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004073
Alexander Duyck84418e32010-08-19 13:40:54 +00004074 /* ring already cleared, nothing to do */
4075 if (!rx_ring->rx_buffer_info)
4076 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004077
Alexander Duyck84418e32010-08-19 13:40:54 +00004078 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004079 for (i = 0; i < rx_ring->count; i++) {
4080 struct ixgbe_rx_buffer *rx_buffer_info;
4081
4082 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4083 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004084 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004085 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004086 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004087 rx_buffer_info->dma = 0;
4088 }
4089 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004090 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004091 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004092 do {
4093 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004094 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004095 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004096 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004097 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004098 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004099 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004100 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004101 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004102 skb = skb->prev;
4103 dev_kfree_skb(this);
4104 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004105 }
4106 if (!rx_buffer_info->page)
4107 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004108 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004109 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004110 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004111 rx_buffer_info->page_dma = 0;
4112 }
Auke Kok9a799d72007-09-15 14:07:45 -07004113 put_page(rx_buffer_info->page);
4114 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004115 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004116 }
4117
4118 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4119 memset(rx_ring->rx_buffer_info, 0, size);
4120
4121 /* Zero out the descriptor ring */
4122 memset(rx_ring->desc, 0, rx_ring->size);
4123
4124 rx_ring->next_to_clean = 0;
4125 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004126}
4127
4128/**
4129 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004130 * @tx_ring: ring to be cleaned
4131 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004132static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004133{
4134 struct ixgbe_tx_buffer *tx_buffer_info;
4135 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004136 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004137
Alexander Duyck84418e32010-08-19 13:40:54 +00004138 /* ring already cleared, nothing to do */
4139 if (!tx_ring->tx_buffer_info)
4140 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004141
Alexander Duyck84418e32010-08-19 13:40:54 +00004142 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004143 for (i = 0; i < tx_ring->count; i++) {
4144 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004145 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004146 }
4147
4148 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4149 memset(tx_ring->tx_buffer_info, 0, size);
4150
4151 /* Zero out the descriptor ring */
4152 memset(tx_ring->desc, 0, tx_ring->size);
4153
4154 tx_ring->next_to_use = 0;
4155 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004156}
4157
4158/**
Auke Kok9a799d72007-09-15 14:07:45 -07004159 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4160 * @adapter: board private structure
4161 **/
4162static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4163{
4164 int i;
4165
4166 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004167 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004168}
4169
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004170/**
4171 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4172 * @adapter: board private structure
4173 **/
4174static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4175{
4176 int i;
4177
4178 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004179 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004180}
4181
Auke Kok9a799d72007-09-15 14:07:45 -07004182void ixgbe_down(struct ixgbe_adapter *adapter)
4183{
4184 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004185 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004186 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004187 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004188 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004189
4190 /* signal that we are down to the interrupt handler */
4191 set_bit(__IXGBE_DOWN, &adapter->state);
4192
4193 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004194 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4195 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004196
Yi Zou2d39d572011-01-06 14:29:56 +00004197 /* disable all enabled rx queues */
4198 for (i = 0; i < adapter->num_rx_queues; i++)
4199 /* this call also flushes the previous write */
4200 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4201
Don Skidmore032b4322011-03-18 09:32:53 +00004202 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004203
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004204 netif_tx_stop_all_queues(netdev);
4205
Alexander Duyck70864002011-04-27 09:13:56 +00004206 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004207 netif_carrier_off(netdev);
4208 netif_tx_disable(netdev);
4209
4210 ixgbe_irq_disable(adapter);
4211
4212 ixgbe_napi_disable_all(adapter);
4213
Alexander Duyckd034acf2011-04-27 09:25:34 +00004214 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4215 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004216 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4217
4218 del_timer_sync(&adapter->service_timer);
4219
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004220 /* disable receive for all VFs and wait one second */
4221 if (adapter->num_vfs) {
4222 /* ping all the active vfs to let them know we are going down */
4223 ixgbe_ping_all_vfs(adapter);
4224
4225 /* Disable all VFTE/VFRE TX/RX */
4226 ixgbe_disable_tx_rx(adapter);
4227
4228 /* Mark all the VFs as inactive */
4229 for (i = 0 ; i < adapter->num_vfs; i++)
4230 adapter->vfinfo[i].clear_to_send = 0;
4231 }
4232
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004233 /* Cleanup the affinity_hint CPU mask memory and callback */
4234 for (i = 0; i < num_q_vectors; i++) {
4235 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4236 /* clear the affinity_mask in the IRQ descriptor */
4237 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4238 /* release the CPU mask memory */
4239 free_cpumask_var(q_vector->affinity_mask);
4240 }
4241
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004242 /* disable transmits in the hardware now that interrupts are off */
4243 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004244 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004245 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004246 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004247
4248 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004249 switch (hw->mac.type) {
4250 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004251 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004252 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004253 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4254 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004255 break;
4256 default:
4257 break;
4258 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004259
Paul Larson6f4a0e42008-06-24 17:00:56 -07004260 if (!pci_channel_offline(adapter->pdev))
4261 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004262
4263 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4264 if (hw->mac.ops.disable_tx_laser &&
4265 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004266 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004267 (hw->mac.type == ixgbe_mac_82599EB))))
4268 hw->mac.ops.disable_tx_laser(hw);
4269
Auke Kok9a799d72007-09-15 14:07:45 -07004270 ixgbe_clean_all_tx_rings(adapter);
4271 ixgbe_clean_all_rx_rings(adapter);
4272
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004273#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004274 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004275 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004276#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004277}
4278
Auke Kok9a799d72007-09-15 14:07:45 -07004279/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004280 * ixgbe_poll - NAPI Rx polling callback
4281 * @napi: structure for representing this polling device
4282 * @budget: how many packets driver is allowed to clean
4283 *
4284 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004285 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004286static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004287{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004288 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004289 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004290 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004291 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004292
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004293#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004294 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4295 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004296#endif
4297
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004298 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4299 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004300
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004301 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004302 work_done = budget;
4303
David S. Miller53e52c72008-01-07 21:06:12 -08004304 /* If budget not fully consumed, exit the polling mode */
4305 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004306 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004307 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004308 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004309 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004310 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004311 }
Auke Kok9a799d72007-09-15 14:07:45 -07004312 return work_done;
4313}
4314
4315/**
4316 * ixgbe_tx_timeout - Respond to a Tx Hang
4317 * @netdev: network interface device structure
4318 **/
4319static void ixgbe_tx_timeout(struct net_device *netdev)
4320{
4321 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4322
4323 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004324 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004325}
4326
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004327/**
4328 * ixgbe_set_rss_queues: Allocate queues for RSS
4329 * @adapter: board private structure to initialize
4330 *
4331 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4332 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4333 *
4334 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004335static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4336{
4337 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004338 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004339
4340 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004341 f->mask = 0xF;
4342 adapter->num_rx_queues = f->indices;
4343 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004344 ret = true;
4345 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004346 ret = false;
4347 }
4348
4349 return ret;
4350}
4351
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004352/**
4353 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4354 * @adapter: board private structure to initialize
4355 *
4356 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4357 * to the original CPU that initiated the Tx session. This runs in addition
4358 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4359 * Rx load across CPUs using RSS.
4360 *
4361 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004362static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004363{
4364 bool ret = false;
4365 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4366
4367 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4368 f_fdir->mask = 0;
4369
4370 /* Flow Director must have RSS enabled */
4371 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4372 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4373 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4374 adapter->num_tx_queues = f_fdir->indices;
4375 adapter->num_rx_queues = f_fdir->indices;
4376 ret = true;
4377 } else {
4378 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4379 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4380 }
4381 return ret;
4382}
4383
Yi Zou0331a832009-05-17 12:33:52 +00004384#ifdef IXGBE_FCOE
4385/**
4386 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4387 * @adapter: board private structure to initialize
4388 *
4389 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4390 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4391 * rx queues out of the max number of rx queues, instead, it is used as the
4392 * index of the first rx queue used by FCoE.
4393 *
4394 **/
4395static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4396{
Yi Zou0331a832009-05-17 12:33:52 +00004397 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4398
John Fastabende5b64632011-03-08 03:44:52 +00004399 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4400 return false;
4401
4402 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4403#ifdef CONFIG_IXGBE_DCB
4404 int tc;
4405 struct net_device *dev = adapter->netdev;
4406
4407 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4408 f->indices = dev->tc_to_txq[tc].count;
4409 f->mask = dev->tc_to_txq[tc].offset;
4410#endif
4411 } else {
4412 f->indices = min((int)num_online_cpus(), f->indices);
4413
Yi Zou8de8b2e2009-09-03 14:55:50 +00004414 adapter->num_rx_queues = 1;
4415 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004416
Yi Zou0331a832009-05-17 12:33:52 +00004417 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004418 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004419 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4420 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4421 ixgbe_set_fdir_queues(adapter);
4422 else
4423 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004424 }
4425 /* adding FCoE rx rings to the end */
4426 f->mask = adapter->num_rx_queues;
4427 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004428 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004429 }
4430
John Fastabende5b64632011-03-08 03:44:52 +00004431 return true;
4432}
4433#endif /* IXGBE_FCOE */
4434
4435#ifdef CONFIG_IXGBE_DCB
4436static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4437{
4438 bool ret = false;
4439 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4440 int i, q;
4441
4442 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4443 return ret;
4444
4445 f->indices = 0;
4446 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4447 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4448 f->indices += q;
4449 }
4450
4451 f->mask = 0x7 << 3;
4452 adapter->num_rx_queues = f->indices;
4453 adapter->num_tx_queues = f->indices;
4454 ret = true;
4455
4456#ifdef IXGBE_FCOE
4457 /* FCoE enabled queues require special configuration done through
4458 * configure_fcoe() and others. Here we map FCoE indices onto the
4459 * DCB queue pairs allowing FCoE to own configuration later.
4460 */
4461 ixgbe_set_fcoe_queues(adapter);
4462#endif
4463
Yi Zou0331a832009-05-17 12:33:52 +00004464 return ret;
4465}
John Fastabende5b64632011-03-08 03:44:52 +00004466#endif
Yi Zou0331a832009-05-17 12:33:52 +00004467
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004468/**
4469 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4470 * @adapter: board private structure to initialize
4471 *
4472 * IOV doesn't actually use anything, so just NAK the
4473 * request for now and let the other queue routines
4474 * figure out what to do.
4475 */
4476static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4477{
4478 return false;
4479}
4480
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004481/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004482 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004483 * @adapter: board private structure to initialize
4484 *
4485 * This is the top level queue allocation routine. The order here is very
4486 * important, starting with the "most" number of features turned on at once,
4487 * and ending with the smallest set of features. This way large combinations
4488 * can be allocated if they're turned on, and smaller combinations are the
4489 * fallthrough conditions.
4490 *
4491 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004492static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004493{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004494 /* Start with base case */
4495 adapter->num_rx_queues = 1;
4496 adapter->num_tx_queues = 1;
4497 adapter->num_rx_pools = adapter->num_rx_queues;
4498 adapter->num_rx_queues_per_pool = 1;
4499
4500 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004501 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004502
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004503#ifdef CONFIG_IXGBE_DCB
4504 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004505 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004506
4507#endif
John Fastabende5b64632011-03-08 03:44:52 +00004508#ifdef IXGBE_FCOE
4509 if (ixgbe_set_fcoe_queues(adapter))
4510 goto done;
4511
4512#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004513 if (ixgbe_set_fdir_queues(adapter))
4514 goto done;
4515
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004516 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004517 goto done;
4518
4519 /* fallback to base case */
4520 adapter->num_rx_queues = 1;
4521 adapter->num_tx_queues = 1;
4522
4523done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004524 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004525 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004526 return netif_set_real_num_rx_queues(adapter->netdev,
4527 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004528}
4529
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004530static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004531 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004532{
4533 int err, vector_threshold;
4534
4535 /* We'll want at least 3 (vector_threshold):
4536 * 1) TxQ[0] Cleanup
4537 * 2) RxQ[0] Cleanup
4538 * 3) Other (Link Status Change, etc.)
4539 * 4) TCP Timer (optional)
4540 */
4541 vector_threshold = MIN_MSIX_COUNT;
4542
4543 /* The more we get, the more we will assign to Tx/Rx Cleanup
4544 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4545 * Right now, we simply care about how many we'll get; we'll
4546 * set them up later while requesting irq's.
4547 */
4548 while (vectors >= vector_threshold) {
4549 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004550 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004551 if (!err) /* Success in acquiring all requested vectors. */
4552 break;
4553 else if (err < 0)
4554 vectors = 0; /* Nasty failure, quit now */
4555 else /* err == number of vectors we should try again with */
4556 vectors = err;
4557 }
4558
4559 if (vectors < vector_threshold) {
4560 /* Can't allocate enough MSI-X interrupts? Oh well.
4561 * This just means we'll go with either a single MSI
4562 * vector or fall back to legacy interrupts.
4563 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004564 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4565 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004566 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4567 kfree(adapter->msix_entries);
4568 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004569 } else {
4570 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004571 /*
4572 * Adjust for only the vectors we'll use, which is minimum
4573 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4574 * vectors we were allocated.
4575 */
4576 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004577 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004578 }
4579}
4580
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004581/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004582 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004583 * @adapter: board private structure to initialize
4584 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004585 * Cache the descriptor ring offsets for RSS to the assigned rings.
4586 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004587 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004588static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004589{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004590 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004591
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004592 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4593 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004594
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004595 for (i = 0; i < adapter->num_rx_queues; i++)
4596 adapter->rx_ring[i]->reg_idx = i;
4597 for (i = 0; i < adapter->num_tx_queues; i++)
4598 adapter->tx_ring[i]->reg_idx = i;
4599
4600 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004601}
4602
4603#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004604
4605/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004606static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4607 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004608{
4609 struct net_device *dev = adapter->netdev;
4610 struct ixgbe_hw *hw = &adapter->hw;
4611 u8 num_tcs = netdev_get_num_tc(dev);
4612
4613 *tx = 0;
4614 *rx = 0;
4615
4616 switch (hw->mac.type) {
4617 case ixgbe_mac_82598EB:
4618 *tx = tc << 3;
4619 *rx = tc << 2;
4620 break;
4621 case ixgbe_mac_82599EB:
4622 case ixgbe_mac_X540:
4623 if (num_tcs == 8) {
4624 if (tc < 3) {
4625 *tx = tc << 5;
4626 *rx = tc << 4;
4627 } else if (tc < 5) {
4628 *tx = ((tc + 2) << 4);
4629 *rx = tc << 4;
4630 } else if (tc < num_tcs) {
4631 *tx = ((tc + 8) << 3);
4632 *rx = tc << 4;
4633 }
4634 } else if (num_tcs == 4) {
4635 *rx = tc << 5;
4636 switch (tc) {
4637 case 0:
4638 *tx = 0;
4639 break;
4640 case 1:
4641 *tx = 64;
4642 break;
4643 case 2:
4644 *tx = 96;
4645 break;
4646 case 3:
4647 *tx = 112;
4648 break;
4649 default:
4650 break;
4651 }
4652 }
4653 break;
4654 default:
4655 break;
4656 }
4657}
4658
4659#define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4660
4661/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4662 * classes.
4663 *
4664 * @netdev: net device to configure
4665 * @tc: number of traffic classes to enable
4666 */
4667int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4668{
4669 int i;
4670 unsigned int q, offset = 0;
4671
4672 if (!tc) {
4673 netdev_reset_tc(dev);
4674 } else {
John Fastabend24095aa2011-02-23 05:58:03 +00004675 struct ixgbe_adapter *adapter = netdev_priv(dev);
4676
4677 /* Hardware supports up to 8 traffic classes */
4678 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
John Fastabende5b64632011-03-08 03:44:52 +00004679 return -EINVAL;
4680
4681 /* Partition Tx queues evenly amongst traffic classes */
4682 for (i = 0; i < tc; i++) {
4683 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4684 netdev_set_prio_tc_map(dev, i, i);
4685 netdev_set_tc_queue(dev, i, q, offset);
4686 offset += q;
4687 }
John Fastabend24095aa2011-02-23 05:58:03 +00004688
4689 /* This enables multiple traffic class support in the hardware
4690 * which defaults to strict priority transmission by default.
4691 * If traffic classes are already enabled perhaps through DCB
4692 * code path then existing configuration will be used.
4693 */
4694 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4695 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4696 struct ieee_ets ets = {
4697 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4698 };
4699 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4700
4701 dev->dcbnl_ops->setdcbx(dev, mode);
4702 dev->dcbnl_ops->ieee_setets(dev, &ets);
4703 }
John Fastabende5b64632011-03-08 03:44:52 +00004704 }
4705 return 0;
4706}
4707
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004708/**
4709 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4710 * @adapter: board private structure to initialize
4711 *
4712 * Cache the descriptor ring offsets for DCB to the assigned rings.
4713 *
4714 **/
4715static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4716{
John Fastabende5b64632011-03-08 03:44:52 +00004717 struct net_device *dev = adapter->netdev;
4718 int i, j, k;
4719 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004720
Alexander Duyckbd508172010-11-16 19:27:03 -08004721 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4722 return false;
4723
John Fastabende5b64632011-03-08 03:44:52 +00004724 for (i = 0, k = 0; i < num_tcs; i++) {
4725 unsigned int tx_s, rx_s;
4726 u16 count = dev->tc_to_txq[i].count;
4727
4728 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4729 for (j = 0; j < count; j++, k++) {
4730 adapter->tx_ring[k]->reg_idx = tx_s + j;
4731 adapter->rx_ring[k]->reg_idx = rx_s + j;
4732 adapter->tx_ring[k]->dcb_tc = i;
4733 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004734 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004735 }
John Fastabende5b64632011-03-08 03:44:52 +00004736
4737 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004738}
4739#endif
4740
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004741/**
4742 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4743 * @adapter: board private structure to initialize
4744 *
4745 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4746 *
4747 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004748static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004749{
4750 int i;
4751 bool ret = false;
4752
4753 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4754 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4755 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4756 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004757 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004758 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004759 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004760 ret = true;
4761 }
4762
4763 return ret;
4764}
4765
Yi Zou0331a832009-05-17 12:33:52 +00004766#ifdef IXGBE_FCOE
4767/**
4768 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4769 * @adapter: board private structure to initialize
4770 *
4771 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4772 *
4773 */
4774static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4775{
Yi Zou0331a832009-05-17 12:33:52 +00004776 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004777 int i;
4778 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004779
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004780 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4781 return false;
4782
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004783 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4784 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4785 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4786 ixgbe_cache_ring_fdir(adapter);
4787 else
4788 ixgbe_cache_ring_rss(adapter);
4789
4790 fcoe_rx_i = f->mask;
4791 fcoe_tx_i = f->mask;
4792 }
4793 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4794 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4795 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4796 }
4797 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004798}
4799
4800#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004801/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004802 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4803 * @adapter: board private structure to initialize
4804 *
4805 * SR-IOV doesn't use any descriptor rings but changes the default if
4806 * no other mapping is used.
4807 *
4808 */
4809static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4810{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004811 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4812 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004813 if (adapter->num_vfs)
4814 return true;
4815 else
4816 return false;
4817}
4818
4819/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004820 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4821 * @adapter: board private structure to initialize
4822 *
4823 * Once we know the feature-set enabled for the device, we'll cache
4824 * the register offset the descriptor ring is assigned to.
4825 *
4826 * Note, the order the various feature calls is important. It must start with
4827 * the "most" features enabled at the same time, then trickle down to the
4828 * least amount of features turned on at once.
4829 **/
4830static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4831{
4832 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004833 adapter->rx_ring[0]->reg_idx = 0;
4834 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004835
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004836 if (ixgbe_cache_ring_sriov(adapter))
4837 return;
4838
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004839#ifdef CONFIG_IXGBE_DCB
4840 if (ixgbe_cache_ring_dcb(adapter))
4841 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004842#endif
John Fastabende5b64632011-03-08 03:44:52 +00004843
4844#ifdef IXGBE_FCOE
4845 if (ixgbe_cache_ring_fcoe(adapter))
4846 return;
4847#endif /* IXGBE_FCOE */
4848
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004849 if (ixgbe_cache_ring_fdir(adapter))
4850 return;
4851
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004852 if (ixgbe_cache_ring_rss(adapter))
4853 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004854}
4855
Auke Kok9a799d72007-09-15 14:07:45 -07004856/**
4857 * ixgbe_alloc_queues - Allocate memory for all rings
4858 * @adapter: board private structure to initialize
4859 *
4860 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004861 * number of queues at compile-time. The polling_netdev array is
4862 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004863 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004864static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004865{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004866 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004867
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004868 if (nid < 0 || !node_online(nid))
4869 nid = first_online_node;
4870
4871 for (; tx < adapter->num_tx_queues; tx++) {
4872 struct ixgbe_ring *ring;
4873
4874 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004875 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004876 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004877 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004878 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004879 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004880 ring->queue_index = tx;
4881 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004882 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004883 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004884
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004885 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004886 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004887
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004888 for (; rx < adapter->num_rx_queues; rx++) {
4889 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004890
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004891 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004892 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004893 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004894 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004895 goto err_allocation;
4896 ring->count = adapter->rx_ring_count;
4897 ring->queue_index = rx;
4898 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004899 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004900 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004901
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004902 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004903 }
4904
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004905 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004906
4907 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004908
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004909err_allocation:
4910 while (tx)
4911 kfree(adapter->tx_ring[--tx]);
4912
4913 while (rx)
4914 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004915 return -ENOMEM;
4916}
4917
4918/**
4919 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4920 * @adapter: board private structure to initialize
4921 *
4922 * Attempt to configure the interrupts using the best available
4923 * capabilities of the hardware and the kernel.
4924 **/
Al Virofeea6a52008-11-27 15:34:07 -08004925static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004926{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004927 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004928 int err = 0;
4929 int vector, v_budget;
4930
4931 /*
4932 * It's easy to be greedy for MSI-X vectors, but it really
4933 * doesn't do us much good if we have a lot more vectors
4934 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004935 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004936 */
4937 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004938 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004939
4940 /*
4941 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004942 * hw.mac->max_msix_vectors vectors. With features
4943 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4944 * descriptor queues supported by our device. Thus, we cap it off in
4945 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004946 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004947 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004948
4949 /* A failure in MSI-X entry allocation isn't fatal, but it does
4950 * mean we disable MSI-X capabilities of the adapter. */
4951 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004952 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004953 if (adapter->msix_entries) {
4954 for (vector = 0; vector < v_budget; vector++)
4955 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004956
Alexander Duyck7a921c92009-05-06 10:43:28 +00004957 ixgbe_acquire_msix_vectors(adapter, v_budget);
4958
4959 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4960 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004961 }
David S. Miller26d27842010-05-03 15:18:22 -07004962
Alexander Duyck7a921c92009-05-06 10:43:28 +00004963 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4964 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004965 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4966 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4967 e_err(probe,
4968 "Flow Director is not supported while multiple "
4969 "queues are disabled. Disabling Flow Director\n");
4970 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004971 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4972 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4973 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004974 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4975 ixgbe_disable_sriov(adapter);
4976
Ben Hutchings847f53f2010-09-27 08:28:56 +00004977 err = ixgbe_set_num_queues(adapter);
4978 if (err)
4979 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004980
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004981 err = pci_enable_msi(adapter->pdev);
4982 if (!err) {
4983 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4984 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004985 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4986 "Unable to allocate MSI interrupt, "
4987 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004988 /* reset err */
4989 err = 0;
4990 }
4991
4992out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004993 return err;
4994}
4995
Alexander Duyck7a921c92009-05-06 10:43:28 +00004996/**
4997 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4998 * @adapter: board private structure to initialize
4999 *
5000 * We allocate one q_vector per queue interrupt. If allocation fails we
5001 * return -ENOMEM.
5002 **/
5003static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5004{
5005 int q_idx, num_q_vectors;
5006 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005007 int (*poll)(struct napi_struct *, int);
5008
5009 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5010 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005011 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005012 } else {
5013 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005014 poll = &ixgbe_poll;
5015 }
5016
5017 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005018 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005019 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005020 if (!q_vector)
5021 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005022 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005023 if (!q_vector)
5024 goto err_out;
5025 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005026 if (q_vector->txr_count && !q_vector->rxr_count)
5027 q_vector->eitr = adapter->tx_eitr_param;
5028 else
5029 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005030 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005031 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005032 adapter->q_vector[q_idx] = q_vector;
5033 }
5034
5035 return 0;
5036
5037err_out:
5038 while (q_idx) {
5039 q_idx--;
5040 q_vector = adapter->q_vector[q_idx];
5041 netif_napi_del(&q_vector->napi);
5042 kfree(q_vector);
5043 adapter->q_vector[q_idx] = NULL;
5044 }
5045 return -ENOMEM;
5046}
5047
5048/**
5049 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5050 * @adapter: board private structure to initialize
5051 *
5052 * This function frees the memory allocated to the q_vectors. In addition if
5053 * NAPI is enabled it will delete any references to the NAPI struct prior
5054 * to freeing the q_vector.
5055 **/
5056static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5057{
5058 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005059
Alexander Duyck91281fd2009-06-04 16:00:27 +00005060 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005061 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005062 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005063 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005064
5065 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5066 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005067 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005068 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005069 kfree(q_vector);
5070 }
5071}
5072
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005073static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005074{
5075 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5076 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5077 pci_disable_msix(adapter->pdev);
5078 kfree(adapter->msix_entries);
5079 adapter->msix_entries = NULL;
5080 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5081 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5082 pci_disable_msi(adapter->pdev);
5083 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005084}
5085
5086/**
5087 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5088 * @adapter: board private structure to initialize
5089 *
5090 * We determine which interrupt scheme to use based on...
5091 * - Kernel support (MSI, MSI-X)
5092 * - which can be user-defined (via MODULE_PARAM)
5093 * - Hardware queue count (num_*_queues)
5094 * - defined by miscellaneous hardware support/features (RSS, etc.)
5095 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005096int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005097{
5098 int err;
5099
5100 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005101 err = ixgbe_set_num_queues(adapter);
5102 if (err)
5103 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005104
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005105 err = ixgbe_set_interrupt_capability(adapter);
5106 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005107 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005108 goto err_set_interrupt;
5109 }
5110
Alexander Duyck7a921c92009-05-06 10:43:28 +00005111 err = ixgbe_alloc_q_vectors(adapter);
5112 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005113 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005114 goto err_alloc_q_vectors;
5115 }
5116
5117 err = ixgbe_alloc_queues(adapter);
5118 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005119 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005120 goto err_alloc_queues;
5121 }
5122
Emil Tantilov849c4542010-06-03 16:53:41 +00005123 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005124 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5125 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005126
5127 set_bit(__IXGBE_DOWN, &adapter->state);
5128
5129 return 0;
5130
Alexander Duyck7a921c92009-05-06 10:43:28 +00005131err_alloc_queues:
5132 ixgbe_free_q_vectors(adapter);
5133err_alloc_q_vectors:
5134 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005135err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005136 return err;
5137}
5138
Eric Dumazet1a515022010-11-16 19:26:42 -08005139static void ring_free_rcu(struct rcu_head *head)
5140{
5141 kfree(container_of(head, struct ixgbe_ring, rcu));
5142}
5143
Alexander Duyck7a921c92009-05-06 10:43:28 +00005144/**
5145 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5146 * @adapter: board private structure to clear interrupt scheme on
5147 *
5148 * We go through and clear interrupt specific resources and reset the structure
5149 * to pre-load conditions
5150 **/
5151void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5152{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005153 int i;
5154
5155 for (i = 0; i < adapter->num_tx_queues; i++) {
5156 kfree(adapter->tx_ring[i]);
5157 adapter->tx_ring[i] = NULL;
5158 }
5159 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005160 struct ixgbe_ring *ring = adapter->rx_ring[i];
5161
5162 /* ixgbe_get_stats64() might access this ring, we must wait
5163 * a grace period before freeing it.
5164 */
5165 call_rcu(&ring->rcu, ring_free_rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005166 adapter->rx_ring[i] = NULL;
5167 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005168
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005169 adapter->num_tx_queues = 0;
5170 adapter->num_rx_queues = 0;
5171
Alexander Duyck7a921c92009-05-06 10:43:28 +00005172 ixgbe_free_q_vectors(adapter);
5173 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005174}
5175
5176/**
5177 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5178 * @adapter: board private structure to initialize
5179 *
5180 * ixgbe_sw_init initializes the Adapter private data structure.
5181 * Fields are initialized based on PCI device information and
5182 * OS network device settings (MTU size).
5183 **/
5184static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5185{
5186 struct ixgbe_hw *hw = &adapter->hw;
5187 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005188 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005189 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005190#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005191 int j;
5192 struct tc_configuration *tc;
5193#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005194 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005195
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005196 /* PCI config space info */
5197
5198 hw->vendor_id = pdev->vendor;
5199 hw->device_id = pdev->device;
5200 hw->revision_id = pdev->revision;
5201 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5202 hw->subsystem_device_id = pdev->subsystem_device;
5203
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005204 /* Set capability flags */
5205 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5206 adapter->ring_feature[RING_F_RSS].indices = rss;
5207 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005208 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005209 switch (hw->mac.type) {
5210 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005211 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5212 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005213 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005214 break;
5215 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005216 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005217 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005218 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5219 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005220 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5221 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005222 /* n-tuple support exists, always init our spinlock */
5223 spin_lock_init(&adapter->fdir_perfect_lock);
5224 /* Flow Director hash filters enabled */
5225 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5226 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005227 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005228 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005229 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005230#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005231 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5232 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5233 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005234#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005235 /* Default traffic class to use for FCoE */
5236 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005237 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005238#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005239#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005240 break;
5241 default:
5242 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005243 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005244
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005245#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005246 /* Configure DCB traffic classes */
5247 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5248 tc = &adapter->dcb_cfg.tc_config[j];
5249 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5250 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5251 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5252 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5253 tc->dcb_pfc = pfc_disabled;
5254 }
5255 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5256 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5257 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005258 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005259 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005260 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005261 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005262 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005263
5264#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005265
5266 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005267 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005268 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005269#ifdef CONFIG_DCB
5270 adapter->last_lfc_mode = hw->fc.current_mode;
5271#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005272 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5273 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005274 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5275 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005276 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005277
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005278 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005279 adapter->rx_itr_setting = 1;
5280 adapter->rx_eitr_param = 20000;
5281 adapter->tx_itr_setting = 1;
5282 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005283
5284 /* set defaults for eitr in MegaBytes */
5285 adapter->eitr_low = 10;
5286 adapter->eitr_high = 20;
5287
5288 /* set default ring sizes */
5289 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5290 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5291
Auke Kok9a799d72007-09-15 14:07:45 -07005292 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005293 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005294 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005295 return -EIO;
5296 }
5297
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005298 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005299 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5300
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005301 /* get assigned NUMA node */
5302 adapter->node = dev_to_node(&pdev->dev);
5303
Auke Kok9a799d72007-09-15 14:07:45 -07005304 set_bit(__IXGBE_DOWN, &adapter->state);
5305
5306 return 0;
5307}
5308
5309/**
5310 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005311 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005312 *
5313 * Return 0 on success, negative on failure
5314 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005315int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005316{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005317 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005318 int size;
5319
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005320 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005321 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005322 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005323 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005324 if (!tx_ring->tx_buffer_info)
5325 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005326
5327 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005328 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005329 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005330
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005331 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005332 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005333 if (!tx_ring->desc)
5334 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005335
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005336 tx_ring->next_to_use = 0;
5337 tx_ring->next_to_clean = 0;
5338 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005339 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005340
5341err:
5342 vfree(tx_ring->tx_buffer_info);
5343 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005344 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005345 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005346}
5347
5348/**
Alexander Duyck69888672008-09-11 20:05:39 -07005349 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5350 * @adapter: board private structure
5351 *
5352 * If this function returns with an error, then it's possible one or
5353 * more of the rings is populated (while the rest are not). It is the
5354 * callers duty to clean those orphaned rings.
5355 *
5356 * Return 0 on success, negative on failure
5357 **/
5358static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5359{
5360 int i, err = 0;
5361
5362 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005363 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005364 if (!err)
5365 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005366 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005367 break;
5368 }
5369
5370 return err;
5371}
5372
5373/**
Auke Kok9a799d72007-09-15 14:07:45 -07005374 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005375 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005376 *
5377 * Returns 0 on success, negative on failure
5378 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005379int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005380{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005381 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005382 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005383
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005384 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005385 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005386 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005387 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388 if (!rx_ring->rx_buffer_info)
5389 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005390
Auke Kok9a799d72007-09-15 14:07:45 -07005391 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005392 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5393 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005394
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005395 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005396 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005397
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005398 if (!rx_ring->desc)
5399 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005400
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005401 rx_ring->next_to_clean = 0;
5402 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005403
5404 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005405err:
5406 vfree(rx_ring->rx_buffer_info);
5407 rx_ring->rx_buffer_info = NULL;
5408 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005409 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005410}
5411
5412/**
Alexander Duyck69888672008-09-11 20:05:39 -07005413 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5414 * @adapter: board private structure
5415 *
5416 * If this function returns with an error, then it's possible one or
5417 * more of the rings is populated (while the rest are not). It is the
5418 * callers duty to clean those orphaned rings.
5419 *
5420 * Return 0 on success, negative on failure
5421 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005422static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5423{
5424 int i, err = 0;
5425
5426 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005427 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005428 if (!err)
5429 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005430 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005431 break;
5432 }
5433
5434 return err;
5435}
5436
5437/**
Auke Kok9a799d72007-09-15 14:07:45 -07005438 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005439 * @tx_ring: Tx descriptor ring for a specific queue
5440 *
5441 * Free all transmit software resources
5442 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005443void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005444{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005445 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005446
5447 vfree(tx_ring->tx_buffer_info);
5448 tx_ring->tx_buffer_info = NULL;
5449
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005450 /* if not set, then don't free */
5451 if (!tx_ring->desc)
5452 return;
5453
5454 dma_free_coherent(tx_ring->dev, tx_ring->size,
5455 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005456
5457 tx_ring->desc = NULL;
5458}
5459
5460/**
5461 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5462 * @adapter: board private structure
5463 *
5464 * Free all transmit software resources
5465 **/
5466static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5467{
5468 int i;
5469
5470 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005471 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005472 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005473}
5474
5475/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005476 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005477 * @rx_ring: ring to clean the resources from
5478 *
5479 * Free all receive software resources
5480 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005481void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005482{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005483 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005484
5485 vfree(rx_ring->rx_buffer_info);
5486 rx_ring->rx_buffer_info = NULL;
5487
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005488 /* if not set, then don't free */
5489 if (!rx_ring->desc)
5490 return;
5491
5492 dma_free_coherent(rx_ring->dev, rx_ring->size,
5493 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005494
5495 rx_ring->desc = NULL;
5496}
5497
5498/**
5499 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5500 * @adapter: board private structure
5501 *
5502 * Free all receive software resources
5503 **/
5504static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5505{
5506 int i;
5507
5508 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005509 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005510 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005511}
5512
5513/**
Auke Kok9a799d72007-09-15 14:07:45 -07005514 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5515 * @netdev: network interface device structure
5516 * @new_mtu: new value for maximum frame size
5517 *
5518 * Returns 0 on success, negative on failure
5519 **/
5520static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5521{
5522 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005523 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005524 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5525
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005526 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005527 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5528 hw->mac.type != ixgbe_mac_X540) {
5529 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5530 return -EINVAL;
5531 } else {
5532 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5533 return -EINVAL;
5534 }
Auke Kok9a799d72007-09-15 14:07:45 -07005535
Emil Tantilov396e7992010-07-01 20:05:12 +00005536 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005537 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005538 netdev->mtu = new_mtu;
5539
John Fastabend16b61be2010-11-16 19:26:44 -08005540 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5541 hw->fc.low_water = FC_LOW_WATER(max_frame);
5542
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005543 if (netif_running(netdev))
5544 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005545
5546 return 0;
5547}
5548
5549/**
5550 * ixgbe_open - Called when a network interface is made active
5551 * @netdev: network interface device structure
5552 *
5553 * Returns 0 on success, negative value on failure
5554 *
5555 * The open entry point is called when a network interface is made
5556 * active by the system (IFF_UP). At this point all resources needed
5557 * for transmit and receive operations are allocated, the interrupt
5558 * handler is registered with the OS, the watchdog timer is started,
5559 * and the stack is notified that the interface is ready.
5560 **/
5561static int ixgbe_open(struct net_device *netdev)
5562{
5563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5564 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005565
Auke Kok4bebfaa2008-02-11 09:26:01 -08005566 /* disallow open during test */
5567 if (test_bit(__IXGBE_TESTING, &adapter->state))
5568 return -EBUSY;
5569
Jesse Brandeburg54386462009-04-17 20:44:27 +00005570 netif_carrier_off(netdev);
5571
Auke Kok9a799d72007-09-15 14:07:45 -07005572 /* allocate transmit descriptors */
5573 err = ixgbe_setup_all_tx_resources(adapter);
5574 if (err)
5575 goto err_setup_tx;
5576
Auke Kok9a799d72007-09-15 14:07:45 -07005577 /* allocate receive descriptors */
5578 err = ixgbe_setup_all_rx_resources(adapter);
5579 if (err)
5580 goto err_setup_rx;
5581
5582 ixgbe_configure(adapter);
5583
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005584 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005585 if (err)
5586 goto err_req_irq;
5587
Auke Kok9a799d72007-09-15 14:07:45 -07005588 err = ixgbe_up_complete(adapter);
5589 if (err)
5590 goto err_up;
5591
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005592 netif_tx_start_all_queues(netdev);
5593
Auke Kok9a799d72007-09-15 14:07:45 -07005594 return 0;
5595
5596err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005597 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005598 ixgbe_free_irq(adapter);
5599err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005600err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005601 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005602err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005603 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005604 ixgbe_reset(adapter);
5605
5606 return err;
5607}
5608
5609/**
5610 * ixgbe_close - Disables a network interface
5611 * @netdev: network interface device structure
5612 *
5613 * Returns 0, this is not allowed to fail
5614 *
5615 * The close entry point is called when an interface is de-activated
5616 * by the OS. The hardware is still under the drivers control, but
5617 * needs to be disabled. A global MAC reset is issued to stop the
5618 * hardware, and all transmit and receive resources are freed.
5619 **/
5620static int ixgbe_close(struct net_device *netdev)
5621{
5622 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005623
5624 ixgbe_down(adapter);
5625 ixgbe_free_irq(adapter);
5626
5627 ixgbe_free_all_tx_resources(adapter);
5628 ixgbe_free_all_rx_resources(adapter);
5629
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005630 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005631
5632 return 0;
5633}
5634
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005635#ifdef CONFIG_PM
5636static int ixgbe_resume(struct pci_dev *pdev)
5637{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005638 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5639 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005640 u32 err;
5641
5642 pci_set_power_state(pdev, PCI_D0);
5643 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005644 /*
5645 * pci_restore_state clears dev->state_saved so call
5646 * pci_save_state to restore it.
5647 */
5648 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005649
5650 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005651 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005652 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005653 return err;
5654 }
5655 pci_set_master(pdev);
5656
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005657 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005658
5659 err = ixgbe_init_interrupt_scheme(adapter);
5660 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005661 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005662 return err;
5663 }
5664
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005665 ixgbe_reset(adapter);
5666
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005667 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5668
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005669 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005670 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005671 if (err)
5672 return err;
5673 }
5674
5675 netif_device_attach(netdev);
5676
5677 return 0;
5678}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005679#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005680
5681static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005682{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005683 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5684 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005685 struct ixgbe_hw *hw = &adapter->hw;
5686 u32 ctrl, fctrl;
5687 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005688#ifdef CONFIG_PM
5689 int retval = 0;
5690#endif
5691
5692 netif_device_detach(netdev);
5693
5694 if (netif_running(netdev)) {
5695 ixgbe_down(adapter);
5696 ixgbe_free_irq(adapter);
5697 ixgbe_free_all_tx_resources(adapter);
5698 ixgbe_free_all_rx_resources(adapter);
5699 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005700
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005701 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005702#ifdef CONFIG_DCB
5703 kfree(adapter->ixgbe_ieee_pfc);
5704 kfree(adapter->ixgbe_ieee_ets);
5705#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005706
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005707#ifdef CONFIG_PM
5708 retval = pci_save_state(pdev);
5709 if (retval)
5710 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005711
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005712#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005713 if (wufc) {
5714 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005715
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005716 /* turn on all-multi mode if wake on multicast is enabled */
5717 if (wufc & IXGBE_WUFC_MC) {
5718 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5719 fctrl |= IXGBE_FCTRL_MPE;
5720 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5721 }
5722
5723 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5724 ctrl |= IXGBE_CTRL_GIO_DIS;
5725 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5726
5727 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5728 } else {
5729 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5730 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5731 }
5732
Alexander Duyckbd508172010-11-16 19:27:03 -08005733 switch (hw->mac.type) {
5734 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005735 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005736 break;
5737 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005738 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005739 pci_wake_from_d3(pdev, !!wufc);
5740 break;
5741 default:
5742 break;
5743 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005744
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005745 *enable_wake = !!wufc;
5746
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005747 ixgbe_release_hw_control(adapter);
5748
5749 pci_disable_device(pdev);
5750
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005751 return 0;
5752}
5753
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005754#ifdef CONFIG_PM
5755static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5756{
5757 int retval;
5758 bool wake;
5759
5760 retval = __ixgbe_shutdown(pdev, &wake);
5761 if (retval)
5762 return retval;
5763
5764 if (wake) {
5765 pci_prepare_to_sleep(pdev);
5766 } else {
5767 pci_wake_from_d3(pdev, false);
5768 pci_set_power_state(pdev, PCI_D3hot);
5769 }
5770
5771 return 0;
5772}
5773#endif /* CONFIG_PM */
5774
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005775static void ixgbe_shutdown(struct pci_dev *pdev)
5776{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005777 bool wake;
5778
5779 __ixgbe_shutdown(pdev, &wake);
5780
5781 if (system_state == SYSTEM_POWER_OFF) {
5782 pci_wake_from_d3(pdev, wake);
5783 pci_set_power_state(pdev, PCI_D3hot);
5784 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005785}
5786
5787/**
Auke Kok9a799d72007-09-15 14:07:45 -07005788 * ixgbe_update_stats - Update the board statistics counters.
5789 * @adapter: board private structure
5790 **/
5791void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5792{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005793 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005794 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005795 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005796 u64 total_mpc = 0;
5797 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005798 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5799 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5800 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005801
Don Skidmored08935c2010-06-11 13:20:29 +00005802 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5803 test_bit(__IXGBE_RESETTING, &adapter->state))
5804 return;
5805
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005806 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005807 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005808 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005809 for (i = 0; i < 16; i++)
5810 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005811 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005812 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005813 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5814 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005815 }
5816 adapter->rsc_total_count = rsc_count;
5817 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005818 }
5819
Alexander Duyck5b7da512010-11-16 19:26:50 -08005820 for (i = 0; i < adapter->num_rx_queues; i++) {
5821 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5822 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5823 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5824 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5825 bytes += rx_ring->stats.bytes;
5826 packets += rx_ring->stats.packets;
5827 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005828 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005829 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5830 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5831 netdev->stats.rx_bytes = bytes;
5832 netdev->stats.rx_packets = packets;
5833
5834 bytes = 0;
5835 packets = 0;
5836 /* gather some stats to the adapter struct that are per queue */
5837 for (i = 0; i < adapter->num_tx_queues; i++) {
5838 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5839 restart_queue += tx_ring->tx_stats.restart_queue;
5840 tx_busy += tx_ring->tx_stats.tx_busy;
5841 bytes += tx_ring->stats.bytes;
5842 packets += tx_ring->stats.packets;
5843 }
5844 adapter->restart_queue = restart_queue;
5845 adapter->tx_busy = tx_busy;
5846 netdev->stats.tx_bytes = bytes;
5847 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005848
Joe Perches7ca647b2010-09-07 21:35:40 +00005849 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005850 for (i = 0; i < 8; i++) {
5851 /* for packet buffers not used, the register should read 0 */
5852 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5853 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005854 hwstats->mpc[i] += mpc;
5855 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005856 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005857 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5858 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5859 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5860 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5861 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005862 switch (hw->mac.type) {
5863 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005864 hwstats->pxonrxc[i] +=
5865 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005866 break;
5867 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005868 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005869 hwstats->pxonrxc[i] +=
5870 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005871 break;
5872 default:
5873 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005874 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005875 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5876 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005877 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005878 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005879 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005880 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005881
John Fastabendc84d3242010-11-16 19:27:12 -08005882 ixgbe_update_xoff_received(adapter);
5883
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005884 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005885 switch (hw->mac.type) {
5886 case ixgbe_mac_82598EB:
5887 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005888 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5889 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5890 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5891 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005892 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005893 /* OS2BMC stats are X540 only*/
5894 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5895 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5896 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5897 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5898 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005899 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005900 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005902 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005904 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005905 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005906 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5907 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005908#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005909 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5910 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5911 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5912 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5913 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5914 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005915#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005916 break;
5917 default:
5918 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005919 }
Auke Kok9a799d72007-09-15 14:07:45 -07005920 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005921 hwstats->bprc += bprc;
5922 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005923 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->mprc -= bprc;
5925 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5926 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5927 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5928 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5929 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5930 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5931 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5932 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005933 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005934 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005935 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005936 hwstats->lxofftxc += lxoff;
5937 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5938 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5939 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005940 /*
5941 * 82598 errata - tx of flow control packets is included in tx counters
5942 */
5943 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005944 hwstats->gptc -= xon_off_tot;
5945 hwstats->mptc -= xon_off_tot;
5946 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5947 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5948 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5949 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5950 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5951 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5952 hwstats->ptc64 -= xon_off_tot;
5953 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5954 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5955 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5956 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5957 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5958 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005959
5960 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005961 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005962
5963 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005964 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005965 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005966 netdev->stats.rx_length_errors = hwstats->rlec;
5967 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005968 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005969}
5970
5971/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005972 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5973 * @adapter - pointer to the device adapter structure
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005974 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005975static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005976{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005977 struct ixgbe_hw *hw = &adapter->hw;
5978 int i;
5979
Alexander Duyckd034acf2011-04-27 09:25:34 +00005980 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5981 return;
5982
5983 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5984
5985 /* if interface is down do nothing */
5986 if (test_bit(__IXGBE_DOWN, &adapter->state))
5987 return;
5988
5989 /* do nothing if we are not using signature filters */
5990 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5991 return;
5992
5993 adapter->fdir_overflow++;
5994
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005995 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5996 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005997 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005998 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005999 /* re-enable flow director interrupts */
6000 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006001 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006002 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006003 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006004 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006005}
6006
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006007/**
6008 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6009 * @adapter - pointer to the device adapter structure
6010 *
6011 * This function serves two purposes. First it strobes the interrupt lines
6012 * in order to make certain interrupts are occuring. Secondly it sets the
6013 * bits needed to check for TX hangs. As a result we should immediately
6014 * determine if a hang has occured.
6015 */
6016static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6017{
6018 struct ixgbe_hw *hw = &adapter->hw;
6019 u64 eics = 0;
6020 int i;
6021
6022 /* If we're down or resetting, just bail */
6023 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6024 test_bit(__IXGBE_RESETTING, &adapter->state))
6025 return;
6026
6027 /* Force detection of hung controller */
6028 if (netif_carrier_ok(adapter->netdev)) {
6029 for (i = 0; i < adapter->num_tx_queues; i++)
6030 set_check_for_tx_hang(adapter->tx_ring[i]);
6031 }
6032
6033 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6034 /*
6035 * for legacy and MSI interrupts don't set any bits
6036 * that are enabled for EIAM, because this operation
6037 * would set *both* EIMS and EICS for any bit in EIAM
6038 */
6039 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6040 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6041 } else {
6042 /* get one bit for every active tx/rx interrupt vector */
6043 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6044 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6045 if (qv->rxr_count || qv->txr_count)
6046 eics |= ((u64)1 << i);
6047 }
6048 }
6049
6050 /* Cause software interrupt to ensure rings are cleaned */
6051 ixgbe_irq_rearm_queues(adapter, eics);
6052
6053}
6054
6055/**
6056 * ixgbe_watchdog_update_link - update the link status
6057 * @adapter - pointer to the device adapter structure
6058 * @link_speed - pointer to a u32 to store the link_speed
6059 **/
6060static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
6061{
6062 struct ixgbe_hw *hw = &adapter->hw;
6063 u32 link_speed = adapter->link_speed;
6064 bool link_up = adapter->link_up;
6065 int i;
6066
6067 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6068 return;
6069
6070 if (hw->mac.ops.check_link) {
6071 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
6072 } else {
6073 /* always assume link is up, if no check link function */
6074 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6075 link_up = true;
6076 }
6077 if (link_up) {
6078 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6079 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6080 hw->mac.ops.fc_enable(hw, i);
6081 } else {
6082 hw->mac.ops.fc_enable(hw, 0);
6083 }
6084 }
6085
6086 if (link_up ||
6087 time_after(jiffies, (adapter->link_check_timeout +
6088 IXGBE_TRY_LINK_TIMEOUT))) {
6089 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6090 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6091 IXGBE_WRITE_FLUSH(hw);
6092 }
6093
6094 adapter->link_up = link_up;
6095 adapter->link_speed = link_speed;
6096}
6097
6098/**
6099 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6100 * print link up message
6101 * @adapter - pointer to the device adapter structure
6102 **/
6103static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6104{
6105 struct net_device *netdev = adapter->netdev;
6106 struct ixgbe_hw *hw = &adapter->hw;
6107 u32 link_speed = adapter->link_speed;
6108 bool flow_rx, flow_tx;
6109
6110 /* only continue if link was previously down */
6111 if (netif_carrier_ok(netdev))
6112 return;
6113
6114 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6115
6116 switch (hw->mac.type) {
6117 case ixgbe_mac_82598EB: {
6118 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6119 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6120 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6121 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6122 }
6123 break;
6124 case ixgbe_mac_X540:
6125 case ixgbe_mac_82599EB: {
6126 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6127 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6128 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6129 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6130 }
6131 break;
6132 default:
6133 flow_tx = false;
6134 flow_rx = false;
6135 break;
6136 }
6137 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6138 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6139 "10 Gbps" :
6140 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6141 "1 Gbps" :
6142 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6143 "100 Mbps" :
6144 "unknown speed"))),
6145 ((flow_rx && flow_tx) ? "RX/TX" :
6146 (flow_rx ? "RX" :
6147 (flow_tx ? "TX" : "None"))));
6148
6149 netif_carrier_on(netdev);
6150#ifdef HAVE_IPLINK_VF_CONFIG
6151 ixgbe_check_vf_rate_limit(adapter);
6152#endif /* HAVE_IPLINK_VF_CONFIG */
6153}
6154
6155/**
6156 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6157 * print link down message
6158 * @adapter - pointer to the adapter structure
6159 **/
6160static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6161{
6162 struct net_device *netdev = adapter->netdev;
6163 struct ixgbe_hw *hw = &adapter->hw;
6164
6165 adapter->link_up = false;
6166 adapter->link_speed = 0;
6167
6168 /* only continue if link was up previously */
6169 if (!netif_carrier_ok(netdev))
6170 return;
6171
6172 /* poll for SFP+ cable when link is down */
6173 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6174 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6175
6176 e_info(drv, "NIC Link is Down\n");
6177 netif_carrier_off(netdev);
6178}
6179
6180/**
6181 * ixgbe_watchdog_flush_tx - flush queues on link down
6182 * @adapter - pointer to the device adapter structure
6183 **/
6184static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6185{
6186 int i;
6187 int some_tx_pending = 0;
6188
6189 if (!netif_carrier_ok(adapter->netdev)) {
6190 for (i = 0; i < adapter->num_tx_queues; i++) {
6191 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6192 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6193 some_tx_pending = 1;
6194 break;
6195 }
6196 }
6197
6198 if (some_tx_pending) {
6199 /* We've lost link, so the controller stops DMA,
6200 * but we've got queued Tx work that's never going
6201 * to get done, so reset controller to flush Tx.
6202 * (Do the reset outside of interrupt context).
6203 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006204 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006205 }
6206 }
6207}
6208
Greg Rosea985b6c32010-11-18 03:02:52 +00006209static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6210{
6211 u32 ssvpc;
6212
6213 /* Do not perform spoof check for 82598 */
6214 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6215 return;
6216
6217 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6218
6219 /*
6220 * ssvpc register is cleared on read, if zero then no
6221 * spoofed packets in the last interval.
6222 */
6223 if (!ssvpc)
6224 return;
6225
6226 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6227}
6228
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006229/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006230 * ixgbe_watchdog_subtask - check and bring link up
6231 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006232 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006233static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006234{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006235 /* if interface is down do nothing */
6236 if (test_bit(__IXGBE_DOWN, &adapter->state))
6237 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006238
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006239 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006240
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006241 if (adapter->link_up)
6242 ixgbe_watchdog_link_is_up(adapter);
6243 else
6244 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006245
Greg Rosea985b6c32010-11-18 03:02:52 +00006246 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006247 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006248
6249 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006250}
6251
Alexander Duyck70864002011-04-27 09:13:56 +00006252/**
6253 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6254 * @adapter - the ixgbe adapter structure
6255 **/
6256static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6257{
6258 struct ixgbe_hw *hw = &adapter->hw;
6259 s32 err;
6260
6261 /* not searching for SFP so there is nothing to do here */
6262 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6263 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6264 return;
6265
6266 /* someone else is in init, wait until next service event */
6267 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6268 return;
6269
6270 err = hw->phy.ops.identify_sfp(hw);
6271 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6272 goto sfp_out;
6273
6274 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6275 /* If no cable is present, then we need to reset
6276 * the next time we find a good cable. */
6277 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6278 }
6279
6280 /* exit on error */
6281 if (err)
6282 goto sfp_out;
6283
6284 /* exit if reset not needed */
6285 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6286 goto sfp_out;
6287
6288 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6289
6290 /*
6291 * A module may be identified correctly, but the EEPROM may not have
6292 * support for that module. setup_sfp() will fail in that case, so
6293 * we should not allow that module to load.
6294 */
6295 if (hw->mac.type == ixgbe_mac_82598EB)
6296 err = hw->phy.ops.reset(hw);
6297 else
6298 err = hw->mac.ops.setup_sfp(hw);
6299
6300 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6301 goto sfp_out;
6302
6303 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6304 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6305
6306sfp_out:
6307 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6308
6309 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6310 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6311 e_dev_err("failed to initialize because an unsupported "
6312 "SFP+ module type was detected.\n");
6313 e_dev_err("Reload the driver after installing a "
6314 "supported module.\n");
6315 unregister_netdev(adapter->netdev);
6316 }
6317}
6318
6319/**
6320 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6321 * @adapter - the ixgbe adapter structure
6322 **/
6323static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6324{
6325 struct ixgbe_hw *hw = &adapter->hw;
6326 u32 autoneg;
6327 bool negotiation;
6328
6329 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6330 return;
6331
6332 /* someone else is in init, wait until next service event */
6333 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6334 return;
6335
6336 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6337
6338 autoneg = hw->phy.autoneg_advertised;
6339 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6340 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6341 hw->mac.autotry_restart = false;
6342 if (hw->mac.ops.setup_link)
6343 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6344
6345 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6346 adapter->link_check_timeout = jiffies;
6347 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6348}
6349
6350/**
6351 * ixgbe_service_timer - Timer Call-back
6352 * @data: pointer to adapter cast into an unsigned long
6353 **/
6354static void ixgbe_service_timer(unsigned long data)
6355{
6356 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6357 unsigned long next_event_offset;
6358
6359 /* poll faster when waiting for link */
6360 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6361 next_event_offset = HZ / 10;
6362 else
6363 next_event_offset = HZ * 2;
6364
6365 /* Reset the timer */
6366 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6367
6368 ixgbe_service_event_schedule(adapter);
6369}
6370
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006371static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6372{
6373 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6374 return;
6375
6376 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6377
6378 /* If we're already down or resetting, just bail */
6379 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6380 test_bit(__IXGBE_RESETTING, &adapter->state))
6381 return;
6382
6383 ixgbe_dump(adapter);
6384 netdev_err(adapter->netdev, "Reset adapter\n");
6385 adapter->tx_timeout_count++;
6386
6387 ixgbe_reinit_locked(adapter);
6388}
6389
Alexander Duyck70864002011-04-27 09:13:56 +00006390/**
6391 * ixgbe_service_task - manages and runs subtasks
6392 * @work: pointer to work_struct containing our data
6393 **/
6394static void ixgbe_service_task(struct work_struct *work)
6395{
6396 struct ixgbe_adapter *adapter = container_of(work,
6397 struct ixgbe_adapter,
6398 service_task);
6399
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006400 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006401 ixgbe_sfp_detection_subtask(adapter);
6402 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006403 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006404 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006405 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006406 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006407
6408 ixgbe_service_event_complete(adapter);
6409}
6410
Auke Kok9a799d72007-09-15 14:07:45 -07006411static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006412 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006413 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006414{
6415 struct ixgbe_adv_tx_context_desc *context_desc;
6416 unsigned int i;
6417 int err;
6418 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006419 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6420 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006421
6422 if (skb_is_gso(skb)) {
6423 if (skb_header_cloned(skb)) {
6424 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6425 if (err)
6426 return err;
6427 }
6428 l4len = tcp_hdrlen(skb);
6429 *hdr_len += l4len;
6430
Hao Zheng5e09a102010-11-11 13:47:59 +00006431 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006432 struct iphdr *iph = ip_hdr(skb);
6433 iph->tot_len = 0;
6434 iph->check = 0;
6435 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006436 iph->daddr, 0,
6437 IPPROTO_TCP,
6438 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006439 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006440 ipv6_hdr(skb)->payload_len = 0;
6441 tcp_hdr(skb)->check =
6442 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006443 &ipv6_hdr(skb)->daddr,
6444 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006445 }
6446
6447 i = tx_ring->next_to_use;
6448
6449 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006450 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006451
6452 /* VLAN MACLEN IPLEN */
6453 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6454 vlan_macip_lens |=
6455 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6456 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006457 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006458 *hdr_len += skb_network_offset(skb);
6459 vlan_macip_lens |=
6460 (skb_transport_header(skb) - skb_network_header(skb));
6461 *hdr_len +=
6462 (skb_transport_header(skb) - skb_network_header(skb));
6463 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6464 context_desc->seqnum_seed = 0;
6465
6466 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006467 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006468 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006469
Hao Zheng5e09a102010-11-11 13:47:59 +00006470 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006471 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6472 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6473 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6474
6475 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006476 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006477 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6478 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006479 /* use index 1 for TSO */
6480 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006481 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6482
6483 tx_buffer_info->time_stamp = jiffies;
6484 tx_buffer_info->next_to_watch = i;
6485
6486 i++;
6487 if (i == tx_ring->count)
6488 i = 0;
6489 tx_ring->next_to_use = i;
6490
6491 return true;
6492 }
6493 return false;
6494}
6495
Hao Zheng5e09a102010-11-11 13:47:59 +00006496static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6497 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006498{
6499 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006500
6501 switch (protocol) {
6502 case cpu_to_be16(ETH_P_IP):
6503 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6504 switch (ip_hdr(skb)->protocol) {
6505 case IPPROTO_TCP:
6506 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6507 break;
6508 case IPPROTO_SCTP:
6509 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6510 break;
6511 }
6512 break;
6513 case cpu_to_be16(ETH_P_IPV6):
6514 /* XXX what about other V6 headers?? */
6515 switch (ipv6_hdr(skb)->nexthdr) {
6516 case IPPROTO_TCP:
6517 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6518 break;
6519 case IPPROTO_SCTP:
6520 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6521 break;
6522 }
6523 break;
6524 default:
6525 if (unlikely(net_ratelimit()))
6526 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006527 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006528 break;
6529 }
6530
6531 return rtn;
6532}
6533
Auke Kok9a799d72007-09-15 14:07:45 -07006534static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006535 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006536 struct sk_buff *skb, u32 tx_flags,
6537 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006538{
6539 struct ixgbe_adv_tx_context_desc *context_desc;
6540 unsigned int i;
6541 struct ixgbe_tx_buffer *tx_buffer_info;
6542 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6543
6544 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6545 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6546 i = tx_ring->next_to_use;
6547 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006548 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006549
6550 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6551 vlan_macip_lens |=
6552 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6553 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006554 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006555 if (skb->ip_summed == CHECKSUM_PARTIAL)
6556 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006557 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006558
6559 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6560 context_desc->seqnum_seed = 0;
6561
6562 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006563 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006564
Joe Perches7ca647b2010-09-07 21:35:40 +00006565 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006566 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006567
6568 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006569 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006570 context_desc->mss_l4len_idx = 0;
6571
6572 tx_buffer_info->time_stamp = jiffies;
6573 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006574
Auke Kok9a799d72007-09-15 14:07:45 -07006575 i++;
6576 if (i == tx_ring->count)
6577 i = 0;
6578 tx_ring->next_to_use = i;
6579
6580 return true;
6581 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006582
Auke Kok9a799d72007-09-15 14:07:45 -07006583 return false;
6584}
6585
6586static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006587 struct ixgbe_ring *tx_ring,
6588 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006589 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006590{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006591 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006592 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006593 unsigned int len;
6594 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006595 unsigned int offset = 0, size, count = 0, i;
6596 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6597 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006598 unsigned int bytecount = skb->len;
6599 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006600
6601 i = tx_ring->next_to_use;
6602
Yi Zoueacd73f2009-05-13 13:11:06 +00006603 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6604 /* excluding fcoe_crc_eof for FCoE */
6605 total -= sizeof(struct fcoe_crc_eof);
6606
6607 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006608 while (len) {
6609 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6610 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6611
6612 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006613 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006614 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006615 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006616 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006617 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006618 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006619 tx_buffer_info->time_stamp = jiffies;
6620 tx_buffer_info->next_to_watch = i;
6621
6622 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006623 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006624 offset += size;
6625 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006626
6627 if (len) {
6628 i++;
6629 if (i == tx_ring->count)
6630 i = 0;
6631 }
Auke Kok9a799d72007-09-15 14:07:45 -07006632 }
6633
6634 for (f = 0; f < nr_frags; f++) {
6635 struct skb_frag_struct *frag;
6636
6637 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006638 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006639 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006640
6641 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006642 i++;
6643 if (i == tx_ring->count)
6644 i = 0;
6645
Auke Kok9a799d72007-09-15 14:07:45 -07006646 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6647 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6648
6649 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006650 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006651 frag->page,
6652 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006653 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006654 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006655 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006656 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006657 tx_buffer_info->time_stamp = jiffies;
6658 tx_buffer_info->next_to_watch = i;
6659
6660 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006661 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006662 offset += size;
6663 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006664 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006665 if (total == 0)
6666 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006667 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006668
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006669 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6670 gso_segs = skb_shinfo(skb)->gso_segs;
6671#ifdef IXGBE_FCOE
6672 /* adjust for FCoE Sequence Offload */
6673 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6674 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6675 skb_shinfo(skb)->gso_size);
6676#endif /* IXGBE_FCOE */
6677 bytecount += (gso_segs - 1) * hdr_len;
6678
6679 /* multiply data chunks by size of headers */
6680 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6681 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006682 tx_ring->tx_buffer_info[i].skb = skb;
6683 tx_ring->tx_buffer_info[first].next_to_watch = i;
6684
6685 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006686
6687dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006688 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006689
6690 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6691 tx_buffer_info->dma = 0;
6692 tx_buffer_info->time_stamp = 0;
6693 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006694 if (count)
6695 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006696
6697 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006698 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006699 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006700 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006701 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006702 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006703 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006704 }
6705
Anton Blancharde44d38e2010-02-03 13:12:51 +00006706 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006707}
6708
Alexander Duyck84ea2592010-11-16 19:26:49 -08006709static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006710 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006711{
6712 union ixgbe_adv_tx_desc *tx_desc = NULL;
6713 struct ixgbe_tx_buffer *tx_buffer_info;
6714 u32 olinfo_status = 0, cmd_type_len = 0;
6715 unsigned int i;
6716 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6717
6718 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6719
6720 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6721
6722 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6723 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6724
6725 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6726 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6727
6728 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006729 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006730
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006731 /* use index 1 context for tso */
6732 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006733 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6734 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006735 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006736
6737 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6738 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006739 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006740
Yi Zoueacd73f2009-05-13 13:11:06 +00006741 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6742 olinfo_status |= IXGBE_ADVTXD_CC;
6743 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6744 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6745 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6746 }
6747
Auke Kok9a799d72007-09-15 14:07:45 -07006748 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6749
6750 i = tx_ring->next_to_use;
6751 while (count--) {
6752 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006753 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006754 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6755 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006756 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006757 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006758 i++;
6759 if (i == tx_ring->count)
6760 i = 0;
6761 }
6762
6763 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6764
6765 /*
6766 * Force memory writes to complete before letting h/w
6767 * know there are new descriptors to fetch. (Only
6768 * applicable for weak-ordered memory model archs,
6769 * such as IA-64).
6770 */
6771 wmb();
6772
6773 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006774 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006775}
6776
Alexander Duyck69830522011-01-06 14:29:58 +00006777static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6778 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006779{
Alexander Duyck69830522011-01-06 14:29:58 +00006780 struct ixgbe_q_vector *q_vector = ring->q_vector;
6781 union ixgbe_atr_hash_dword input = { .dword = 0 };
6782 union ixgbe_atr_hash_dword common = { .dword = 0 };
6783 union {
6784 unsigned char *network;
6785 struct iphdr *ipv4;
6786 struct ipv6hdr *ipv6;
6787 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006788 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006789 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006790
Alexander Duyck69830522011-01-06 14:29:58 +00006791 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6792 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006793 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006794
Alexander Duyck69830522011-01-06 14:29:58 +00006795 /* do nothing if sampling is disabled */
6796 if (!ring->atr_sample_rate)
6797 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006798
Alexander Duyck69830522011-01-06 14:29:58 +00006799 ring->atr_count++;
6800
6801 /* snag network header to get L4 type and address */
6802 hdr.network = skb_network_header(skb);
6803
6804 /* Currently only IPv4/IPv6 with TCP is supported */
6805 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6806 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6807 (protocol != __constant_htons(ETH_P_IP) ||
6808 hdr.ipv4->protocol != IPPROTO_TCP))
6809 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006810
6811 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006812
Alexander Duyck69830522011-01-06 14:29:58 +00006813 /* skip this packet since the socket is closing */
6814 if (th->fin)
6815 return;
6816
6817 /* sample on all syn packets or once every atr sample count */
6818 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6819 return;
6820
6821 /* reset sample count */
6822 ring->atr_count = 0;
6823
6824 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6825
6826 /*
6827 * src and dst are inverted, think how the receiver sees them
6828 *
6829 * The input is broken into two sections, a non-compressed section
6830 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6831 * is XORed together and stored in the compressed dword.
6832 */
6833 input.formatted.vlan_id = vlan_id;
6834
6835 /*
6836 * since src port and flex bytes occupy the same word XOR them together
6837 * and write the value to source port portion of compressed dword
6838 */
6839 if (vlan_id)
6840 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6841 else
6842 common.port.src ^= th->dest ^ protocol;
6843 common.port.dst ^= th->source;
6844
6845 if (protocol == __constant_htons(ETH_P_IP)) {
6846 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6847 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6848 } else {
6849 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6850 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6851 hdr.ipv6->saddr.s6_addr32[1] ^
6852 hdr.ipv6->saddr.s6_addr32[2] ^
6853 hdr.ipv6->saddr.s6_addr32[3] ^
6854 hdr.ipv6->daddr.s6_addr32[0] ^
6855 hdr.ipv6->daddr.s6_addr32[1] ^
6856 hdr.ipv6->daddr.s6_addr32[2] ^
6857 hdr.ipv6->daddr.s6_addr32[3];
6858 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006859
6860 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006861 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6862 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006863}
6864
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006865static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006866{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006867 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006868 /* Herbert's original patch had:
6869 * smp_mb__after_netif_stop_queue();
6870 * but since that doesn't exist yet, just open code it. */
6871 smp_mb();
6872
6873 /* We need to check again in a case another CPU has just
6874 * made room available. */
6875 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6876 return -EBUSY;
6877
6878 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006879 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006880 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006881 return 0;
6882}
6883
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006884static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006885{
6886 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6887 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006888 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006889}
6890
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006891static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6892{
6893 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006894 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006895#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006896 __be16 protocol;
6897
6898 protocol = vlan_get_protocol(skb);
6899
John Fastabende5b64632011-03-08 03:44:52 +00006900 if (((protocol == htons(ETH_P_FCOE)) ||
6901 (protocol == htons(ETH_P_FIP))) &&
6902 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6903 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6904 txq += adapter->ring_feature[RING_F_FCOE].mask;
6905 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006906 }
6907#endif
6908
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006909 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6910 while (unlikely(txq >= dev->real_num_tx_queues))
6911 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006912 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006913 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006914
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006915 return skb_tx_hash(dev, skb);
6916}
6917
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006918netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006919 struct ixgbe_adapter *adapter,
6920 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006921{
Auke Kok9a799d72007-09-15 14:07:45 -07006922 unsigned int first;
6923 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006924 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006925 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006926 int count = 0;
6927 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006928 __be16 protocol;
6929
6930 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006931
Jesse Grosseab6d182010-10-20 13:56:03 +00006932 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006933 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006934 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6935 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006936 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006937 }
6938 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6939 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006940 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6941 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006942 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006943 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6944 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006945 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006946
Yi Zou09ad1cc2009-09-03 14:56:10 +00006947#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006948 /* for FCoE with DCB, we force the priority to what
6949 * was specified by the switch */
6950 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006951 (protocol == htons(ETH_P_FCOE)))
6952 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006953#endif
6954
Yi Zoueacd73f2009-05-13 13:11:06 +00006955 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006956 if (skb_is_gso(skb) ||
6957 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006958 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6959 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006960 count++;
6961
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006962 count += TXD_USE_COUNT(skb_headlen(skb));
6963 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006964 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6965
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006966 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006967 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006968 return NETDEV_TX_BUSY;
6969 }
Auke Kok9a799d72007-09-15 14:07:45 -07006970
Auke Kok9a799d72007-09-15 14:07:45 -07006971 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006972 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6973#ifdef IXGBE_FCOE
6974 /* setup tx offload for FCoE */
6975 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6976 if (tso < 0) {
6977 dev_kfree_skb_any(skb);
6978 return NETDEV_TX_OK;
6979 }
6980 if (tso)
6981 tx_flags |= IXGBE_TX_FLAGS_FSO;
6982#endif /* IXGBE_FCOE */
6983 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006984 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006985 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006986 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6987 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006988 if (tso < 0) {
6989 dev_kfree_skb_any(skb);
6990 return NETDEV_TX_OK;
6991 }
6992
6993 if (tso)
6994 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006995 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6996 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006997 (skb->ip_summed == CHECKSUM_PARTIAL))
6998 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006999 }
7000
Alexander Duyck8ad494b2010-11-16 19:26:47 -08007001 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007002 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007003 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00007004 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7005 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08007006 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007007 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007008
Alexander Duyck44df32c2009-03-31 21:34:23 +00007009 } else {
7010 dev_kfree_skb_any(skb);
7011 tx_ring->tx_buffer_info[first].time_stamp = 0;
7012 tx_ring->next_to_use = first;
7013 }
Auke Kok9a799d72007-09-15 14:07:45 -07007014
7015 return NETDEV_TX_OK;
7016}
7017
Alexander Duyck84418e32010-08-19 13:40:54 +00007018static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7019{
7020 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7021 struct ixgbe_ring *tx_ring;
7022
7023 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007024 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00007025}
7026
Auke Kok9a799d72007-09-15 14:07:45 -07007027/**
Auke Kok9a799d72007-09-15 14:07:45 -07007028 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7029 * @netdev: network interface device structure
7030 * @p: pointer to an address structure
7031 *
7032 * Returns 0 on success, negative on failure
7033 **/
7034static int ixgbe_set_mac(struct net_device *netdev, void *p)
7035{
7036 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007037 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07007038 struct sockaddr *addr = p;
7039
7040 if (!is_valid_ether_addr(addr->sa_data))
7041 return -EADDRNOTAVAIL;
7042
7043 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007044 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007045
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007046 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7047 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07007048
7049 return 0;
7050}
7051
Ben Hutchings6b73e102009-04-29 08:08:58 +00007052static int
7053ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7054{
7055 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7056 struct ixgbe_hw *hw = &adapter->hw;
7057 u16 value;
7058 int rc;
7059
7060 if (prtad != hw->phy.mdio.prtad)
7061 return -EINVAL;
7062 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7063 if (!rc)
7064 rc = value;
7065 return rc;
7066}
7067
7068static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7069 u16 addr, u16 value)
7070{
7071 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7072 struct ixgbe_hw *hw = &adapter->hw;
7073
7074 if (prtad != hw->phy.mdio.prtad)
7075 return -EINVAL;
7076 return hw->phy.ops.write_reg(hw, addr, devad, value);
7077}
7078
7079static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7080{
7081 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7082
7083 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7084}
7085
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007086/**
7087 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007088 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007089 * @netdev: network interface device structure
7090 *
7091 * Returns non-zero on failure
7092 **/
7093static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7094{
7095 int err = 0;
7096 struct ixgbe_adapter *adapter = netdev_priv(dev);
7097 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7098
7099 if (is_valid_ether_addr(mac->san_addr)) {
7100 rtnl_lock();
7101 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7102 rtnl_unlock();
7103 }
7104 return err;
7105}
7106
7107/**
7108 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007109 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007110 * @netdev: network interface device structure
7111 *
7112 * Returns non-zero on failure
7113 **/
7114static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7115{
7116 int err = 0;
7117 struct ixgbe_adapter *adapter = netdev_priv(dev);
7118 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7119
7120 if (is_valid_ether_addr(mac->san_addr)) {
7121 rtnl_lock();
7122 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7123 rtnl_unlock();
7124 }
7125 return err;
7126}
7127
Auke Kok9a799d72007-09-15 14:07:45 -07007128#ifdef CONFIG_NET_POLL_CONTROLLER
7129/*
7130 * Polling 'interrupt' - used by things like netconsole to send skbs
7131 * without having to re-enable interrupts. It's not called while
7132 * the interrupt routine is executing.
7133 */
7134static void ixgbe_netpoll(struct net_device *netdev)
7135{
7136 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007137 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007138
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007139 /* if interface is down do nothing */
7140 if (test_bit(__IXGBE_DOWN, &adapter->state))
7141 return;
7142
Auke Kok9a799d72007-09-15 14:07:45 -07007143 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007144 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7145 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7146 for (i = 0; i < num_q_vectors; i++) {
7147 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7148 ixgbe_msix_clean_many(0, q_vector);
7149 }
7150 } else {
7151 ixgbe_intr(adapter->pdev->irq, netdev);
7152 }
Auke Kok9a799d72007-09-15 14:07:45 -07007153 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007154}
7155#endif
7156
Eric Dumazetde1036b2010-10-20 23:00:04 +00007157static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7158 struct rtnl_link_stats64 *stats)
7159{
7160 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7161 int i;
7162
Eric Dumazet1a515022010-11-16 19:26:42 -08007163 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007164 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007165 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007166 u64 bytes, packets;
7167 unsigned int start;
7168
Eric Dumazet1a515022010-11-16 19:26:42 -08007169 if (ring) {
7170 do {
7171 start = u64_stats_fetch_begin_bh(&ring->syncp);
7172 packets = ring->stats.packets;
7173 bytes = ring->stats.bytes;
7174 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7175 stats->rx_packets += packets;
7176 stats->rx_bytes += bytes;
7177 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007178 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007179
7180 for (i = 0; i < adapter->num_tx_queues; i++) {
7181 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7182 u64 bytes, packets;
7183 unsigned int start;
7184
7185 if (ring) {
7186 do {
7187 start = u64_stats_fetch_begin_bh(&ring->syncp);
7188 packets = ring->stats.packets;
7189 bytes = ring->stats.bytes;
7190 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7191 stats->tx_packets += packets;
7192 stats->tx_bytes += bytes;
7193 }
7194 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007195 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007196 /* following stats updated by ixgbe_watchdog_task() */
7197 stats->multicast = netdev->stats.multicast;
7198 stats->rx_errors = netdev->stats.rx_errors;
7199 stats->rx_length_errors = netdev->stats.rx_length_errors;
7200 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7201 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7202 return stats;
7203}
7204
7205
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007206static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007207 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007208 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007209 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007210 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007211 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007212 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7213 .ndo_validate_addr = eth_validate_addr,
7214 .ndo_set_mac_address = ixgbe_set_mac,
7215 .ndo_change_mtu = ixgbe_change_mtu,
7216 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007217 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7218 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007219 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007220 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7221 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7222 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7223 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007224 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007225#ifdef CONFIG_IXGBE_DCB
7226 .ndo_setup_tc = ixgbe_setup_tc,
7227#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007228#ifdef CONFIG_NET_POLL_CONTROLLER
7229 .ndo_poll_controller = ixgbe_netpoll,
7230#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007231#ifdef IXGBE_FCOE
7232 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007233 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007234 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007235 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7236 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007237 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007238#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007239};
7240
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007241static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7242 const struct ixgbe_info *ii)
7243{
7244#ifdef CONFIG_PCI_IOV
7245 struct ixgbe_hw *hw = &adapter->hw;
7246 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007247 int num_vf_macvlans, i;
7248 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007249
Greg Rose3377eba792010-12-07 08:16:45 +00007250 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007251 return;
7252
7253 /* The 82599 supports up to 64 VFs per physical function
7254 * but this implementation limits allocation to 63 so that
7255 * basic networking resources are still available to the
7256 * physical function
7257 */
7258 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7259 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7260 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7261 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007262 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007263 goto err_novfs;
7264 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007265
7266 num_vf_macvlans = hw->mac.num_rar_entries -
7267 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7268
7269 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7270 sizeof(struct vf_macvlans),
7271 GFP_KERNEL);
7272 if (mv_list) {
7273 /* Initialize list of VF macvlans */
7274 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7275 for (i = 0; i < num_vf_macvlans; i++) {
7276 mv_list->vf = -1;
7277 mv_list->free = true;
7278 mv_list->rar_entry = hw->mac.num_rar_entries -
7279 (i + adapter->num_vfs + 1);
7280 list_add(&mv_list->l, &adapter->vf_mvs.l);
7281 mv_list++;
7282 }
7283 }
7284
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007285 /* If call to enable VFs succeeded then allocate memory
7286 * for per VF control structures.
7287 */
7288 adapter->vfinfo =
7289 kcalloc(adapter->num_vfs,
7290 sizeof(struct vf_data_storage), GFP_KERNEL);
7291 if (adapter->vfinfo) {
7292 /* Now that we're sure SR-IOV is enabled
7293 * and memory allocated set up the mailbox parameters
7294 */
7295 ixgbe_init_mbx_params_pf(hw);
7296 memcpy(&hw->mbx.ops, ii->mbx_ops,
7297 sizeof(hw->mbx.ops));
7298
7299 /* Disable RSC when in SR-IOV mode */
7300 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7301 IXGBE_FLAG2_RSC_ENABLED);
7302 return;
7303 }
7304
7305 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007306 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7307 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007308 pci_disable_sriov(adapter->pdev);
7309
7310err_novfs:
7311 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7312 adapter->num_vfs = 0;
7313#endif /* CONFIG_PCI_IOV */
7314}
7315
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007316/**
Auke Kok9a799d72007-09-15 14:07:45 -07007317 * ixgbe_probe - Device Initialization Routine
7318 * @pdev: PCI device information struct
7319 * @ent: entry in ixgbe_pci_tbl
7320 *
7321 * Returns 0 on success, negative on failure
7322 *
7323 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7324 * The OS initialization, configuring of the adapter private structure,
7325 * and a hardware reset occur.
7326 **/
7327static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007328 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007329{
7330 struct net_device *netdev;
7331 struct ixgbe_adapter *adapter = NULL;
7332 struct ixgbe_hw *hw;
7333 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007334 static int cards_found;
7335 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007336 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007337 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007338#ifdef IXGBE_FCOE
7339 u16 device_caps;
7340#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007341 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007342
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007343 /* Catch broken hardware that put the wrong VF device ID in
7344 * the PCIe SR-IOV capability.
7345 */
7346 if (pdev->is_virtfn) {
7347 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7348 pci_name(pdev), pdev->vendor, pdev->device);
7349 return -EINVAL;
7350 }
7351
gouji-new9ce77662009-05-06 10:44:45 +00007352 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007353 if (err)
7354 return err;
7355
Nick Nunley1b507732010-04-27 13:10:27 +00007356 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7357 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007358 pci_using_dac = 1;
7359 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007360 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007361 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007362 err = dma_set_coherent_mask(&pdev->dev,
7363 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007364 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007365 dev_err(&pdev->dev,
7366 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007367 goto err_dma;
7368 }
7369 }
7370 pci_using_dac = 0;
7371 }
7372
gouji-new9ce77662009-05-06 10:44:45 +00007373 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007374 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007375 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007376 dev_err(&pdev->dev,
7377 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007378 goto err_pci_reg;
7379 }
7380
Frans Pop19d5afd2009-10-02 10:04:12 -07007381 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007382
Auke Kok9a799d72007-09-15 14:07:45 -07007383 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007384 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007385
John Fastabendc85a2612010-02-25 23:15:21 +00007386 if (ii->mac == ixgbe_mac_82598EB)
7387 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7388 else
7389 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7390
John Fastabende5b64632011-03-08 03:44:52 +00007391#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007392 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007393#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007394 indices += min_t(unsigned int, num_possible_cpus(),
7395 IXGBE_MAX_FCOE_INDICES);
7396#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007397 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007398 if (!netdev) {
7399 err = -ENOMEM;
7400 goto err_alloc_etherdev;
7401 }
7402
Auke Kok9a799d72007-09-15 14:07:45 -07007403 SET_NETDEV_DEV(netdev, &pdev->dev);
7404
Auke Kok9a799d72007-09-15 14:07:45 -07007405 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007406 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007407
7408 adapter->netdev = netdev;
7409 adapter->pdev = pdev;
7410 hw = &adapter->hw;
7411 hw->back = adapter;
7412 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7413
Jeff Kirsher05857982008-09-11 19:57:00 -07007414 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007415 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007416 if (!hw->hw_addr) {
7417 err = -EIO;
7418 goto err_ioremap;
7419 }
7420
7421 for (i = 1; i <= 5; i++) {
7422 if (pci_resource_len(pdev, i) == 0)
7423 continue;
7424 }
7425
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007426 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007427 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007428 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007429 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007430
Auke Kok9a799d72007-09-15 14:07:45 -07007431 adapter->bd_number = cards_found;
7432
Auke Kok9a799d72007-09-15 14:07:45 -07007433 /* Setup hw api */
7434 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007435 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007436
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007437 /* EEPROM */
7438 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7439 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7440 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7441 if (!(eec & (1 << 8)))
7442 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7443
7444 /* PHY */
7445 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007446 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007447 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7448 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7449 hw->phy.mdio.mmds = 0;
7450 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7451 hw->phy.mdio.dev = netdev;
7452 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7453 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007454
Don Skidmore8ca783a2009-05-26 20:40:47 -07007455 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007456
7457 /* setup the private structure */
7458 err = ixgbe_sw_init(adapter);
7459 if (err)
7460 goto err_sw_init;
7461
Don Skidmoree86bff02010-02-11 04:14:08 +00007462 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007463 switch (adapter->hw.mac.type) {
7464 case ixgbe_mac_82599EB:
7465 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007466 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007467 break;
7468 default:
7469 break;
7470 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007471
Don Skidmorebf069c92009-05-07 10:39:54 +00007472 /*
7473 * If there is a fan on this device and it has failed log the
7474 * failure.
7475 */
7476 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7477 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7478 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007479 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007480 }
7481
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007482 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007483 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007484 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007485 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007486 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7487 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007488 err = 0;
7489 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007490 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007491 "module type was detected.\n");
7492 e_dev_err("Reload the driver after installing a supported "
7493 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007494 goto err_sw_init;
7495 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007496 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007497 goto err_sw_init;
7498 }
7499
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007500 ixgbe_probe_vf(adapter, ii);
7501
Emil Tantilov396e7992010-07-01 20:05:12 +00007502 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007503 NETIF_F_IP_CSUM |
7504 NETIF_F_HW_VLAN_TX |
7505 NETIF_F_HW_VLAN_RX |
7506 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007507
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007508 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007509 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007510 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007511 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007512 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007513
Don Skidmore58be7662011-04-12 09:42:11 +00007514 switch (adapter->hw.mac.type) {
7515 case ixgbe_mac_82599EB:
7516 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007517 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007518 break;
7519 default:
7520 break;
7521 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007522
Jeff Kirsherad31c402008-06-05 04:05:30 -07007523 netdev->vlan_features |= NETIF_F_TSO;
7524 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007525 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007526 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007527 netdev->vlan_features |= NETIF_F_SG;
7528
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007529 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7530 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7531 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007532
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007533#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007534 netdev->dcbnl_ops = &dcbnl_ops;
7535#endif
7536
Yi Zoueacd73f2009-05-13 13:11:06 +00007537#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007538 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007539 if (hw->mac.ops.get_device_caps) {
7540 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007541 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7542 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007543 }
7544 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007545 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7546 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7547 netdev->vlan_features |= NETIF_F_FSO;
7548 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7549 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007550#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007551 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007552 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007553 netdev->vlan_features |= NETIF_F_HIGHDMA;
7554 }
Auke Kok9a799d72007-09-15 14:07:45 -07007555
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007556 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007557 netdev->features |= NETIF_F_LRO;
7558
Auke Kok9a799d72007-09-15 14:07:45 -07007559 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007560 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007561 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007562 err = -EIO;
7563 goto err_eeprom;
7564 }
7565
7566 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7567 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7568
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007569 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007570 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007571 err = -EIO;
7572 goto err_eeprom;
7573 }
7574
Don Skidmorec6ecf392010-12-03 03:31:51 +00007575 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7576 if (hw->mac.ops.disable_tx_laser &&
7577 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007578 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007579 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007580 hw->mac.ops.disable_tx_laser(hw);
7581
Alexander Duyck70864002011-04-27 09:13:56 +00007582 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7583 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007584
Alexander Duyck70864002011-04-27 09:13:56 +00007585 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7586 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7587
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007588 err = ixgbe_init_interrupt_scheme(adapter);
7589 if (err)
7590 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007591
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007592 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7593 netdev->features &= ~NETIF_F_RXHASH;
7594
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007595 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007596 case IXGBE_DEV_ID_82599_SFP:
7597 /* Only this subdevice supports WOL */
7598 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7599 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7600 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7601 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007602 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7603 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007604 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7605 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7606 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7607 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007608 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007609 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007610 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007611 break;
7612 default:
7613 adapter->wol = 0;
7614 break;
7615 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007616 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7617
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007618 /* pick up the PCI bus settings for reporting later */
7619 hw->mac.ops.get_bus_info(hw);
7620
Auke Kok9a799d72007-09-15 14:07:45 -07007621 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007622 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007623 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7624 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007625 "Unknown"),
7626 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7627 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7628 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7629 "Unknown"),
7630 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007631
7632 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7633 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007634 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007635 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007636 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007637 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007638 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007639 else
Don Skidmore289700db2010-12-03 03:32:58 +00007640 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7641 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007642
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007643 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007644 e_dev_warn("PCI-Express bandwidth available for this card is "
7645 "not sufficient for optimal performance.\n");
7646 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7647 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007648 }
7649
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007650 /* save off EEPROM version number */
7651 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7652
Auke Kok9a799d72007-09-15 14:07:45 -07007653 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007654 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007655
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007656 if (err == IXGBE_ERR_EEPROM_VERSION) {
7657 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007658 e_dev_warn("This device is a pre-production adapter/LOM. "
7659 "Please be aware there may be issues associated "
7660 "with your hardware. If you are experiencing "
7661 "problems please contact your Intel or hardware "
7662 "representative who provided you with this "
7663 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007664 }
Auke Kok9a799d72007-09-15 14:07:45 -07007665 strcpy(netdev->name, "eth%d");
7666 err = register_netdev(netdev);
7667 if (err)
7668 goto err_register;
7669
Jesse Brandeburg54386462009-04-17 20:44:27 +00007670 /* carrier off reporting is important to ethtool even BEFORE open */
7671 netif_carrier_off(netdev);
7672
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007673#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007674 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007675 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007676 ixgbe_setup_dca(adapter);
7677 }
7678#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007679 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007680 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007681 for (i = 0; i < adapter->num_vfs; i++)
7682 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7683 }
7684
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007685 /* add san mac addr to netdev */
7686 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007687
Emil Tantilov849c4542010-06-03 16:53:41 +00007688 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007689 cards_found++;
7690 return 0;
7691
7692err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007693 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007694 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007695err_sw_init:
7696err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007697 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7698 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007699 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007700 iounmap(hw->hw_addr);
7701err_ioremap:
7702 free_netdev(netdev);
7703err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007704 pci_release_selected_regions(pdev,
7705 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007706err_pci_reg:
7707err_dma:
7708 pci_disable_device(pdev);
7709 return err;
7710}
7711
7712/**
7713 * ixgbe_remove - Device Removal Routine
7714 * @pdev: PCI device information struct
7715 *
7716 * ixgbe_remove is called by the PCI subsystem to alert the driver
7717 * that it should release a PCI device. The could be caused by a
7718 * Hot-Plug event, or because the driver is going to be removed from
7719 * memory.
7720 **/
7721static void __devexit ixgbe_remove(struct pci_dev *pdev)
7722{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007723 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7724 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007725
7726 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007727 cancel_work_sync(&adapter->service_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007728
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007729#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007730 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7731 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7732 dca_remove_requester(&pdev->dev);
7733 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7734 }
7735
7736#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007737#ifdef IXGBE_FCOE
7738 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7739 ixgbe_cleanup_fcoe(adapter);
7740
7741#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007742
7743 /* remove the added san mac */
7744 ixgbe_del_sanmac_netdev(netdev);
7745
Donald Skidmorec4900be2008-11-20 21:11:42 -08007746 if (netdev->reg_state == NETREG_REGISTERED)
7747 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007748
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007749 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7750 ixgbe_disable_sriov(adapter);
7751
Alexander Duyck7a921c92009-05-06 10:43:28 +00007752 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007753
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007754 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007755
7756 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007757 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007758 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007759
Emil Tantilov849c4542010-06-03 16:53:41 +00007760 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007761
Auke Kok9a799d72007-09-15 14:07:45 -07007762 free_netdev(netdev);
7763
Frans Pop19d5afd2009-10-02 10:04:12 -07007764 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007765
Auke Kok9a799d72007-09-15 14:07:45 -07007766 pci_disable_device(pdev);
7767}
7768
7769/**
7770 * ixgbe_io_error_detected - called when PCI error is detected
7771 * @pdev: Pointer to PCI device
7772 * @state: The current pci connection state
7773 *
7774 * This function is called after a PCI bus error affecting
7775 * this device has been detected.
7776 */
7777static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007778 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007779{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007780 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7781 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007782
7783 netif_device_detach(netdev);
7784
Breno Leitao3044b8d2009-05-06 10:44:26 +00007785 if (state == pci_channel_io_perm_failure)
7786 return PCI_ERS_RESULT_DISCONNECT;
7787
Auke Kok9a799d72007-09-15 14:07:45 -07007788 if (netif_running(netdev))
7789 ixgbe_down(adapter);
7790 pci_disable_device(pdev);
7791
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007792 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007793 return PCI_ERS_RESULT_NEED_RESET;
7794}
7795
7796/**
7797 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7798 * @pdev: Pointer to PCI device
7799 *
7800 * Restart the card from scratch, as if from a cold-boot.
7801 */
7802static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7803{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007804 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007805 pci_ers_result_t result;
7806 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007807
gouji-new9ce77662009-05-06 10:44:45 +00007808 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007809 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007810 result = PCI_ERS_RESULT_DISCONNECT;
7811 } else {
7812 pci_set_master(pdev);
7813 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007814 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007815
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007816 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007817
7818 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007819 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007820 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007821 }
Auke Kok9a799d72007-09-15 14:07:45 -07007822
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007823 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7824 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007825 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7826 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007827 /* non-fatal, continue */
7828 }
Auke Kok9a799d72007-09-15 14:07:45 -07007829
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007830 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007831}
7832
7833/**
7834 * ixgbe_io_resume - called when traffic can start flowing again.
7835 * @pdev: Pointer to PCI device
7836 *
7837 * This callback is called when the error recovery driver tells us that
7838 * its OK to resume normal operation.
7839 */
7840static void ixgbe_io_resume(struct pci_dev *pdev)
7841{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007842 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7843 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007844
7845 if (netif_running(netdev)) {
7846 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007847 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007848 return;
7849 }
7850 }
7851
7852 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007853}
7854
7855static struct pci_error_handlers ixgbe_err_handler = {
7856 .error_detected = ixgbe_io_error_detected,
7857 .slot_reset = ixgbe_io_slot_reset,
7858 .resume = ixgbe_io_resume,
7859};
7860
7861static struct pci_driver ixgbe_driver = {
7862 .name = ixgbe_driver_name,
7863 .id_table = ixgbe_pci_tbl,
7864 .probe = ixgbe_probe,
7865 .remove = __devexit_p(ixgbe_remove),
7866#ifdef CONFIG_PM
7867 .suspend = ixgbe_suspend,
7868 .resume = ixgbe_resume,
7869#endif
7870 .shutdown = ixgbe_shutdown,
7871 .err_handler = &ixgbe_err_handler
7872};
7873
7874/**
7875 * ixgbe_init_module - Driver Registration Routine
7876 *
7877 * ixgbe_init_module is the first routine called when the driver is
7878 * loaded. All it does is register with the PCI subsystem.
7879 **/
7880static int __init ixgbe_init_module(void)
7881{
7882 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007883 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007884 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007885
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007886#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007887 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007888#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007889
Auke Kok9a799d72007-09-15 14:07:45 -07007890 ret = pci_register_driver(&ixgbe_driver);
7891 return ret;
7892}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007893
Auke Kok9a799d72007-09-15 14:07:45 -07007894module_init(ixgbe_init_module);
7895
7896/**
7897 * ixgbe_exit_module - Driver Exit Cleanup Routine
7898 *
7899 * ixgbe_exit_module is called just before the driver is removed
7900 * from memory.
7901 **/
7902static void __exit ixgbe_exit_module(void)
7903{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007904#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007905 dca_unregister_notify(&dca_notifier);
7906#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007907 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007908 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007909}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007910
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007911#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007912static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007913 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007914{
7915 int ret_val;
7916
7917 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007918 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007919
7920 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7921}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007922
Alexander Duyckb4533682009-03-31 21:32:42 +00007923#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007924
Auke Kok9a799d72007-09-15 14:07:45 -07007925module_exit(ixgbe_exit_module);
7926
7927/* ixgbe_main.c */