blob: 26b132bca43eae2ee50df30e5579b65e6911710e [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>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
45#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040046#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000047#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048
49#include "ixgbe.h"
50#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000051#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000052#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070053
54char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070055static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000056 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000057#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000058#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000059#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000061 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070062const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000063static const char ixgbe_copyright[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070065
66static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070067 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000068 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080069 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070070};
71
72/* ixgbe_pci_tbl - PCI Device ID Table
73 *
74 * Wildcard entries (PCI_ANY_ID) should come last
75 * Last entry must be all 0s
76 *
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
79 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000080static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
82 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070086 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
88 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
90 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070092 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
94 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
96 board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
98 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
100 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
102 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
104 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
106 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
108 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
110 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
112 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
114 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
116 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
118 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
120 board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
122 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
124 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
126 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000128 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
130 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
132 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700133
134 /* required last entry */
135 {0, }
136};
137MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
138
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400139#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800140static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000141 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800142static struct notifier_block dca_notifier = {
143 .notifier_call = ixgbe_notify_dca,
144 .next = NULL,
145 .priority = 0
146};
147#endif
148
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000149#ifdef CONFIG_PCI_IOV
150static unsigned int max_vfs;
151module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000152MODULE_PARM_DESC(max_vfs,
153 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000154#endif /* CONFIG_PCI_IOV */
155
Auke Kok9a799d72007-09-15 14:07:45 -0700156MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
157MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
158MODULE_LICENSE("GPL");
159MODULE_VERSION(DRV_VERSION);
160
161#define DEFAULT_DEBUG_LEVEL_SHIFT 3
162
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000163static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
164{
165 struct ixgbe_hw *hw = &adapter->hw;
166 u32 gcr;
167 u32 gpie;
168 u32 vmdctl;
169
170#ifdef CONFIG_PCI_IOV
171 /* disable iov and allow time for transactions to clear */
172 pci_disable_sriov(adapter->pdev);
173#endif
174
175 /* turn off device IOV mode */
176 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
177 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
178 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
179 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
180 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
181 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
182
183 /* set default pool back to 0 */
184 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
185 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
186 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000187 IXGBE_WRITE_FLUSH(hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000188
189 /* take a breather then clean up driver data */
190 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000191
192 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000193 adapter->vfinfo = NULL;
194
195 adapter->num_vfs = 0;
196 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
197}
198
Alexander Duyck70864002011-04-27 09:13:56 +0000199static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
200{
201 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
202 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
203 schedule_work(&adapter->service_task);
204}
205
206static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
207{
208 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
209
210 /* flush memory to make sure state is correct before next watchog */
211 smp_mb__before_clear_bit();
212 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
213}
214
Taku Izumidcd79ae2010-04-27 14:39:53 +0000215struct ixgbe_reg_info {
216 u32 ofs;
217 char *name;
218};
219
220static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
221
222 /* General Registers */
223 {IXGBE_CTRL, "CTRL"},
224 {IXGBE_STATUS, "STATUS"},
225 {IXGBE_CTRL_EXT, "CTRL_EXT"},
226
227 /* Interrupt Registers */
228 {IXGBE_EICR, "EICR"},
229
230 /* RX Registers */
231 {IXGBE_SRRCTL(0), "SRRCTL"},
232 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
233 {IXGBE_RDLEN(0), "RDLEN"},
234 {IXGBE_RDH(0), "RDH"},
235 {IXGBE_RDT(0), "RDT"},
236 {IXGBE_RXDCTL(0), "RXDCTL"},
237 {IXGBE_RDBAL(0), "RDBAL"},
238 {IXGBE_RDBAH(0), "RDBAH"},
239
240 /* TX Registers */
241 {IXGBE_TDBAL(0), "TDBAL"},
242 {IXGBE_TDBAH(0), "TDBAH"},
243 {IXGBE_TDLEN(0), "TDLEN"},
244 {IXGBE_TDH(0), "TDH"},
245 {IXGBE_TDT(0), "TDT"},
246 {IXGBE_TXDCTL(0), "TXDCTL"},
247
248 /* List Terminator */
249 {}
250};
251
252
253/*
254 * ixgbe_regdump - register printout routine
255 */
256static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
257{
258 int i = 0, j = 0;
259 char rname[16];
260 u32 regs[64];
261
262 switch (reginfo->ofs) {
263 case IXGBE_SRRCTL(0):
264 for (i = 0; i < 64; i++)
265 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
266 break;
267 case IXGBE_DCA_RXCTRL(0):
268 for (i = 0; i < 64; i++)
269 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
270 break;
271 case IXGBE_RDLEN(0):
272 for (i = 0; i < 64; i++)
273 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
274 break;
275 case IXGBE_RDH(0):
276 for (i = 0; i < 64; i++)
277 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
278 break;
279 case IXGBE_RDT(0):
280 for (i = 0; i < 64; i++)
281 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
282 break;
283 case IXGBE_RXDCTL(0):
284 for (i = 0; i < 64; i++)
285 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
286 break;
287 case IXGBE_RDBAL(0):
288 for (i = 0; i < 64; i++)
289 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
290 break;
291 case IXGBE_RDBAH(0):
292 for (i = 0; i < 64; i++)
293 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
294 break;
295 case IXGBE_TDBAL(0):
296 for (i = 0; i < 64; i++)
297 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
298 break;
299 case IXGBE_TDBAH(0):
300 for (i = 0; i < 64; i++)
301 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
302 break;
303 case IXGBE_TDLEN(0):
304 for (i = 0; i < 64; i++)
305 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
306 break;
307 case IXGBE_TDH(0):
308 for (i = 0; i < 64; i++)
309 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
310 break;
311 case IXGBE_TDT(0):
312 for (i = 0; i < 64; i++)
313 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
314 break;
315 case IXGBE_TXDCTL(0):
316 for (i = 0; i < 64; i++)
317 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
318 break;
319 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000320 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000321 IXGBE_READ_REG(hw, reginfo->ofs));
322 return;
323 }
324
325 for (i = 0; i < 8; i++) {
326 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000327 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000328 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000329 pr_cont(" %08x", regs[i*8+j]);
330 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000331 }
332
333}
334
335/*
336 * ixgbe_dump - Print registers, tx-rings and rx-rings
337 */
338static void ixgbe_dump(struct ixgbe_adapter *adapter)
339{
340 struct net_device *netdev = adapter->netdev;
341 struct ixgbe_hw *hw = &adapter->hw;
342 struct ixgbe_reg_info *reginfo;
343 int n = 0;
344 struct ixgbe_ring *tx_ring;
345 struct ixgbe_tx_buffer *tx_buffer_info;
346 union ixgbe_adv_tx_desc *tx_desc;
347 struct my_u0 { u64 a; u64 b; } *u0;
348 struct ixgbe_ring *rx_ring;
349 union ixgbe_adv_rx_desc *rx_desc;
350 struct ixgbe_rx_buffer *rx_buffer_info;
351 u32 staterr;
352 int i = 0;
353
354 if (!netif_msg_hw(adapter))
355 return;
356
357 /* Print netdevice Info */
358 if (netdev) {
359 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000360 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000361 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000362 pr_info("%-15s %016lX %016lX %016lX\n",
363 netdev->name,
364 netdev->state,
365 netdev->trans_start,
366 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000367 }
368
369 /* Print Registers */
370 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000371 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000372 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
373 reginfo->name; reginfo++) {
374 ixgbe_regdump(hw, reginfo);
375 }
376
377 /* Print TX Ring Summary */
378 if (!netdev || !netif_running(netdev))
379 goto exit;
380
381 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000382 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000383 for (n = 0; n < adapter->num_tx_queues; n++) {
384 tx_ring = adapter->tx_ring[n];
385 tx_buffer_info =
386 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000387 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000388 n, tx_ring->next_to_use, tx_ring->next_to_clean,
389 (u64)tx_buffer_info->dma,
390 tx_buffer_info->length,
391 tx_buffer_info->next_to_watch,
392 (u64)tx_buffer_info->time_stamp);
393 }
394
395 /* Print TX Rings */
396 if (!netif_msg_tx_done(adapter))
397 goto rx_ring_summary;
398
399 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
400
401 /* Transmit Descriptor Formats
402 *
403 * Advanced Transmit Descriptor
404 * +--------------------------------------------------------------+
405 * 0 | Buffer Address [63:0] |
406 * +--------------------------------------------------------------+
407 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
408 * +--------------------------------------------------------------+
409 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
410 */
411
412 for (n = 0; n < adapter->num_tx_queues; n++) {
413 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000414 pr_info("------------------------------------\n");
415 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
416 pr_info("------------------------------------\n");
417 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000418 "[PlPOIdStDDt Ln] [bi->dma ] "
419 "leng ntw timestamp bi->skb\n");
420
421 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000422 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000423 tx_buffer_info = &tx_ring->tx_buffer_info[i];
424 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000425 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000426 " %04X %3X %016llX %p", i,
427 le64_to_cpu(u0->a),
428 le64_to_cpu(u0->b),
429 (u64)tx_buffer_info->dma,
430 tx_buffer_info->length,
431 tx_buffer_info->next_to_watch,
432 (u64)tx_buffer_info->time_stamp,
433 tx_buffer_info->skb);
434 if (i == tx_ring->next_to_use &&
435 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000436 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000437 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000439 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000440 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000441 else
Joe Perchesc7689572010-09-07 21:35:17 +0000442 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000443
444 if (netif_msg_pktdata(adapter) &&
445 tx_buffer_info->dma != 0)
446 print_hex_dump(KERN_INFO, "",
447 DUMP_PREFIX_ADDRESS, 16, 1,
448 phys_to_virt(tx_buffer_info->dma),
449 tx_buffer_info->length, true);
450 }
451 }
452
453 /* Print RX Rings Summary */
454rx_ring_summary:
455 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000456 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000457 for (n = 0; n < adapter->num_rx_queues; n++) {
458 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000459 pr_info("%5d %5X %5X\n",
460 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000461 }
462
463 /* Print RX Rings */
464 if (!netif_msg_rx_status(adapter))
465 goto exit;
466
467 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
468
469 /* Advanced Receive Descriptor (Read) Format
470 * 63 1 0
471 * +-----------------------------------------------------+
472 * 0 | Packet Buffer Address [63:1] |A0/NSE|
473 * +----------------------------------------------+------+
474 * 8 | Header Buffer Address [63:1] | DD |
475 * +-----------------------------------------------------+
476 *
477 *
478 * Advanced Receive Descriptor (Write-Back) Format
479 *
480 * 63 48 47 32 31 30 21 20 16 15 4 3 0
481 * +------------------------------------------------------+
482 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
483 * | Checksum Ident | | | | Type | Type |
484 * +------------------------------------------------------+
485 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
486 * +------------------------------------------------------+
487 * 63 48 47 32 31 20 19 0
488 */
489 for (n = 0; n < adapter->num_rx_queues; n++) {
490 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000491 pr_info("------------------------------------\n");
492 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
493 pr_info("------------------------------------\n");
494 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000495 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
496 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000497 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000498 "[vl er S cks ln] ---------------- [bi->skb] "
499 "<-- Adv Rx Write-Back format\n");
500
501 for (i = 0; i < rx_ring->count; i++) {
502 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000503 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504 u0 = (struct my_u0 *)rx_desc;
505 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
506 if (staterr & IXGBE_RXD_STAT_DD) {
507 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000508 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000509 "%016llX ---------------- %p", i,
510 le64_to_cpu(u0->a),
511 le64_to_cpu(u0->b),
512 rx_buffer_info->skb);
513 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000514 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000515 "%016llX %016llX %p", i,
516 le64_to_cpu(u0->a),
517 le64_to_cpu(u0->b),
518 (u64)rx_buffer_info->dma,
519 rx_buffer_info->skb);
520
521 if (netif_msg_pktdata(adapter)) {
522 print_hex_dump(KERN_INFO, "",
523 DUMP_PREFIX_ADDRESS, 16, 1,
524 phys_to_virt(rx_buffer_info->dma),
525 rx_ring->rx_buf_len, true);
526
527 if (rx_ring->rx_buf_len
528 < IXGBE_RXBUFFER_2048)
529 print_hex_dump(KERN_INFO, "",
530 DUMP_PREFIX_ADDRESS, 16, 1,
531 phys_to_virt(
532 rx_buffer_info->page_dma +
533 rx_buffer_info->page_offset
534 ),
535 PAGE_SIZE/2, true);
536 }
537 }
538
539 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000540 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000541 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000542 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000543 else
Joe Perchesc7689572010-09-07 21:35:17 +0000544 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000545
546 }
547 }
548
549exit:
550 return;
551}
552
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800553static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
554{
555 u32 ctrl_ext;
556
557 /* Let firmware take over control of h/w */
558 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
559 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000560 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800561}
562
563static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
564{
565 u32 ctrl_ext;
566
567 /* Let firmware know the driver has taken over */
568 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
569 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000570 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800571}
Auke Kok9a799d72007-09-15 14:07:45 -0700572
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000573/*
574 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
575 * @adapter: pointer to adapter struct
576 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
577 * @queue: queue to map the corresponding interrupt to
578 * @msix_vector: the vector to map to the corresponding queue
579 *
580 */
581static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000582 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700583{
584 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000585 struct ixgbe_hw *hw = &adapter->hw;
586 switch (hw->mac.type) {
587 case ixgbe_mac_82598EB:
588 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
589 if (direction == -1)
590 direction = 0;
591 index = (((direction * 64) + queue) >> 2) & 0x1F;
592 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
593 ivar &= ~(0xFF << (8 * (queue & 0x3)));
594 ivar |= (msix_vector << (8 * (queue & 0x3)));
595 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
596 break;
597 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800598 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000599 if (direction == -1) {
600 /* other causes */
601 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
602 index = ((queue & 1) * 8);
603 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
604 ivar &= ~(0xFF << index);
605 ivar |= (msix_vector << index);
606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
607 break;
608 } else {
609 /* tx or rx causes */
610 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
611 index = ((16 * (queue & 1)) + (8 * direction));
612 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
613 ivar &= ~(0xFF << index);
614 ivar |= (msix_vector << index);
615 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
616 break;
617 }
618 default:
619 break;
620 }
Auke Kok9a799d72007-09-15 14:07:45 -0700621}
622
Alexander Duyckfe49f042009-06-04 16:00:09 +0000623static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000624 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000625{
626 u32 mask;
627
Alexander Duyckbd508172010-11-16 19:27:03 -0800628 switch (adapter->hw.mac.type) {
629 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000630 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
631 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800632 break;
633 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800634 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000635 mask = (qmask & 0xFFFFFFFF);
636 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
637 mask = (qmask >> 32);
638 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800639 break;
640 default:
641 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000642 }
643}
644
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800645void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
646 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700647{
Alexander Duycke5a43542009-12-02 16:46:56 +0000648 if (tx_buffer_info->dma) {
649 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800650 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000651 tx_buffer_info->dma,
652 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000653 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000654 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800655 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000656 tx_buffer_info->dma,
657 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000658 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000659 tx_buffer_info->dma = 0;
660 }
Auke Kok9a799d72007-09-15 14:07:45 -0700661 if (tx_buffer_info->skb) {
662 dev_kfree_skb_any(tx_buffer_info->skb);
663 tx_buffer_info->skb = NULL;
664 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000665 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700666 /* tx_buffer_info must be completely set up in the transmit path */
667}
668
John Fastabendc84d3242010-11-16 19:27:12 -0800669static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700670{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700671 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800672 struct ixgbe_hw_stats *hwstats = &adapter->stats;
673 u32 data = 0;
674 u32 xoff[8] = {0};
675 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700676
John Fastabendc84d3242010-11-16 19:27:12 -0800677 if ((hw->fc.current_mode == ixgbe_fc_full) ||
678 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
679 switch (hw->mac.type) {
680 case ixgbe_mac_82598EB:
681 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
682 break;
683 default:
684 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
685 }
686 hwstats->lxoffrxc += data;
687
688 /* refill credits (no tx hang) if we received xoff */
689 if (!data)
690 return;
691
692 for (i = 0; i < adapter->num_tx_queues; i++)
693 clear_bit(__IXGBE_HANG_CHECK_ARMED,
694 &adapter->tx_ring[i]->state);
695 return;
696 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
697 return;
698
699 /* update stats for each tc, only valid with PFC enabled */
700 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
701 switch (hw->mac.type) {
702 case ixgbe_mac_82598EB:
703 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
704 break;
705 default:
706 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
707 }
708 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700709 }
710
John Fastabendc84d3242010-11-16 19:27:12 -0800711 /* disarm tx queues that have received xoff frames */
712 for (i = 0; i < adapter->num_tx_queues; i++) {
713 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000714 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800715
716 if (xoff[tc])
717 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
718 }
719}
720
721static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
722{
723 return ring->tx_stats.completed;
724}
725
726static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
727{
728 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
729 struct ixgbe_hw *hw = &adapter->hw;
730
731 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
732 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
733
734 if (head != tail)
735 return (head < tail) ?
736 tail - head : (tail + ring->count - head);
737
738 return 0;
739}
740
741static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
742{
743 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
744 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
745 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
746 bool ret = false;
747
748 clear_check_for_tx_hang(tx_ring);
749
750 /*
751 * Check for a hung queue, but be thorough. This verifies
752 * that a transmit has been completed since the previous
753 * check AND there is at least one packet pending. The
754 * ARMED bit is set to indicate a potential hang. The
755 * bit is cleared if a pause frame is received to remove
756 * false hang detection due to PFC or 802.3x frames. By
757 * requiring this to fail twice we avoid races with
758 * pfc clearing the ARMED bit and conditions where we
759 * run the check_tx_hang logic with a transmit completion
760 * pending but without time to complete it yet.
761 */
762 if ((tx_done_old == tx_done) && tx_pending) {
763 /* make sure it is true for two checks in a row */
764 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
765 &tx_ring->state);
766 } else {
767 /* update completed stats and continue */
768 tx_ring->tx_stats.tx_done_old = tx_done;
769 /* reset the countdown */
770 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
771 }
772
773 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700774}
775
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000776/**
777 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
778 * @adapter: driver private struct
779 **/
780static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
781{
782
783 /* Do the reset outside of interrupt context */
784 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
785 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
786 ixgbe_service_event_schedule(adapter);
787 }
788}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700789
Auke Kok9a799d72007-09-15 14:07:45 -0700790/**
791 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000792 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700793 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700794 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000795static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000796 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700797{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000798 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800799 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
800 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700801 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800802 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700803
804 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800805 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000806 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800807
808 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Alexander Duyckbd198052011-06-11 01:45:08 +0000809 (count < q_vector->tx.work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800810 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000811 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800812 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000813 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700814 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700815
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800816 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800817 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800818
Auke Kok9a799d72007-09-15 14:07:45 -0700819 i++;
820 if (i == tx_ring->count)
821 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800822
823 if (cleaned && tx_buffer_info->skb) {
824 total_bytes += tx_buffer_info->bytecount;
825 total_packets += tx_buffer_info->gso_segs;
826 }
827
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800828 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800829 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700830 }
831
John Fastabendc84d3242010-11-16 19:27:12 -0800832 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800833 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000834 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800835 }
836
Auke Kok9a799d72007-09-15 14:07:45 -0700837 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800838 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000839 tx_ring->stats.packets += total_packets;
840 u64_stats_update_begin(&tx_ring->syncp);
841 q_vector->tx.total_bytes += total_bytes;
842 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800843 u64_stats_update_end(&tx_ring->syncp);
844
John Fastabendc84d3242010-11-16 19:27:12 -0800845 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800846 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800847 struct ixgbe_hw *hw = &adapter->hw;
848 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
849 e_err(drv, "Detected Tx Unit Hang\n"
850 " Tx Queue <%d>\n"
851 " TDH, TDT <%x>, <%x>\n"
852 " next_to_use <%x>\n"
853 " next_to_clean <%x>\n"
854 "tx_buffer_info[next_to_clean]\n"
855 " time_stamp <%lx>\n"
856 " jiffies <%lx>\n",
857 tx_ring->queue_index,
858 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
859 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
860 tx_ring->next_to_use, eop,
861 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
862
863 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
864
865 e_info(probe,
866 "tx hang %d detected on queue %d, resetting adapter\n",
867 adapter->tx_timeout_count + 1, tx_ring->queue_index);
868
869 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000870 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800871
872 /* the adapter is about to reset, no point in enabling stuff */
873 return true;
874 }
Auke Kok9a799d72007-09-15 14:07:45 -0700875
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800876#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800877 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000878 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800879 /* Make sure that anybody stopping the queue after this
880 * sees the new next_to_clean.
881 */
882 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800883 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800884 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800885 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800886 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800887 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800888 }
Auke Kok9a799d72007-09-15 14:07:45 -0700889
Alexander Duyckbd198052011-06-11 01:45:08 +0000890 return count < q_vector->tx.work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700891}
892
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400893#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800894static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800895 struct ixgbe_ring *rx_ring,
896 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800897{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800898 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800899 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800900 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800901
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800902 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
903 switch (hw->mac.type) {
904 case ixgbe_mac_82598EB:
905 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
906 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
907 break;
908 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800909 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800910 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
911 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
912 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
913 break;
914 default:
915 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800916 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800917 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
918 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
919 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800920 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800921}
922
923static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800924 struct ixgbe_ring *tx_ring,
925 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800926{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000927 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800928 u32 txctrl;
929 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800930
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931 switch (hw->mac.type) {
932 case ixgbe_mac_82598EB:
933 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
934 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
935 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
936 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800937 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
938 break;
939 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800940 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800941 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
942 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
943 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
944 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
945 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800946 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
947 break;
948 default:
949 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800950 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800951}
952
953static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
954{
955 struct ixgbe_adapter *adapter = q_vector->adapter;
956 int cpu = get_cpu();
957 long r_idx;
958 int i;
959
960 if (q_vector->cpu == cpu)
961 goto out_no_update;
962
Alexander Duyck08c88332011-06-11 01:45:03 +0000963 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
964 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800965 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000966 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800967 r_idx + 1);
968 }
969
Alexander Duyck08c88332011-06-11 01:45:03 +0000970 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
971 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800972 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000973 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974 r_idx + 1);
975 }
976
977 q_vector->cpu = cpu;
978out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800979 put_cpu();
980}
981
982static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
983{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800984 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800985 int i;
986
987 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
988 return;
989
Alexander Duycke35ec122009-05-21 13:07:12 +0000990 /* always use CB2 mode, difference is masked in the CB driver */
991 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
992
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800993 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
994 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
995 else
996 num_q_vectors = 1;
997
998 for (i = 0; i < num_q_vectors; i++) {
999 adapter->q_vector[i]->cpu = -1;
1000 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001001 }
1002}
1003
1004static int __ixgbe_notify_dca(struct device *dev, void *data)
1005{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001006 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001007 unsigned long event = *(unsigned long *)data;
1008
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001009 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1010 return 0;
1011
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001012 switch (event) {
1013 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001014 /* if we're already enabled, don't do it again */
1015 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1016 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001017 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001018 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001019 ixgbe_setup_dca(adapter);
1020 break;
1021 }
1022 /* Fall Through since DCA is disabled. */
1023 case DCA_PROVIDER_REMOVE:
1024 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1025 dca_remove_requester(dev);
1026 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1027 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1028 }
1029 break;
1030 }
1031
Denis V. Lunev652f0932008-03-27 14:39:17 +03001032 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001033}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001034#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001035
1036static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1037 struct sk_buff *skb)
1038{
1039 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1040}
1041
Auke Kok9a799d72007-09-15 14:07:45 -07001042/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001043 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1044 * @adapter: address of board private structure
1045 * @rx_desc: advanced rx descriptor
1046 *
1047 * Returns : true if it is FCoE pkt
1048 */
1049static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1050 union ixgbe_adv_rx_desc *rx_desc)
1051{
1052 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1053
1054 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1055 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1056 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1057 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1058}
1059
1060/**
Auke Kok9a799d72007-09-15 14:07:45 -07001061 * ixgbe_receive_skb - Send a completed packet up the stack
1062 * @adapter: board private structure
1063 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001064 * @status: hardware indication of status of receive
1065 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1066 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001067 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001068static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001069 struct sk_buff *skb, u8 status,
1070 struct ixgbe_ring *ring,
1071 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001072{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001073 struct ixgbe_adapter *adapter = q_vector->adapter;
1074 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001075 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1076 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001077
Jesse Grossf62bbb52010-10-20 13:56:10 +00001078 if (is_vlan && (tag & VLAN_VID_MASK))
1079 __vlan_hwaccel_put_tag(skb, tag);
1080
1081 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1082 napi_gro_receive(napi, skb);
1083 else
1084 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001085}
1086
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001087/**
1088 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1089 * @adapter: address of board private structure
1090 * @status_err: hardware indication of status of receive
1091 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001092 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001093 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001094static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001095 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001096 struct sk_buff *skb,
1097 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001098{
Alexander Duyckff886df2011-06-11 01:45:13 +00001099 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001100
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001101 /* Rx csum disabled */
1102 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001103 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001104
1105 /* if IP and error */
1106 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1107 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001108 adapter->hw_csum_rx_error++;
1109 return;
1110 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001111
1112 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1113 return;
1114
1115 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001116 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1117
1118 /*
1119 * 82599 errata, UDP frames with a 0 checksum can be marked as
1120 * checksum errors.
1121 */
1122 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1123 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1124 return;
1125
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001126 adapter->hw_csum_rx_error++;
1127 return;
1128 }
1129
Auke Kok9a799d72007-09-15 14:07:45 -07001130 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001131 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001132}
1133
Alexander Duyck84ea2592010-11-16 19:26:49 -08001134static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001135{
1136 /*
1137 * Force memory writes to complete before letting h/w
1138 * know there are new descriptors to fetch. (Only
1139 * applicable for weak-ordered memory model archs,
1140 * such as IA-64).
1141 */
1142 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001143 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001144}
1145
Auke Kok9a799d72007-09-15 14:07:45 -07001146/**
1147 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001148 * @rx_ring: ring to place buffers on
1149 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001150 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001151void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001152{
Auke Kok9a799d72007-09-15 14:07:45 -07001153 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001154 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001155 struct sk_buff *skb;
1156 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001157
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001158 /* do nothing if no valid netdev defined */
1159 if (!rx_ring->netdev)
1160 return;
1161
Auke Kok9a799d72007-09-15 14:07:45 -07001162 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001163 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001164 bi = &rx_ring->rx_buffer_info[i];
1165 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001166
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001167 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001168 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001169 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001170 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001171 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001172 goto no_buffers;
1173 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001174 /* initialize queue mapping */
1175 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001176 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001177 }
Auke Kok9a799d72007-09-15 14:07:45 -07001178
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001179 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001180 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001181 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001182 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001183 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001184 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001185 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001186 bi->dma = 0;
1187 goto no_buffers;
1188 }
Auke Kok9a799d72007-09-15 14:07:45 -07001189 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001190
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001191 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001192 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001193 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001194 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001195 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001196 goto no_buffers;
1197 }
1198 }
1199
1200 if (!bi->page_dma) {
1201 /* use a half page if we're re-using */
1202 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001203 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001204 bi->page,
1205 bi->page_offset,
1206 PAGE_SIZE / 2,
1207 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001208 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001209 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001210 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001211 bi->page_dma = 0;
1212 goto no_buffers;
1213 }
1214 }
1215
1216 /* Refresh the desc even if buffer_addrs didn't change
1217 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001218 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1219 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001220 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001221 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001222 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001223 }
1224
1225 i++;
1226 if (i == rx_ring->count)
1227 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001228 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001229
Auke Kok9a799d72007-09-15 14:07:45 -07001230no_buffers:
1231 if (rx_ring->next_to_use != i) {
1232 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001233 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001234 }
1235}
1236
Alexander Duyckc267fc12010-11-16 19:27:00 -08001237static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001238{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001239 /* HW will not DMA in data larger than the given buffer, even if it
1240 * parses the (NFS, of course) header to be larger. In that case, it
1241 * fills the header buffer and spills the rest into the page.
1242 */
1243 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1244 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1245 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1246 if (hlen > IXGBE_RX_HDR_SIZE)
1247 hlen = IXGBE_RX_HDR_SIZE;
1248 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001249}
1250
Alexander Duyckf8212f92009-04-27 22:42:37 +00001251/**
1252 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1253 * @skb: pointer to the last skb in the rsc queue
1254 *
1255 * This function changes a queue full of hw rsc buffers into a completed
1256 * packet. It uses the ->prev pointers to find the first packet and then
1257 * turns it into the frag list owner.
1258 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001259static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001260{
1261 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001262 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001263
1264 while (skb->prev) {
1265 struct sk_buff *prev = skb->prev;
1266 frag_list_size += skb->len;
1267 skb->prev = NULL;
1268 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001269 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001270 }
1271
1272 skb_shinfo(skb)->frag_list = skb->next;
1273 skb->next = NULL;
1274 skb->len += frag_list_size;
1275 skb->data_len += frag_list_size;
1276 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001277 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1278
Alexander Duyckf8212f92009-04-27 22:42:37 +00001279 return skb;
1280}
1281
Alexander Duyckaa801752010-11-16 19:27:02 -08001282static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1283{
1284 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1285 IXGBE_RXDADV_RSCCNT_MASK);
1286}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001287
Alexander Duyckc267fc12010-11-16 19:27:00 -08001288static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001289 struct ixgbe_ring *rx_ring,
1290 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001291{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001292 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001293 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1294 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1295 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001296 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001297 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001298#ifdef IXGBE_FCOE
1299 int ddp_bytes = 0;
1300#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001301 u32 staterr;
1302 u16 i;
1303 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001304 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001305
1306 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001307 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001308 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001309
1310 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001311 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001312
Milton Miller3c945e52010-02-19 17:44:42 +00001313 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001314
Alexander Duyckc267fc12010-11-16 19:27:00 -08001315 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1316
Auke Kok9a799d72007-09-15 14:07:45 -07001317 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001318 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001319 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001320
Alexander Duyckc267fc12010-11-16 19:27:00 -08001321 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001322 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001323
1324 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001325 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001326 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001327 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001328 !(staterr & IXGBE_RXD_STAT_EOP) &&
1329 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001330 /*
1331 * When HWRSC is enabled, delay unmapping
1332 * of the first packet. It carries the
1333 * header information, HW may still
1334 * access the header after the writeback.
1335 * Only unmap it when EOP is reached
1336 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001337 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001338 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001339 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001340 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001341 rx_buffer_info->dma,
1342 rx_ring->rx_buf_len,
1343 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001344 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001345 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001346
1347 if (ring_is_ps_enabled(rx_ring)) {
1348 hlen = ixgbe_get_hlen(rx_desc);
1349 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1350 } else {
1351 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1352 }
1353
1354 skb_put(skb, hlen);
1355 } else {
1356 /* assume packet split since header is unmapped */
1357 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001358 }
1359
1360 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001361 dma_unmap_page(rx_ring->dev,
1362 rx_buffer_info->page_dma,
1363 PAGE_SIZE / 2,
1364 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001365 rx_buffer_info->page_dma = 0;
1366 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001367 rx_buffer_info->page,
1368 rx_buffer_info->page_offset,
1369 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001370
Alexander Duyckc267fc12010-11-16 19:27:00 -08001371 if ((page_count(rx_buffer_info->page) == 1) &&
1372 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001373 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001374 else
1375 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001376
1377 skb->len += upper_len;
1378 skb->data_len += upper_len;
1379 skb->truesize += upper_len;
1380 }
1381
1382 i++;
1383 if (i == rx_ring->count)
1384 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001385
Alexander Duyck31f05a22010-08-19 13:40:31 +00001386 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001387 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001388 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001389
Alexander Duyckaa801752010-11-16 19:27:02 -08001390 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001391 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1392 IXGBE_RXDADV_NEXTP_SHIFT;
1393 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001394 } else {
1395 next_buffer = &rx_ring->rx_buffer_info[i];
1396 }
1397
Alexander Duyckc267fc12010-11-16 19:27:00 -08001398 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001399 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001400 rx_buffer_info->skb = next_buffer->skb;
1401 rx_buffer_info->dma = next_buffer->dma;
1402 next_buffer->skb = skb;
1403 next_buffer->dma = 0;
1404 } else {
1405 skb->next = next_buffer->skb;
1406 skb->next->prev = skb;
1407 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001408 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001409 goto next_desc;
1410 }
1411
Alexander Duyckaa801752010-11-16 19:27:02 -08001412 if (skb->prev) {
1413 skb = ixgbe_transform_rsc_queue(skb);
1414 /* if we got here without RSC the packet is invalid */
1415 if (!pkt_is_rsc) {
1416 __pskb_trim(skb, 0);
1417 rx_buffer_info->skb = skb;
1418 goto next_desc;
1419 }
1420 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001421
1422 if (ring_is_rsc_enabled(rx_ring)) {
1423 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1424 dma_unmap_single(rx_ring->dev,
1425 IXGBE_RSC_CB(skb)->dma,
1426 rx_ring->rx_buf_len,
1427 DMA_FROM_DEVICE);
1428 IXGBE_RSC_CB(skb)->dma = 0;
1429 IXGBE_RSC_CB(skb)->delay_unmap = false;
1430 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001431 }
1432 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001433 if (ring_is_ps_enabled(rx_ring))
1434 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001435 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001436 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001437 rx_ring->rx_stats.rsc_count +=
1438 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001439 rx_ring->rx_stats.rsc_flush++;
1440 }
1441
1442 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001443 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1444 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001445 goto next_desc;
1446 }
1447
Alexander Duyckff886df2011-06-11 01:45:13 +00001448 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001449 if (adapter->netdev->features & NETIF_F_RXHASH)
1450 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001451
1452 /* probably a little skewed due to removing CRC */
1453 total_rx_bytes += skb->len;
1454 total_rx_packets++;
1455
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001456 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001457#ifdef IXGBE_FCOE
1458 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001459 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1460 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1461 staterr);
Yi Zou3d8fd382009-06-08 14:38:44 +00001462 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001463 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001464 }
Yi Zou332d4a72009-05-13 13:11:53 +00001465#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001466 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001467
1468next_desc:
1469 rx_desc->wb.upper.status_error = 0;
1470
Alexander Duyckc267fc12010-11-16 19:27:00 -08001471 (*work_done)++;
1472 if (*work_done >= work_to_do)
1473 break;
1474
Auke Kok9a799d72007-09-15 14:07:45 -07001475 /* return some buffers to hardware, one at a time is too slow */
1476 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001477 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001478 cleaned_count = 0;
1479 }
1480
1481 /* use prefetched values */
1482 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001483 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001484 }
1485
Auke Kok9a799d72007-09-15 14:07:45 -07001486 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001487 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001488
1489 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001490 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001491
Yi Zou3d8fd382009-06-08 14:38:44 +00001492#ifdef IXGBE_FCOE
1493 /* include DDPed FCoE data */
1494 if (ddp_bytes > 0) {
1495 unsigned int mss;
1496
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001497 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001498 sizeof(struct fc_frame_header) -
1499 sizeof(struct fcoe_crc_eof);
1500 if (mss > 512)
1501 mss &= ~511;
1502 total_rx_bytes += ddp_bytes;
1503 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1504 }
1505#endif /* IXGBE_FCOE */
1506
Alexander Duyckc267fc12010-11-16 19:27:00 -08001507 u64_stats_update_begin(&rx_ring->syncp);
1508 rx_ring->stats.packets += total_rx_packets;
1509 rx_ring->stats.bytes += total_rx_bytes;
1510 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001511 q_vector->rx.total_packets += total_rx_packets;
1512 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001513}
1514
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001515static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001516/**
1517 * ixgbe_configure_msix - Configure MSI-X hardware
1518 * @adapter: board private structure
1519 *
1520 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1521 * interrupts.
1522 **/
1523static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1524{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001525 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001526 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001527 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001528
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001529 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1530
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001531 /*
1532 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001533 * corresponding register.
1534 */
1535 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001536 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001537 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001538 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001539 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001540
Alexander Duyck08c88332011-06-11 01:45:03 +00001541 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001542 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1543 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001544 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001545 adapter->num_rx_queues,
1546 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001547 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001548 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001549 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001550
Alexander Duyck08c88332011-06-11 01:45:03 +00001551 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001552 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1553 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001554 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001555 adapter->num_tx_queues,
1556 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001557 }
1558
Alexander Duyck08c88332011-06-11 01:45:03 +00001559 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001560 /* tx only */
1561 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001562 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001563 /* rx or mixed */
1564 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001565
Alexander Duyckfe49f042009-06-04 16:00:09 +00001566 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001567 /* If ATR is enabled, set interrupt affinity */
1568 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001569 /*
1570 * Allocate the affinity_hint cpumask, assign the mask
1571 * for this vector, and set our affinity_hint for
1572 * this irq.
1573 */
1574 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1575 GFP_KERNEL))
1576 return;
1577 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1578 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1579 q_vector->affinity_mask);
1580 }
Auke Kok9a799d72007-09-15 14:07:45 -07001581 }
1582
Alexander Duyckbd508172010-11-16 19:27:03 -08001583 switch (adapter->hw.mac.type) {
1584 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001585 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001586 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001587 break;
1588 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001589 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001590 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001591 break;
1592
1593 default:
1594 break;
1595 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001596 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001597
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001598 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001599 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001600 if (adapter->num_vfs)
1601 mask &= ~(IXGBE_EIMS_OTHER |
1602 IXGBE_EIMS_MAILBOX |
1603 IXGBE_EIMS_LSC);
1604 else
1605 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001606 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001607}
1608
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001609enum latency_range {
1610 lowest_latency = 0,
1611 low_latency = 1,
1612 bulk_latency = 2,
1613 latency_invalid = 255
1614};
1615
1616/**
1617 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001618 * @q_vector: structure containing interrupt and ring information
1619 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001620 *
1621 * Stores a new ITR value based on packets and byte
1622 * counts during the last interrupt. The advantage of per interrupt
1623 * computation is faster updates and more accurate ITR for the current
1624 * traffic pattern. Constants in this function were computed
1625 * based on theoretical maximum wire speed and thresholds were set based
1626 * on testing data as well as attempting to minimize response time
1627 * while increasing bulk throughput.
1628 * this functionality is controlled by the InterruptThrottleRate module
1629 * parameter (see ixgbe_param.c)
1630 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001631static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1632 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001633{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001634 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001635 struct ixgbe_adapter *adapter = q_vector->adapter;
1636 int bytes = ring_container->total_bytes;
1637 int packets = ring_container->total_packets;
1638 u32 timepassed_us;
1639 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001640
1641 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001642 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001643
1644 /* simple throttlerate management
1645 * 0-20MB/s lowest (100000 ints/s)
1646 * 20-100MB/s low (20000 ints/s)
1647 * 100-1249MB/s bulk (8000 ints/s)
1648 */
1649 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001650 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001651 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1652
1653 switch (itr_setting) {
1654 case lowest_latency:
1655 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001656 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001657 break;
1658 case low_latency:
1659 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001660 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001661 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001662 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001663 break;
1664 case bulk_latency:
1665 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001666 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001667 break;
1668 }
1669
Alexander Duyckbd198052011-06-11 01:45:08 +00001670 /* clear work counters since we have the values we need */
1671 ring_container->total_bytes = 0;
1672 ring_container->total_packets = 0;
1673
1674 /* write updated itr to ring container */
1675 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001676}
1677
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001678/**
1679 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001680 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001681 *
1682 * This function is made to be called by ethtool and by the driver
1683 * when it needs to update EITR registers at runtime. Hardware
1684 * specific quirks/differences are taken care of here.
1685 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001686void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001687{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001688 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001689 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001690 int v_idx = q_vector->v_idx;
1691 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1692
Alexander Duyckbd508172010-11-16 19:27:03 -08001693 switch (adapter->hw.mac.type) {
1694 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001695 /* must write high and low 16 bits to reset counter */
1696 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001697 break;
1698 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001699 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001700 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001701 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001702 * max interrupt rate, but there is an errata where it can
1703 * not be zero with RSC
1704 */
1705 if (itr_reg == 8 &&
1706 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1707 itr_reg = 0;
1708
1709 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001710 * set the WDIS bit to not clear the timer bits and cause an
1711 * immediate assertion of the interrupt
1712 */
1713 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001714 break;
1715 default:
1716 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001717 }
1718 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1719}
1720
Alexander Duyckbd198052011-06-11 01:45:08 +00001721static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001722{
Alexander Duyckbd198052011-06-11 01:45:08 +00001723 u32 new_itr = q_vector->eitr;
1724 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001725
Alexander Duyckbd198052011-06-11 01:45:08 +00001726 ixgbe_update_itr(q_vector, &q_vector->tx);
1727 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001728
Alexander Duyck08c88332011-06-11 01:45:03 +00001729 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001730
1731 switch (current_itr) {
1732 /* counts and packets in update_itr are dependent on these numbers */
1733 case lowest_latency:
1734 new_itr = 100000;
1735 break;
1736 case low_latency:
1737 new_itr = 20000; /* aka hwitr = ~200 */
1738 break;
1739 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001740 new_itr = 8000;
1741 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001742 default:
1743 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001744 }
1745
1746 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001747 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001748 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001749
Alexander Duyckbd198052011-06-11 01:45:08 +00001750 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001751 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001752
1753 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001754 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001755}
1756
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001757/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001758 * ixgbe_check_overtemp_subtask - check for over tempurature
1759 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001760 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001761static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001762{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001763 struct ixgbe_hw *hw = &adapter->hw;
1764 u32 eicr = adapter->interrupt_event;
1765
Alexander Duyckf0f97782011-04-22 04:08:09 +00001766 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001767 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001768
Alexander Duyckf0f97782011-04-22 04:08:09 +00001769 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1770 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1771 return;
1772
1773 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1774
Joe Perches7ca647b2010-09-07 21:35:40 +00001775 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001776 case IXGBE_DEV_ID_82599_T3_LOM:
1777 /*
1778 * Since the warning interrupt is for both ports
1779 * we don't have to check if:
1780 * - This interrupt wasn't for our port.
1781 * - We may have missed the interrupt so always have to
1782 * check if we got a LSC
1783 */
1784 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1785 !(eicr & IXGBE_EICR_LSC))
1786 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001787
Alexander Duyckf0f97782011-04-22 04:08:09 +00001788 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1789 u32 autoneg;
1790 bool link_up = false;
1791
Joe Perches7ca647b2010-09-07 21:35:40 +00001792 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1793
Alexander Duyckf0f97782011-04-22 04:08:09 +00001794 if (link_up)
1795 return;
1796 }
1797
1798 /* Check if this is not due to overtemp */
1799 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1800 return;
1801
1802 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001803 default:
1804 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1805 return;
1806 break;
1807 }
1808 e_crit(drv,
1809 "Network adapter has been stopped because it has over heated. "
1810 "Restart the computer. If the problem persists, "
1811 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001812
1813 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001814}
1815
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001816static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1817{
1818 struct ixgbe_hw *hw = &adapter->hw;
1819
1820 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1821 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001822 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001823 /* write to clear the interrupt */
1824 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1825 }
1826}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001827
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001828static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1829{
1830 struct ixgbe_hw *hw = &adapter->hw;
1831
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001832 if (eicr & IXGBE_EICR_GPI_SDP2) {
1833 /* Clear the interrupt */
1834 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001835 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1836 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1837 ixgbe_service_event_schedule(adapter);
1838 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001839 }
1840
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001841 if (eicr & IXGBE_EICR_GPI_SDP1) {
1842 /* Clear the interrupt */
1843 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001844 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1845 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1846 ixgbe_service_event_schedule(adapter);
1847 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001848 }
1849}
1850
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001851static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1852{
1853 struct ixgbe_hw *hw = &adapter->hw;
1854
1855 adapter->lsc_int++;
1856 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1857 adapter->link_check_timeout = jiffies;
1858 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1859 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001860 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001861 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001862 }
1863}
1864
Auke Kok9a799d72007-09-15 14:07:45 -07001865static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1866{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001867 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001868 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001869 u32 eicr;
1870
1871 /*
1872 * Workaround for Silicon errata. Use clear-by-write instead
1873 * of clear-by-read. Reading with EICS will return the
1874 * interrupt causes without clearing, which later be done
1875 * with the write to EICR.
1876 */
1877 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1878 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001879
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001880 if (eicr & IXGBE_EICR_LSC)
1881 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001882
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001883 if (eicr & IXGBE_EICR_MAILBOX)
1884 ixgbe_msg_task(adapter);
1885
Alexander Duyckbd508172010-11-16 19:27:03 -08001886 switch (hw->mac.type) {
1887 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001888 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001889 /* Handle Flow Director Full threshold interrupt */
1890 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001891 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001892 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001893 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001894 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001895 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001896 &ring->state))
1897 reinit_count++;
1898 }
1899 if (reinit_count) {
1900 /* no more flow director interrupts until after init */
1901 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1902 eicr &= ~IXGBE_EICR_FLOW_DIR;
1903 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1904 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001905 }
1906 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001907 ixgbe_check_sfp_event(adapter, eicr);
1908 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1909 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1910 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1911 adapter->interrupt_event = eicr;
1912 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1913 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001914 }
1915 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001916 break;
1917 default:
1918 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001919 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001920
1921 ixgbe_check_fan_failure(adapter, eicr);
1922
Alexander Duyck70864002011-04-27 09:13:56 +00001923 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001924 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001925 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1926 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001927
1928 return IRQ_HANDLED;
1929}
1930
Alexander Duyckfe49f042009-06-04 16:00:09 +00001931static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1932 u64 qmask)
1933{
1934 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001935 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001936
Alexander Duyckbd508172010-11-16 19:27:03 -08001937 switch (hw->mac.type) {
1938 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001939 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001940 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1941 break;
1942 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001943 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001944 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001945 if (mask)
1946 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001947 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001948 if (mask)
1949 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1950 break;
1951 default:
1952 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001953 }
1954 /* skip the flush */
1955}
1956
1957static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001958 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001959{
1960 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001961 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001962
Alexander Duyckbd508172010-11-16 19:27:03 -08001963 switch (hw->mac.type) {
1964 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001965 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001966 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1967 break;
1968 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001969 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001970 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001971 if (mask)
1972 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001973 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001974 if (mask)
1975 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1976 break;
1977 default:
1978 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001979 }
1980 /* skip the flush */
1981}
1982
Auke Kok9a799d72007-09-15 14:07:45 -07001983static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1984{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001985 struct ixgbe_q_vector *q_vector = data;
1986 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001987 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001988 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001989
Alexander Duyck08c88332011-06-11 01:45:03 +00001990 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001991 return IRQ_HANDLED;
1992
Alexander Duyck08c88332011-06-11 01:45:03 +00001993 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
1994 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00001995 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00001996 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001997 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001998 }
1999
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002000 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002001 napi_schedule(&q_vector->napi);
2002
Auke Kok9a799d72007-09-15 14:07:45 -07002003 return IRQ_HANDLED;
2004}
2005
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002006/**
2007 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2008 * @irq: unused
2009 * @data: pointer to our q_vector struct for this interrupt vector
2010 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002011static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2012{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002013 struct ixgbe_q_vector *q_vector = data;
2014 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002015 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002016 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002017 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002018
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002019#ifdef CONFIG_IXGBE_DCA
2020 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2021 ixgbe_update_dca(q_vector);
2022#endif
2023
Alexander Duyck08c88332011-06-11 01:45:03 +00002024 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2025 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002026 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002027 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002028 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002029 }
2030
Alexander Duyck08c88332011-06-11 01:45:03 +00002031 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032 return IRQ_HANDLED;
2033
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002034 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002035 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002036
Auke Kok9a799d72007-09-15 14:07:45 -07002037 return IRQ_HANDLED;
2038}
2039
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002040static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2041{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002042 struct ixgbe_q_vector *q_vector = data;
2043 struct ixgbe_adapter *adapter = q_vector->adapter;
2044 struct ixgbe_ring *ring;
2045 int r_idx;
2046 int i;
2047
Alexander Duyck08c88332011-06-11 01:45:03 +00002048 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002049 return IRQ_HANDLED;
2050
Alexander Duyck08c88332011-06-11 01:45:03 +00002051 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2052 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002053 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002054 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002055 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002056 }
2057
Alexander Duyck08c88332011-06-11 01:45:03 +00002058 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2059 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002060 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002061 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002062 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002063 }
2064
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002065 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002066 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002067
2068 return IRQ_HANDLED;
2069}
2070
2071/**
2072 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2073 * @napi: napi struct with our devices info in it
2074 * @budget: amount of work driver is allowed to do this pass, in packets
2075 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002076 * This function is optimized for cleaning one queue only on a single
2077 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002078 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002079static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2080{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002081 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002082 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002083 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002084 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002085 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002086 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002087
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002088#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002089 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002090 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002091#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002092
Alexander Duyck08c88332011-06-11 01:45:03 +00002093 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002094 rx_ring = adapter->rx_ring[r_idx];
2095
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002096 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002097
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002098 /* If all Rx work done, exit the polling mode */
2099 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002100 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002101 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002102 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002103 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002104 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002105 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002106 }
2107
2108 return work_done;
2109}
2110
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002111/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002112 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002113 * @napi: napi struct with our devices info in it
2114 * @budget: amount of work driver is allowed to do this pass, in packets
2115 *
2116 * This function will clean more than one rx queue associated with a
2117 * q_vector.
2118 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002119static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002120{
2121 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002122 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002123 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002124 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002125 int work_done = 0, i;
2126 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002127 bool tx_clean_complete = true;
2128
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002129#ifdef CONFIG_IXGBE_DCA
2130 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2131 ixgbe_update_dca(q_vector);
2132#endif
2133
Alexander Duyck08c88332011-06-11 01:45:03 +00002134 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2135 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002136 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002137 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002138 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002139 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002140 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002141
2142 /* attempt to distribute budget to each queue fairly, but don't allow
2143 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002144 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002145 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002146 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2147 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002148 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002149 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002150 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002151 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002152 }
2153
Alexander Duyck08c88332011-06-11 01:45:03 +00002154 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002155 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002156 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002157 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002158 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002159 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002160 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002161 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002162 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002163 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002164 return 0;
2165 }
2166
2167 return work_done;
2168}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002169
2170/**
2171 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2172 * @napi: napi struct with our devices info in it
2173 * @budget: amount of work driver is allowed to do this pass, in packets
2174 *
2175 * This function is optimized for cleaning one queue only on a single
2176 * q_vector!!!
2177 **/
2178static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2179{
2180 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002181 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002182 struct ixgbe_adapter *adapter = q_vector->adapter;
2183 struct ixgbe_ring *tx_ring = NULL;
2184 int work_done = 0;
2185 long r_idx;
2186
Alexander Duyck91281fd2009-06-04 16:00:27 +00002187#ifdef CONFIG_IXGBE_DCA
2188 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002189 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002190#endif
2191
Alexander Duyck08c88332011-06-11 01:45:03 +00002192 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002193 tx_ring = adapter->tx_ring[r_idx];
2194
Alexander Duyck91281fd2009-06-04 16:00:27 +00002195 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2196 work_done = budget;
2197
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002198 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002199 if (work_done < budget) {
2200 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002201 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002202 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002203 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002204 ixgbe_irq_enable_queues(adapter,
2205 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002206 }
2207
2208 return work_done;
2209}
2210
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002211static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002212 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002213{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002214 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002215 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002216
Alexander Duyck08c88332011-06-11 01:45:03 +00002217 set_bit(r_idx, q_vector->rx.idx);
2218 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002219 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002220}
Auke Kok9a799d72007-09-15 14:07:45 -07002221
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002222static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002223 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002224{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002225 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002226 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002227
Alexander Duyck08c88332011-06-11 01:45:03 +00002228 set_bit(t_idx, q_vector->tx.idx);
2229 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002230 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002231 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002232}
Auke Kok9a799d72007-09-15 14:07:45 -07002233
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002234/**
2235 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2236 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002237 *
2238 * This function maps descriptor rings to the queue-specific vectors
2239 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2240 * one vector per ring/queue, but on a constrained vector budget, we
2241 * group the rings as "efficiently" as possible. You would add new
2242 * mapping configurations in here.
2243 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002244static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002246 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247 int v_start = 0;
2248 int rxr_idx = 0, txr_idx = 0;
2249 int rxr_remaining = adapter->num_rx_queues;
2250 int txr_remaining = adapter->num_tx_queues;
2251 int i, j;
2252 int rqpv, tqpv;
2253 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002254
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002255 /* No mapping required if MSI-X is disabled. */
2256 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002257 goto out;
2258
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002259 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2260
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261 /*
2262 * The ideal configuration...
2263 * We have enough vectors to map one per queue.
2264 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002265 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002266 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2267 map_vector_to_rxq(adapter, v_start, rxr_idx);
2268
2269 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2270 map_vector_to_txq(adapter, v_start, txr_idx);
2271
2272 goto out;
2273 }
2274
2275 /*
2276 * If we don't have enough vectors for a 1-to-1
2277 * mapping, we'll have to group them so there are
2278 * multiple queues per vector.
2279 */
2280 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002281 for (i = v_start; i < q_vectors; i++) {
2282 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002283 for (j = 0; j < rqpv; j++) {
2284 map_vector_to_rxq(adapter, i, rxr_idx);
2285 rxr_idx++;
2286 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002287 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002288 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289 for (j = 0; j < tqpv; j++) {
2290 map_vector_to_txq(adapter, i, txr_idx);
2291 txr_idx++;
2292 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002293 }
Auke Kok9a799d72007-09-15 14:07:45 -07002294 }
Auke Kok9a799d72007-09-15 14:07:45 -07002295out:
Auke Kok9a799d72007-09-15 14:07:45 -07002296 return err;
2297}
2298
2299/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002300 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2301 * @adapter: board private structure
2302 *
2303 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2304 * interrupts from the kernel.
2305 **/
2306static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2307{
2308 struct net_device *netdev = adapter->netdev;
2309 irqreturn_t (*handler)(int, void *);
2310 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002311 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312
2313 /* Decrement for Other and TCP Timer vectors */
2314 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2315
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002316 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002317 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002318 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002319
Alexander Duyck08c88332011-06-11 01:45:03 +00002320#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002321 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002322 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2323 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002324 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002326 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2327 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002328
Joe Perchese8e9f692010-09-07 21:34:53 +00002329 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002330 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2331 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002332 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002333 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2334 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002335 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002336 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2337 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002338 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002339 } else {
2340 /* skip this unused q_vector */
2341 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002342 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002344 handler, 0, q_vector->name,
2345 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002347 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002348 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002349 goto free_queue_irqs;
2350 }
2351 }
2352
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002353 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002354 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002355 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002357 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002358 goto free_queue_irqs;
2359 }
2360
2361 return 0;
2362
2363free_queue_irqs:
2364 for (i = vector - 1; i >= 0; i--)
2365 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002366 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2368 pci_disable_msix(adapter->pdev);
2369 kfree(adapter->msix_entries);
2370 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002371 return err;
2372}
2373
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002374/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002375 * ixgbe_irq_enable - Enable default interrupt generation settings
2376 * @adapter: board private structure
2377 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002378static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2379 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002380{
2381 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002382
2383 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002384 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2385 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002386 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2387 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002388 switch (adapter->hw.mac.type) {
2389 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002390 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002391 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002392 mask |= IXGBE_EIMS_GPI_SDP1;
2393 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002394 if (adapter->num_vfs)
2395 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002396 break;
2397 default:
2398 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002399 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002400 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002401 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002402
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002403 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002404 if (queues)
2405 ixgbe_irq_enable_queues(adapter, ~0);
2406 if (flush)
2407 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002408
2409 if (adapter->num_vfs > 32) {
2410 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2411 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2412 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002413}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002414
2415/**
2416 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002417 * @irq: interrupt number
2418 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002419 **/
2420static irqreturn_t ixgbe_intr(int irq, void *data)
2421{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002422 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002423 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002424 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002425 u32 eicr;
2426
Don Skidmore54037502009-02-21 15:42:56 -08002427 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002428 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002429 * before the read of EICR.
2430 */
2431 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2432
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002433 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2434 * therefore no explict interrupt disable is necessary */
2435 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002436 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002437 /*
2438 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002439 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002440 * have disabled interrupts due to EIAM
2441 * finish the workaround of silicon errata on 82598. Unmask
2442 * the interrupt that we masked before the EICR read.
2443 */
2444 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2445 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002446 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002447 }
Auke Kok9a799d72007-09-15 14:07:45 -07002448
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002449 if (eicr & IXGBE_EICR_LSC)
2450 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002451
Alexander Duyckbd508172010-11-16 19:27:03 -08002452 switch (hw->mac.type) {
2453 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002454 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002455 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2456 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002457 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2458 adapter->interrupt_event = eicr;
2459 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2460 ixgbe_service_event_schedule(adapter);
2461 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002462 }
2463 break;
2464 default:
2465 break;
2466 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002467
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002468 ixgbe_check_fan_failure(adapter, eicr);
2469
Alexander Duyck7a921c92009-05-06 10:43:28 +00002470 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002471 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002472 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002473 }
2474
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002475 /*
2476 * re-enable link(maybe) and non-queue interrupts, no flush.
2477 * ixgbe_poll will re-enable the queue interrupts
2478 */
2479
2480 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2481 ixgbe_irq_enable(adapter, false, false);
2482
Auke Kok9a799d72007-09-15 14:07:45 -07002483 return IRQ_HANDLED;
2484}
2485
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002486static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2487{
2488 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2489
2490 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002491 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002492 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2493 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2494 q_vector->rx.count = 0;
2495 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002496 }
2497}
2498
Auke Kok9a799d72007-09-15 14:07:45 -07002499/**
2500 * ixgbe_request_irq - initialize interrupts
2501 * @adapter: board private structure
2502 *
2503 * Attempts to configure interrupts using the best available
2504 * capabilities of the hardware and kernel.
2505 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002506static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002507{
2508 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002509 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002510
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002511 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2512 err = ixgbe_request_msix_irqs(adapter);
2513 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002514 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002515 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002516 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002517 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002518 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002519 }
2520
Auke Kok9a799d72007-09-15 14:07:45 -07002521 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002522 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002523
Auke Kok9a799d72007-09-15 14:07:45 -07002524 return err;
2525}
2526
2527static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2528{
Auke Kok9a799d72007-09-15 14:07:45 -07002529 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002530 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002531
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 q_vectors = adapter->num_msix_vectors;
2533
2534 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002535 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002536
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002537 i--;
2538 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002539 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002540 if (!adapter->q_vector[i]->rx.count &&
2541 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002542 continue;
2543
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002544 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002545 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002546 }
2547
2548 ixgbe_reset_q_vectors(adapter);
2549 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002550 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002551 }
2552}
2553
2554/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002555 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2556 * @adapter: board private structure
2557 **/
2558static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2559{
Alexander Duyckbd508172010-11-16 19:27:03 -08002560 switch (adapter->hw.mac.type) {
2561 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002562 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002563 break;
2564 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002565 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002566 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002569 if (adapter->num_vfs > 32)
2570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002571 break;
2572 default:
2573 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002574 }
2575 IXGBE_WRITE_FLUSH(&adapter->hw);
2576 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2577 int i;
2578 for (i = 0; i < adapter->num_msix_vectors; i++)
2579 synchronize_irq(adapter->msix_entries[i].vector);
2580 } else {
2581 synchronize_irq(adapter->pdev->irq);
2582 }
2583}
2584
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002585/**
Auke Kok9a799d72007-09-15 14:07:45 -07002586 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2587 *
2588 **/
2589static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2590{
Auke Kok9a799d72007-09-15 14:07:45 -07002591 struct ixgbe_hw *hw = &adapter->hw;
2592
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002593 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002594 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002595
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002596 ixgbe_set_ivar(adapter, 0, 0, 0);
2597 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002598
2599 map_vector_to_rxq(adapter, 0, 0);
2600 map_vector_to_txq(adapter, 0, 0);
2601
Emil Tantilov396e7992010-07-01 20:05:12 +00002602 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002603}
2604
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002605/**
2606 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2607 * @adapter: board private structure
2608 * @ring: structure containing ring specific data
2609 *
2610 * Configure the Tx descriptor ring after a reset.
2611 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002612void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2613 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002614{
2615 struct ixgbe_hw *hw = &adapter->hw;
2616 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002617 int wait_loop = 10;
2618 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002619 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002620
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002621 /* disable queue to avoid issues while updating state */
2622 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2623 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2624 txdctl & ~IXGBE_TXDCTL_ENABLE);
2625 IXGBE_WRITE_FLUSH(hw);
2626
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002627 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002628 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002629 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2630 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2631 ring->count * sizeof(union ixgbe_adv_tx_desc));
2632 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2633 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002634 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002635
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002636 /* configure fetching thresholds */
2637 if (adapter->rx_itr_setting == 0) {
2638 /* cannot set wthresh when itr==0 */
2639 txdctl &= ~0x007F0000;
2640 } else {
2641 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2642 txdctl |= (8 << 16);
2643 }
2644 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2645 /* PThresh workaround for Tx hang with DFP enabled. */
2646 txdctl |= 32;
2647 }
2648
2649 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002650 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2651 adapter->atr_sample_rate) {
2652 ring->atr_sample_rate = adapter->atr_sample_rate;
2653 ring->atr_count = 0;
2654 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2655 } else {
2656 ring->atr_sample_rate = 0;
2657 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002658
John Fastabendc84d3242010-11-16 19:27:12 -08002659 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2660
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002661 /* enable queue */
2662 txdctl |= IXGBE_TXDCTL_ENABLE;
2663 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2664
2665 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2666 if (hw->mac.type == ixgbe_mac_82598EB &&
2667 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2668 return;
2669
2670 /* poll to verify queue is enabled */
2671 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002672 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002673 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2674 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2675 if (!wait_loop)
2676 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002677}
2678
Alexander Duyck120ff942010-08-19 13:34:50 +00002679static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2680{
2681 struct ixgbe_hw *hw = &adapter->hw;
2682 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002683 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002684 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002685
2686 if (hw->mac.type == ixgbe_mac_82598EB)
2687 return;
2688
2689 /* disable the arbiter while setting MTQC */
2690 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2691 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2692 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2693
2694 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002695 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002696 case (IXGBE_FLAG_SRIOV_ENABLED):
2697 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2698 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2699 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002700 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002701 if (!tcs)
2702 reg = IXGBE_MTQC_64Q_1PB;
2703 else if (tcs <= 4)
2704 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2705 else
2706 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2707
2708 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2709
2710 /* Enable Security TX Buffer IFG for multiple pb */
2711 if (tcs) {
2712 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2713 reg |= IXGBE_SECTX_DCB;
2714 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2715 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002716 break;
2717 }
2718
2719 /* re-enable the arbiter */
2720 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2721 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2722}
2723
Auke Kok9a799d72007-09-15 14:07:45 -07002724/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002725 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002726 * @adapter: board private structure
2727 *
2728 * Configure the Tx unit of the MAC after a reset.
2729 **/
2730static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2731{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002732 struct ixgbe_hw *hw = &adapter->hw;
2733 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002734 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002735
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002736 ixgbe_setup_mtqc(adapter);
2737
2738 if (hw->mac.type != ixgbe_mac_82598EB) {
2739 /* DMATXCTL.EN must be before Tx queues are enabled */
2740 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2741 dmatxctl |= IXGBE_DMATXCTL_TE;
2742 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2743 }
2744
Auke Kok9a799d72007-09-15 14:07:45 -07002745 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002746 for (i = 0; i < adapter->num_tx_queues; i++)
2747 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002748}
2749
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002750#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002751
Yi Zoua6616b42009-08-06 13:05:23 +00002752static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002753 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002754{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002755 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002756 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002757
Alexander Duyckbd508172010-11-16 19:27:03 -08002758 switch (adapter->hw.mac.type) {
2759 case ixgbe_mac_82598EB: {
2760 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2761 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002762 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002763 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002764 break;
2765 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002766 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002767 default:
2768 break;
2769 }
2770
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002771 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002772
2773 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2774 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002775 if (adapter->num_vfs)
2776 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002777
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002778 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2779 IXGBE_SRRCTL_BSIZEHDR_MASK;
2780
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002781 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002782#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2783 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2784#else
2785 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2786#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002787 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002788 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002789 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2790 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002791 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002792 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002793
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002794 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002795}
2796
Alexander Duyck05abb122010-08-19 13:35:41 +00002797static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002798{
Alexander Duyck05abb122010-08-19 13:35:41 +00002799 struct ixgbe_hw *hw = &adapter->hw;
2800 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002801 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2802 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002803 u32 mrqc = 0, reta = 0;
2804 u32 rxcsum;
2805 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002806 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002807 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2808
2809 if (tcs)
2810 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002811
Alexander Duyck05abb122010-08-19 13:35:41 +00002812 /* Fill out hash function seeds */
2813 for (i = 0; i < 10; i++)
2814 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002815
Alexander Duyck05abb122010-08-19 13:35:41 +00002816 /* Fill out redirection table */
2817 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002818 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002819 j = 0;
2820 /* reta = 4-byte sliding window of
2821 * 0x00..(indices-1)(indices-1)00..etc. */
2822 reta = (reta << 8) | (j * 0x11);
2823 if ((i & 3) == 3)
2824 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2825 }
2826
2827 /* Disable indicating checksum in descriptor, enables RSS hash */
2828 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2829 rxcsum |= IXGBE_RXCSUM_PCSD;
2830 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2831
John Fastabend8b1c0b22011-05-03 02:26:48 +00002832 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2833 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002834 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002835 } else {
2836 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2837 | IXGBE_FLAG_SRIOV_ENABLED);
2838
2839 switch (mask) {
2840 case (IXGBE_FLAG_RSS_ENABLED):
2841 if (!tcs)
2842 mrqc = IXGBE_MRQC_RSSEN;
2843 else if (tcs <= 4)
2844 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2845 else
2846 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2847 break;
2848 case (IXGBE_FLAG_SRIOV_ENABLED):
2849 mrqc = IXGBE_MRQC_VMDQEN;
2850 break;
2851 default:
2852 break;
2853 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002854 }
2855
Alexander Duyck05abb122010-08-19 13:35:41 +00002856 /* Perform hash on these packet types */
2857 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2858 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2859 | IXGBE_MRQC_RSS_FIELD_IPV6
2860 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2861
2862 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002863}
2864
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002865/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002866 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2867 * @adapter: address of board private structure
2868 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002869 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002870static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002871 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002872{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002873 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002874 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002875 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002876 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002877
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002878 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002879 return;
2880
2881 rx_buf_len = ring->rx_buf_len;
2882 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002883 rscctrl |= IXGBE_RSCCTL_RSCEN;
2884 /*
2885 * we must limit the number of descriptors so that the
2886 * total size of max desc * buf_len is not greater
2887 * than 65535
2888 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002889 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002890#if (MAX_SKB_FRAGS > 16)
2891 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2892#elif (MAX_SKB_FRAGS > 8)
2893 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2894#elif (MAX_SKB_FRAGS > 4)
2895 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2896#else
2897 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2898#endif
2899 } else {
2900 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2901 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2902 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2903 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2904 else
2905 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2906 }
Alexander Duyck73670962010-08-19 13:38:34 +00002907 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002908}
2909
Alexander Duyck9e10e042010-08-19 13:40:06 +00002910/**
2911 * ixgbe_set_uta - Set unicast filter table address
2912 * @adapter: board private structure
2913 *
2914 * The unicast table address is a register array of 32-bit registers.
2915 * The table is meant to be used in a way similar to how the MTA is used
2916 * however due to certain limitations in the hardware it is necessary to
2917 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2918 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2919 **/
2920static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2921{
2922 struct ixgbe_hw *hw = &adapter->hw;
2923 int i;
2924
2925 /* The UTA table only exists on 82599 hardware and newer */
2926 if (hw->mac.type < ixgbe_mac_82599EB)
2927 return;
2928
2929 /* we only need to do this if VMDq is enabled */
2930 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2931 return;
2932
2933 for (i = 0; i < 128; i++)
2934 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2935}
2936
2937#define IXGBE_MAX_RX_DESC_POLL 10
2938static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2939 struct ixgbe_ring *ring)
2940{
2941 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002942 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2943 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002944 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002945
2946 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2947 if (hw->mac.type == ixgbe_mac_82598EB &&
2948 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2949 return;
2950
2951 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002952 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002953 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2954 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2955
2956 if (!wait_loop) {
2957 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2958 "the polling period\n", reg_idx);
2959 }
2960}
2961
Yi Zou2d39d572011-01-06 14:29:56 +00002962void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2963 struct ixgbe_ring *ring)
2964{
2965 struct ixgbe_hw *hw = &adapter->hw;
2966 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2967 u32 rxdctl;
2968 u8 reg_idx = ring->reg_idx;
2969
2970 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2971 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2972
2973 /* write value back with RXDCTL.ENABLE bit cleared */
2974 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2975
2976 if (hw->mac.type == ixgbe_mac_82598EB &&
2977 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2978 return;
2979
2980 /* the hardware may take up to 100us to really disable the rx queue */
2981 do {
2982 udelay(10);
2983 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2984 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2985
2986 if (!wait_loop) {
2987 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2988 "the polling period\n", reg_idx);
2989 }
2990}
2991
Alexander Duyck84418e32010-08-19 13:40:54 +00002992void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2993 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002994{
2995 struct ixgbe_hw *hw = &adapter->hw;
2996 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002997 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002998 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00002999
Alexander Duyck9e10e042010-08-19 13:40:06 +00003000 /* disable queue to avoid issues while updating state */
3001 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003002 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003003
Alexander Duyckacd37172010-08-19 13:36:05 +00003004 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3005 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3006 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3007 ring->count * sizeof(union ixgbe_adv_rx_desc));
3008 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3009 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003010 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003011
3012 ixgbe_configure_srrctl(adapter, ring);
3013 ixgbe_configure_rscctl(adapter, ring);
3014
Greg Rosee9f98072011-01-26 01:06:07 +00003015 /* If operating in IOV mode set RLPML for X540 */
3016 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3017 hw->mac.type == ixgbe_mac_X540) {
3018 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3019 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3020 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3021 }
3022
Alexander Duyck9e10e042010-08-19 13:40:06 +00003023 if (hw->mac.type == ixgbe_mac_82598EB) {
3024 /*
3025 * enable cache line friendly hardware writes:
3026 * PTHRESH=32 descriptors (half the internal cache),
3027 * this also removes ugly rx_no_buffer_count increment
3028 * HTHRESH=4 descriptors (to minimize latency on fetch)
3029 * WTHRESH=8 burst writeback up to two cache lines
3030 */
3031 rxdctl &= ~0x3FFFFF;
3032 rxdctl |= 0x080420;
3033 }
3034
3035 /* enable receive descriptor ring */
3036 rxdctl |= IXGBE_RXDCTL_ENABLE;
3037 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3038
3039 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003040 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003041}
3042
Alexander Duyck48654522010-08-19 13:36:27 +00003043static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3044{
3045 struct ixgbe_hw *hw = &adapter->hw;
3046 int p;
3047
3048 /* PSRTYPE must be initialized in non 82598 adapters */
3049 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003050 IXGBE_PSRTYPE_UDPHDR |
3051 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003052 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003053 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003054
3055 if (hw->mac.type == ixgbe_mac_82598EB)
3056 return;
3057
3058 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3059 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3060
3061 for (p = 0; p < adapter->num_rx_pools; p++)
3062 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3063 psrtype);
3064}
3065
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003066static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3067{
3068 struct ixgbe_hw *hw = &adapter->hw;
3069 u32 gcr_ext;
3070 u32 vt_reg_bits;
3071 u32 reg_offset, vf_shift;
3072 u32 vmdctl;
3073
3074 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3075 return;
3076
3077 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3078 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3079 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3080 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3081
3082 vf_shift = adapter->num_vfs % 32;
3083 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3084
3085 /* Enable only the PF's pool for Tx/Rx */
3086 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3087 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3088 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3089 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3090 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3091
3092 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3093 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3094
3095 /*
3096 * Set up VF register offsets for selected VT Mode,
3097 * i.e. 32 or 64 VFs for SR-IOV
3098 */
3099 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3100 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3101 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3102 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3103
3104 /* enable Tx loopback for VF/PF communication */
3105 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003106 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003107 hw->mac.ops.set_mac_anti_spoofing(hw,
3108 (adapter->antispoofing_enabled =
3109 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003110 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003111}
3112
Alexander Duyck477de6e2010-08-19 13:38:11 +00003113static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003114{
Auke Kok9a799d72007-09-15 14:07:45 -07003115 struct ixgbe_hw *hw = &adapter->hw;
3116 struct net_device *netdev = adapter->netdev;
3117 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003118 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003119 struct ixgbe_ring *rx_ring;
3120 int i;
3121 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003122
Auke Kok9a799d72007-09-15 14:07:45 -07003123 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003124 /* On by default */
3125 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3126
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003127 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003128 if (adapter->num_vfs)
3129 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3130
3131 /* Disable packet split due to 82599 erratum #45 */
3132 if (hw->mac.type == ixgbe_mac_82599EB)
3133 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003134
3135 /* Set the RX buffer length according to the mode */
3136 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003137 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003138 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003139 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003140 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003141 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003142 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003143 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3144 }
3145
3146#ifdef IXGBE_FCOE
3147 /* adjust max frame to be able to do baby jumbo for FCoE */
3148 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3149 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3150 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3151
3152#endif /* IXGBE_FCOE */
3153 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3154 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3155 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3156 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3157
3158 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003159 }
3160
Auke Kok9a799d72007-09-15 14:07:45 -07003161 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003162 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3163 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003164 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3165
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003166 /*
3167 * Setup the HW Rx Head and Tail Descriptor Pointers and
3168 * the Base and Length of the Rx Descriptor Ring
3169 */
Auke Kok9a799d72007-09-15 14:07:45 -07003170 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003171 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003172 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003173
Yi Zou6e455b892009-08-06 13:05:44 +00003174 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003175 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003176 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003177 clear_ring_ps_enabled(rx_ring);
3178
3179 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3180 set_ring_rsc_enabled(rx_ring);
3181 else
3182 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003183
Yi Zou63f39bd2009-05-17 12:34:35 +00003184#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003185 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003186 struct ixgbe_ring_feature *f;
3187 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003188 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003189 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003190 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3191 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003192 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003193 } else if (!ring_is_rsc_enabled(rx_ring) &&
3194 !ring_is_ps_enabled(rx_ring)) {
3195 rx_ring->rx_buf_len =
3196 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003197 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003198 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003199#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003200 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003201}
3202
Alexander Duyck73670962010-08-19 13:38:34 +00003203static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3204{
3205 struct ixgbe_hw *hw = &adapter->hw;
3206 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3207
3208 switch (hw->mac.type) {
3209 case ixgbe_mac_82598EB:
3210 /*
3211 * For VMDq support of different descriptor types or
3212 * buffer sizes through the use of multiple SRRCTL
3213 * registers, RDRXCTL.MVMEN must be set to 1
3214 *
3215 * also, the manual doesn't mention it clearly but DCA hints
3216 * will only use queue 0's tags unless this bit is set. Side
3217 * effects of setting this bit are only that SRRCTL must be
3218 * fully programmed [0..15]
3219 */
3220 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3221 break;
3222 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003223 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003224 /* Disable RSC for ACK packets */
3225 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3226 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3227 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3228 /* hardware requires some bits to be set by default */
3229 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3230 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3231 break;
3232 default:
3233 /* We should do nothing since we don't know this hardware */
3234 return;
3235 }
3236
3237 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3238}
3239
Alexander Duyck477de6e2010-08-19 13:38:11 +00003240/**
3241 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3242 * @adapter: board private structure
3243 *
3244 * Configure the Rx unit of the MAC after a reset.
3245 **/
3246static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3247{
3248 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003249 int i;
3250 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003251
3252 /* disable receives while setting up the descriptors */
3253 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3254 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3255
3256 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003257 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003258
Alexander Duyck9e10e042010-08-19 13:40:06 +00003259 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003260 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003261
Alexander Duyck9e10e042010-08-19 13:40:06 +00003262 ixgbe_set_uta(adapter);
3263
Alexander Duyck477de6e2010-08-19 13:38:11 +00003264 /* set_rx_buffer_len must be called before ring initialization */
3265 ixgbe_set_rx_buffer_len(adapter);
3266
3267 /*
3268 * Setup the HW Rx Head and Tail Descriptor Pointers and
3269 * the Base and Length of the Rx Descriptor Ring
3270 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003271 for (i = 0; i < adapter->num_rx_queues; i++)
3272 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003273
Alexander Duyck9e10e042010-08-19 13:40:06 +00003274 /* disable drop enable for 82598 parts */
3275 if (hw->mac.type == ixgbe_mac_82598EB)
3276 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3277
3278 /* enable all receives */
3279 rxctrl |= IXGBE_RXCTRL_RXEN;
3280 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003281}
3282
Auke Kok9a799d72007-09-15 14:07:45 -07003283static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3284{
3285 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003286 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003287 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003288
3289 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003290 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003291 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003292}
3293
3294static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3295{
3296 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003297 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003298 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003299
Auke Kok9a799d72007-09-15 14:07:45 -07003300 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003301 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003302 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003303}
3304
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003305/**
3306 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3307 * @adapter: driver data
3308 */
3309static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3310{
3311 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003312 u32 vlnctrl;
3313
3314 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3315 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3316 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3317}
3318
3319/**
3320 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3321 * @adapter: driver data
3322 */
3323static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3324{
3325 struct ixgbe_hw *hw = &adapter->hw;
3326 u32 vlnctrl;
3327
3328 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3329 vlnctrl |= IXGBE_VLNCTRL_VFE;
3330 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3331 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3332}
3333
3334/**
3335 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3336 * @adapter: driver data
3337 */
3338static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3339{
3340 struct ixgbe_hw *hw = &adapter->hw;
3341 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003342 int i, j;
3343
3344 switch (hw->mac.type) {
3345 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003346 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3347 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003348 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3349 break;
3350 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003351 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003352 for (i = 0; i < adapter->num_rx_queues; i++) {
3353 j = adapter->rx_ring[i]->reg_idx;
3354 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3355 vlnctrl &= ~IXGBE_RXDCTL_VME;
3356 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3357 }
3358 break;
3359 default:
3360 break;
3361 }
3362}
3363
3364/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003365 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003366 * @adapter: driver data
3367 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003368static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003369{
3370 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003371 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003372 int i, j;
3373
3374 switch (hw->mac.type) {
3375 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003376 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3377 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003378 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3379 break;
3380 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003381 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003382 for (i = 0; i < adapter->num_rx_queues; i++) {
3383 j = adapter->rx_ring[i]->reg_idx;
3384 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3385 vlnctrl |= IXGBE_RXDCTL_VME;
3386 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3387 }
3388 break;
3389 default:
3390 break;
3391 }
3392}
3393
Auke Kok9a799d72007-09-15 14:07:45 -07003394static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3395{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003396 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003397
Jesse Grossf62bbb52010-10-20 13:56:10 +00003398 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3399
3400 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3401 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003402}
3403
3404/**
Alexander Duyck28500622010-06-15 09:25:48 +00003405 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3406 * @netdev: network interface device structure
3407 *
3408 * Writes unicast address list to the RAR table.
3409 * Returns: -ENOMEM on failure/insufficient address space
3410 * 0 on no addresses written
3411 * X on writing X addresses to the RAR table
3412 **/
3413static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3414{
3415 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3416 struct ixgbe_hw *hw = &adapter->hw;
3417 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003418 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003419 int count = 0;
3420
3421 /* return ENOMEM indicating insufficient memory for addresses */
3422 if (netdev_uc_count(netdev) > rar_entries)
3423 return -ENOMEM;
3424
3425 if (!netdev_uc_empty(netdev) && rar_entries) {
3426 struct netdev_hw_addr *ha;
3427 /* return error if we do not support writing to RAR table */
3428 if (!hw->mac.ops.set_rar)
3429 return -ENOMEM;
3430
3431 netdev_for_each_uc_addr(ha, netdev) {
3432 if (!rar_entries)
3433 break;
3434 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3435 vfn, IXGBE_RAH_AV);
3436 count++;
3437 }
3438 }
3439 /* write the addresses in reverse order to avoid write combining */
3440 for (; rar_entries > 0 ; rar_entries--)
3441 hw->mac.ops.clear_rar(hw, rar_entries);
3442
3443 return count;
3444}
3445
3446/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003447 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003448 * @netdev: network interface device structure
3449 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003450 * The set_rx_method entry point is called whenever the unicast/multicast
3451 * address list or the network interface flags are updated. This routine is
3452 * responsible for configuring the hardware for proper unicast, multicast and
3453 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003454 **/
Greg Rose7f870472010-01-09 02:25:29 +00003455void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003456{
3457 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3458 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003459 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3460 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003461
3462 /* Check for Promiscuous and All Multicast modes */
3463
3464 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3465
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003466 /* set all bits that we expect to always be set */
3467 fctrl |= IXGBE_FCTRL_BAM;
3468 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3469 fctrl |= IXGBE_FCTRL_PMCF;
3470
Alexander Duyck28500622010-06-15 09:25:48 +00003471 /* clear the bits we are changing the status of */
3472 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3473
Auke Kok9a799d72007-09-15 14:07:45 -07003474 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003475 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003476 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003477 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003478 /* don't hardware filter vlans in promisc mode */
3479 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003480 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003481 if (netdev->flags & IFF_ALLMULTI) {
3482 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003483 vmolr |= IXGBE_VMOLR_MPE;
3484 } else {
3485 /*
3486 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003487 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003488 * that we can at least receive multicast traffic
3489 */
3490 hw->mac.ops.update_mc_addr_list(hw, netdev);
3491 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003492 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003493 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003494 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003495 /*
3496 * Write addresses to available RAR registers, if there is not
3497 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003498 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003499 */
3500 count = ixgbe_write_uc_addr_list(netdev);
3501 if (count < 0) {
3502 fctrl |= IXGBE_FCTRL_UPE;
3503 vmolr |= IXGBE_VMOLR_ROPE;
3504 }
3505 }
3506
3507 if (adapter->num_vfs) {
3508 ixgbe_restore_vf_multicasts(adapter);
3509 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3510 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3511 IXGBE_VMOLR_ROPE);
3512 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003513 }
3514
3515 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003516
3517 if (netdev->features & NETIF_F_HW_VLAN_RX)
3518 ixgbe_vlan_strip_enable(adapter);
3519 else
3520 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003521}
3522
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003523static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3524{
3525 int q_idx;
3526 struct ixgbe_q_vector *q_vector;
3527 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3528
3529 /* legacy and MSI only use one vector */
3530 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3531 q_vectors = 1;
3532
3533 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003534 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003535 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003536 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003537 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003538 if (!q_vector->rx.count || !q_vector->tx.count) {
3539 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003540 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003541 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003542 napi->poll = &ixgbe_clean_rxonly;
3543 }
3544 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003545
3546 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003547 }
3548}
3549
3550static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3551{
3552 int q_idx;
3553 struct ixgbe_q_vector *q_vector;
3554 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3555
3556 /* legacy and MSI only use one vector */
3557 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3558 q_vectors = 1;
3559
3560 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003561 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003562 napi_disable(&q_vector->napi);
3563 }
3564}
3565
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003566#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003567/*
3568 * ixgbe_configure_dcb - Configure DCB hardware
3569 * @adapter: ixgbe adapter struct
3570 *
3571 * This is called by the driver on open to configure the DCB hardware.
3572 * This is also called by the gennetlink interface when reconfiguring
3573 * the DCB state.
3574 */
3575static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3576{
3577 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003578 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003579
Alexander Duyck67ebd792010-08-19 13:34:04 +00003580 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3581 if (hw->mac.type == ixgbe_mac_82598EB)
3582 netif_set_gso_max_size(adapter->netdev, 65536);
3583 return;
3584 }
3585
3586 if (hw->mac.type == ixgbe_mac_82598EB)
3587 netif_set_gso_max_size(adapter->netdev, 32768);
3588
Alexander Duyck2f90b862008-11-20 20:52:10 -08003589
Alexander Duyck2f90b862008-11-20 20:52:10 -08003590 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003591 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003592
Alexander Duyck2f90b862008-11-20 20:52:10 -08003593 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003594
3595 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003596 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003597#ifdef CONFIG_FCOE
3598 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3599 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3600#endif
3601 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3602 DCB_TX_CONFIG);
3603 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3604 DCB_RX_CONFIG);
3605 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3606 } else {
3607 struct net_device *dev = adapter->netdev;
3608
3609 if (adapter->ixgbe_ieee_ets)
3610 dev->dcbnl_ops->ieee_setets(dev,
3611 adapter->ixgbe_ieee_ets);
3612 if (adapter->ixgbe_ieee_pfc)
3613 dev->dcbnl_ops->ieee_setpfc(dev,
3614 adapter->ixgbe_ieee_pfc);
3615 }
John Fastabend8187cd42011-02-23 05:58:08 +00003616
3617 /* Enable RSS Hash per TC */
3618 if (hw->mac.type != ixgbe_mac_82598EB) {
3619 int i;
3620 u32 reg = 0;
3621
3622 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3623 u8 msb = 0;
3624 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3625
3626 while (cnt >>= 1)
3627 msb++;
3628
3629 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3630 }
3631 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3632 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003633}
3634
3635#endif
John Fastabend80605c652011-05-02 12:34:10 +00003636
3637static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3638{
3639 int hdrm = 0;
3640 int num_tc = netdev_get_num_tc(adapter->netdev);
3641 struct ixgbe_hw *hw = &adapter->hw;
3642
3643 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3644 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3645 hdrm = 64 << adapter->fdir_pballoc;
3646
3647 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3648}
3649
Alexander Duycke4911d52011-05-11 07:18:52 +00003650static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3651{
3652 struct ixgbe_hw *hw = &adapter->hw;
3653 struct hlist_node *node, *node2;
3654 struct ixgbe_fdir_filter *filter;
3655
3656 spin_lock(&adapter->fdir_perfect_lock);
3657
3658 if (!hlist_empty(&adapter->fdir_filter_list))
3659 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3660
3661 hlist_for_each_entry_safe(filter, node, node2,
3662 &adapter->fdir_filter_list, fdir_node) {
3663 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003664 &filter->filter,
3665 filter->sw_idx,
3666 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3667 IXGBE_FDIR_DROP_QUEUE :
3668 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003669 }
3670
3671 spin_unlock(&adapter->fdir_perfect_lock);
3672}
3673
Auke Kok9a799d72007-09-15 14:07:45 -07003674static void ixgbe_configure(struct ixgbe_adapter *adapter)
3675{
3676 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003677 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003678 int i;
3679
John Fastabend80605c652011-05-02 12:34:10 +00003680 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003681#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003682 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003683#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003684
Jesse Grossf62bbb52010-10-20 13:56:10 +00003685 ixgbe_set_rx_mode(netdev);
3686 ixgbe_restore_vlan(adapter);
3687
Yi Zoueacd73f2009-05-13 13:11:06 +00003688#ifdef IXGBE_FCOE
3689 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3690 ixgbe_configure_fcoe(adapter);
3691
3692#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003693 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3694 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003695 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003696 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003697 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003698 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3699 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3700 adapter->fdir_pballoc);
3701 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003702 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003703 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003704
Auke Kok9a799d72007-09-15 14:07:45 -07003705 ixgbe_configure_tx(adapter);
3706 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003707}
3708
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003709static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3710{
3711 switch (hw->phy.type) {
3712 case ixgbe_phy_sfp_avago:
3713 case ixgbe_phy_sfp_ftl:
3714 case ixgbe_phy_sfp_intel:
3715 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003716 case ixgbe_phy_sfp_passive_tyco:
3717 case ixgbe_phy_sfp_passive_unknown:
3718 case ixgbe_phy_sfp_active_unknown:
3719 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003720 return true;
3721 default:
3722 return false;
3723 }
3724}
3725
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003726/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003727 * ixgbe_sfp_link_config - set up SFP+ link
3728 * @adapter: pointer to private adapter struct
3729 **/
3730static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3731{
Alexander Duyck70864002011-04-27 09:13:56 +00003732 /*
3733 * We are assuming the worst case scenerio here, and that
3734 * is that an SFP was inserted/removed after the reset
3735 * but before SFP detection was enabled. As such the best
3736 * solution is to just start searching as soon as we start
3737 */
3738 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3739 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003740
Alexander Duyck70864002011-04-27 09:13:56 +00003741 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003742}
3743
3744/**
3745 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003746 * @hw: pointer to private hardware struct
3747 *
3748 * Returns 0 on success, negative on failure
3749 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003750static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003751{
3752 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003753 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003754 u32 ret = IXGBE_ERR_LINK_SETUP;
3755
3756 if (hw->mac.ops.check_link)
3757 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3758
3759 if (ret)
3760 goto link_cfg_out;
3761
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003762 autoneg = hw->phy.autoneg_advertised;
3763 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003764 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3765 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003766 if (ret)
3767 goto link_cfg_out;
3768
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003769 if (hw->mac.ops.setup_link)
3770 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003771link_cfg_out:
3772 return ret;
3773}
3774
Alexander Duycka34bcff2010-08-19 13:39:20 +00003775static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003776{
Auke Kok9a799d72007-09-15 14:07:45 -07003777 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003778 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003779
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003780 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003781 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3782 IXGBE_GPIE_OCD;
3783 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003784 /*
3785 * use EIAM to auto-mask when MSI-X interrupt is asserted
3786 * this saves a register write for every interrupt
3787 */
3788 switch (hw->mac.type) {
3789 case ixgbe_mac_82598EB:
3790 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3791 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003792 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003793 case ixgbe_mac_X540:
3794 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003795 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3796 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3797 break;
3798 }
3799 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003800 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3801 * specifically only auto mask tx and rx interrupts */
3802 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003803 }
3804
Alexander Duycka34bcff2010-08-19 13:39:20 +00003805 /* XXX: to interrupt immediately for EICS writes, enable this */
3806 /* gpie |= IXGBE_GPIE_EIMEN; */
3807
3808 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3809 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3810 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003811 }
3812
Alexander Duycka34bcff2010-08-19 13:39:20 +00003813 /* Enable fan failure interrupt */
3814 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003815 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003816
Don Skidmore2698b202011-04-13 07:01:52 +00003817 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003818 gpie |= IXGBE_SDP1_GPIEN;
3819 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003820 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003821
3822 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3823}
3824
3825static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3826{
3827 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003828 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003829 u32 ctrl_ext;
3830
3831 ixgbe_get_hw_control(adapter);
3832 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003833
Auke Kok9a799d72007-09-15 14:07:45 -07003834 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3835 ixgbe_configure_msix(adapter);
3836 else
3837 ixgbe_configure_msi_and_legacy(adapter);
3838
Don Skidmorec6ecf392010-12-03 03:31:51 +00003839 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3840 if (hw->mac.ops.enable_tx_laser &&
3841 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003842 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003843 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003844 hw->mac.ops.enable_tx_laser(hw);
3845
Auke Kok9a799d72007-09-15 14:07:45 -07003846 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003847 ixgbe_napi_enable_all(adapter);
3848
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003849 if (ixgbe_is_sfp(hw)) {
3850 ixgbe_sfp_link_config(adapter);
3851 } else {
3852 err = ixgbe_non_sfp_link_config(hw);
3853 if (err)
3854 e_err(probe, "link_config FAILED %d\n", err);
3855 }
3856
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003857 /* clear any pending interrupts, may auto mask */
3858 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003859 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003860
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003861 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003862 * If this adapter has a fan, check to see if we had a failure
3863 * before we enabled the interrupt.
3864 */
3865 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3866 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3867 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003868 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003869 }
3870
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003871 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003872 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003873
Auke Kok9a799d72007-09-15 14:07:45 -07003874 /* bring the link up in the watchdog, this could race with our first
3875 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003876 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3877 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003878 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003879
3880 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3881 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3882 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3883 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3884
Auke Kok9a799d72007-09-15 14:07:45 -07003885 return 0;
3886}
3887
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003888void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3889{
3890 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003891 /* put off any impending NetWatchDogTimeout */
3892 adapter->netdev->trans_start = jiffies;
3893
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003894 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003895 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003896 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003897 /*
3898 * If SR-IOV enabled then wait a bit before bringing the adapter
3899 * back up to give the VFs time to respond to the reset. The
3900 * two second wait is based upon the watchdog timer cycle in
3901 * the VF driver.
3902 */
3903 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3904 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003905 ixgbe_up(adapter);
3906 clear_bit(__IXGBE_RESETTING, &adapter->state);
3907}
3908
Auke Kok9a799d72007-09-15 14:07:45 -07003909int ixgbe_up(struct ixgbe_adapter *adapter)
3910{
3911 /* hardware has been reset, we need to reload some things */
3912 ixgbe_configure(adapter);
3913
3914 return ixgbe_up_complete(adapter);
3915}
3916
3917void ixgbe_reset(struct ixgbe_adapter *adapter)
3918{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003919 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003920 int err;
3921
Alexander Duyck70864002011-04-27 09:13:56 +00003922 /* lock SFP init bit to prevent race conditions with the watchdog */
3923 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3924 usleep_range(1000, 2000);
3925
3926 /* clear all SFP and link config related flags while holding SFP_INIT */
3927 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3928 IXGBE_FLAG2_SFP_NEEDS_RESET);
3929 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3930
Don Skidmore8ca783a2009-05-26 20:40:47 -07003931 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003932 switch (err) {
3933 case 0:
3934 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003935 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003936 break;
3937 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003938 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003939 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003940 case IXGBE_ERR_EEPROM_VERSION:
3941 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003942 e_dev_warn("This device is a pre-production adapter/LOM. "
3943 "Please be aware there may be issuesassociated with "
3944 "your hardware. If you are experiencing problems "
3945 "please contact your Intel or hardware "
3946 "representative who provided you with this "
3947 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003948 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003949 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003950 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003951 }
Auke Kok9a799d72007-09-15 14:07:45 -07003952
Alexander Duyck70864002011-04-27 09:13:56 +00003953 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3954
Auke Kok9a799d72007-09-15 14:07:45 -07003955 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003956 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3957 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003958}
3959
Auke Kok9a799d72007-09-15 14:07:45 -07003960/**
3961 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003962 * @rx_ring: ring to free buffers from
3963 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003964static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003965{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003966 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003967 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003968 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003969
Alexander Duyck84418e32010-08-19 13:40:54 +00003970 /* ring already cleared, nothing to do */
3971 if (!rx_ring->rx_buffer_info)
3972 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003973
Alexander Duyck84418e32010-08-19 13:40:54 +00003974 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003975 for (i = 0; i < rx_ring->count; i++) {
3976 struct ixgbe_rx_buffer *rx_buffer_info;
3977
3978 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3979 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003980 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003981 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003982 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003983 rx_buffer_info->dma = 0;
3984 }
3985 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00003986 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07003987 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003988 do {
3989 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003990 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003991 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00003992 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003993 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003994 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003995 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003996 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003997 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00003998 skb = skb->prev;
3999 dev_kfree_skb(this);
4000 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004001 }
4002 if (!rx_buffer_info->page)
4003 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004004 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004005 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004006 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004007 rx_buffer_info->page_dma = 0;
4008 }
Auke Kok9a799d72007-09-15 14:07:45 -07004009 put_page(rx_buffer_info->page);
4010 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004011 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004012 }
4013
4014 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4015 memset(rx_ring->rx_buffer_info, 0, size);
4016
4017 /* Zero out the descriptor ring */
4018 memset(rx_ring->desc, 0, rx_ring->size);
4019
4020 rx_ring->next_to_clean = 0;
4021 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004022}
4023
4024/**
4025 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004026 * @tx_ring: ring to be cleaned
4027 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004028static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004029{
4030 struct ixgbe_tx_buffer *tx_buffer_info;
4031 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004032 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004033
Alexander Duyck84418e32010-08-19 13:40:54 +00004034 /* ring already cleared, nothing to do */
4035 if (!tx_ring->tx_buffer_info)
4036 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004037
Alexander Duyck84418e32010-08-19 13:40:54 +00004038 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004039 for (i = 0; i < tx_ring->count; i++) {
4040 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004041 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004042 }
4043
4044 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4045 memset(tx_ring->tx_buffer_info, 0, size);
4046
4047 /* Zero out the descriptor ring */
4048 memset(tx_ring->desc, 0, tx_ring->size);
4049
4050 tx_ring->next_to_use = 0;
4051 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004052}
4053
4054/**
Auke Kok9a799d72007-09-15 14:07:45 -07004055 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4056 * @adapter: board private structure
4057 **/
4058static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4059{
4060 int i;
4061
4062 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004063 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004064}
4065
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004066/**
4067 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4068 * @adapter: board private structure
4069 **/
4070static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4071{
4072 int i;
4073
4074 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004075 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004076}
4077
Alexander Duycke4911d52011-05-11 07:18:52 +00004078static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4079{
4080 struct hlist_node *node, *node2;
4081 struct ixgbe_fdir_filter *filter;
4082
4083 spin_lock(&adapter->fdir_perfect_lock);
4084
4085 hlist_for_each_entry_safe(filter, node, node2,
4086 &adapter->fdir_filter_list, fdir_node) {
4087 hlist_del(&filter->fdir_node);
4088 kfree(filter);
4089 }
4090 adapter->fdir_filter_count = 0;
4091
4092 spin_unlock(&adapter->fdir_perfect_lock);
4093}
4094
Auke Kok9a799d72007-09-15 14:07:45 -07004095void ixgbe_down(struct ixgbe_adapter *adapter)
4096{
4097 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004098 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004099 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004100 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004101 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004102
4103 /* signal that we are down to the interrupt handler */
4104 set_bit(__IXGBE_DOWN, &adapter->state);
4105
4106 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004107 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4108 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004109
Yi Zou2d39d572011-01-06 14:29:56 +00004110 /* disable all enabled rx queues */
4111 for (i = 0; i < adapter->num_rx_queues; i++)
4112 /* this call also flushes the previous write */
4113 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4114
Don Skidmore032b4322011-03-18 09:32:53 +00004115 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004116
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004117 netif_tx_stop_all_queues(netdev);
4118
Alexander Duyck70864002011-04-27 09:13:56 +00004119 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004120 netif_carrier_off(netdev);
4121 netif_tx_disable(netdev);
4122
4123 ixgbe_irq_disable(adapter);
4124
4125 ixgbe_napi_disable_all(adapter);
4126
Alexander Duyckd034acf2011-04-27 09:25:34 +00004127 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4128 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004129 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4130
4131 del_timer_sync(&adapter->service_timer);
4132
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004133 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004134 if (adapter->num_vfs) {
4135 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004136 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004137
Auke Kok9a799d72007-09-15 14:07:45 -07004138 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004139 ixgbe_disable_tx_rx(adapter);
4140
4141 /* Mark all the VFs as inactive */
4142 for (i = 0 ; i < adapter->num_vfs; i++)
4143 adapter->vfinfo[i].clear_to_send = 0;
4144 }
4145
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004146 /* Cleanup the affinity_hint CPU mask memory and callback */
4147 for (i = 0; i < num_q_vectors; i++) {
4148 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4149 /* clear the affinity_mask in the IRQ descriptor */
4150 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4151 /* release the CPU mask memory */
4152 free_cpumask_var(q_vector->affinity_mask);
4153 }
4154
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004155 /* disable transmits in the hardware now that interrupts are off */
4156 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004157 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004158 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004159 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004160
4161 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004162 switch (hw->mac.type) {
4163 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004164 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004165 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004166 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4167 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004168 break;
4169 default:
4170 break;
4171 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004172
Paul Larson6f4a0e42008-06-24 17:00:56 -07004173 if (!pci_channel_offline(adapter->pdev))
4174 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004175
4176 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4177 if (hw->mac.ops.disable_tx_laser &&
4178 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004179 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004180 (hw->mac.type == ixgbe_mac_82599EB))))
4181 hw->mac.ops.disable_tx_laser(hw);
4182
Auke Kok9a799d72007-09-15 14:07:45 -07004183 ixgbe_clean_all_tx_rings(adapter);
4184 ixgbe_clean_all_rx_rings(adapter);
4185
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004186#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004187 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004188 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004189#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004190}
4191
Auke Kok9a799d72007-09-15 14:07:45 -07004192/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004193 * ixgbe_poll - NAPI Rx polling callback
4194 * @napi: structure for representing this polling device
4195 * @budget: how many packets driver is allowed to clean
4196 *
4197 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004198 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004199static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004200{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004201 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004202 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004203 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004204 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004205
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004206#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004207 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4208 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004209#endif
4210
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004211 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4212 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004213
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004214 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004215 work_done = budget;
4216
David S. Miller53e52c72008-01-07 21:06:12 -08004217 /* If budget not fully consumed, exit the polling mode */
4218 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004219 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004220 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004221 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004222 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004223 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004224 }
Auke Kok9a799d72007-09-15 14:07:45 -07004225 return work_done;
4226}
4227
4228/**
4229 * ixgbe_tx_timeout - Respond to a Tx Hang
4230 * @netdev: network interface device structure
4231 **/
4232static void ixgbe_tx_timeout(struct net_device *netdev)
4233{
4234 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4235
4236 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004237 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004238}
4239
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004240/**
4241 * ixgbe_set_rss_queues: Allocate queues for RSS
4242 * @adapter: board private structure to initialize
4243 *
4244 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4245 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4246 *
4247 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004248static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4249{
4250 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004251 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004252
4253 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004254 f->mask = 0xF;
4255 adapter->num_rx_queues = f->indices;
4256 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004257 ret = true;
4258 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004259 ret = false;
4260 }
4261
4262 return ret;
4263}
4264
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004265/**
4266 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4267 * @adapter: board private structure to initialize
4268 *
4269 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4270 * to the original CPU that initiated the Tx session. This runs in addition
4271 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4272 * Rx load across CPUs using RSS.
4273 *
4274 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004275static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004276{
4277 bool ret = false;
4278 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4279
4280 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4281 f_fdir->mask = 0;
4282
4283 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004284 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4285 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004286 adapter->num_tx_queues = f_fdir->indices;
4287 adapter->num_rx_queues = f_fdir->indices;
4288 ret = true;
4289 } else {
4290 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004291 }
4292 return ret;
4293}
4294
Yi Zou0331a832009-05-17 12:33:52 +00004295#ifdef IXGBE_FCOE
4296/**
4297 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4298 * @adapter: board private structure to initialize
4299 *
4300 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4301 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4302 * rx queues out of the max number of rx queues, instead, it is used as the
4303 * index of the first rx queue used by FCoE.
4304 *
4305 **/
4306static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4307{
Yi Zou0331a832009-05-17 12:33:52 +00004308 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4309
John Fastabende5b64632011-03-08 03:44:52 +00004310 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4311 return false;
4312
John Fastabende901acd2011-04-26 07:26:08 +00004313 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004314
John Fastabende901acd2011-04-26 07:26:08 +00004315 adapter->num_rx_queues = 1;
4316 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004317
John Fastabende901acd2011-04-26 07:26:08 +00004318 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4319 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004320 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004321 ixgbe_set_fdir_queues(adapter);
4322 else
4323 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004324 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004325
John Fastabende901acd2011-04-26 07:26:08 +00004326 /* adding FCoE rx rings to the end */
4327 f->mask = adapter->num_rx_queues;
4328 adapter->num_rx_queues += f->indices;
4329 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004330
John Fastabende5b64632011-03-08 03:44:52 +00004331 return true;
4332}
4333#endif /* IXGBE_FCOE */
4334
John Fastabende901acd2011-04-26 07:26:08 +00004335/* Artificial max queue cap per traffic class in DCB mode */
4336#define DCB_QUEUE_CAP 8
4337
John Fastabende5b64632011-03-08 03:44:52 +00004338#ifdef CONFIG_IXGBE_DCB
4339static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4340{
John Fastabende901acd2011-04-26 07:26:08 +00004341 int per_tc_q, q, i, offset = 0;
4342 struct net_device *dev = adapter->netdev;
4343 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004344
John Fastabende901acd2011-04-26 07:26:08 +00004345 if (!tcs)
4346 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004347
John Fastabende901acd2011-04-26 07:26:08 +00004348 /* Map queue offset and counts onto allocated tx queues */
4349 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4350 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004351
John Fastabend8b1c0b22011-05-03 02:26:48 +00004352 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004353 netdev_set_prio_tc_map(dev, i, i);
4354 netdev_set_tc_queue(dev, i, q, offset);
4355 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004356 }
4357
John Fastabende901acd2011-04-26 07:26:08 +00004358 adapter->num_tx_queues = q * tcs;
4359 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004360
4361#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004362 /* FCoE enabled queues require special configuration indexed
4363 * by feature specific indices and mask. Here we map FCoE
4364 * indices onto the DCB queue pairs allowing FCoE to own
4365 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004366 */
John Fastabende901acd2011-04-26 07:26:08 +00004367 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4368 int tc;
4369 struct ixgbe_ring_feature *f =
4370 &adapter->ring_feature[RING_F_FCOE];
4371
4372 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4373 f->indices = dev->tc_to_txq[tc].count;
4374 f->mask = dev->tc_to_txq[tc].offset;
4375 }
John Fastabende5b64632011-03-08 03:44:52 +00004376#endif
4377
John Fastabende901acd2011-04-26 07:26:08 +00004378 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004379}
John Fastabende5b64632011-03-08 03:44:52 +00004380#endif
Yi Zou0331a832009-05-17 12:33:52 +00004381
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004382/**
4383 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4384 * @adapter: board private structure to initialize
4385 *
4386 * IOV doesn't actually use anything, so just NAK the
4387 * request for now and let the other queue routines
4388 * figure out what to do.
4389 */
4390static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4391{
4392 return false;
4393}
4394
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004395/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004396 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004397 * @adapter: board private structure to initialize
4398 *
4399 * This is the top level queue allocation routine. The order here is very
4400 * important, starting with the "most" number of features turned on at once,
4401 * and ending with the smallest set of features. This way large combinations
4402 * can be allocated if they're turned on, and smaller combinations are the
4403 * fallthrough conditions.
4404 *
4405 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004406static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004407{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004408 /* Start with base case */
4409 adapter->num_rx_queues = 1;
4410 adapter->num_tx_queues = 1;
4411 adapter->num_rx_pools = adapter->num_rx_queues;
4412 adapter->num_rx_queues_per_pool = 1;
4413
4414 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004415 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004416
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004417#ifdef CONFIG_IXGBE_DCB
4418 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004419 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004420
4421#endif
John Fastabende5b64632011-03-08 03:44:52 +00004422#ifdef IXGBE_FCOE
4423 if (ixgbe_set_fcoe_queues(adapter))
4424 goto done;
4425
4426#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004427 if (ixgbe_set_fdir_queues(adapter))
4428 goto done;
4429
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004430 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004431 goto done;
4432
4433 /* fallback to base case */
4434 adapter->num_rx_queues = 1;
4435 adapter->num_tx_queues = 1;
4436
4437done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004438 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004439 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004440 return netif_set_real_num_rx_queues(adapter->netdev,
4441 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004442}
4443
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004444static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004445 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004446{
4447 int err, vector_threshold;
4448
4449 /* We'll want at least 3 (vector_threshold):
4450 * 1) TxQ[0] Cleanup
4451 * 2) RxQ[0] Cleanup
4452 * 3) Other (Link Status Change, etc.)
4453 * 4) TCP Timer (optional)
4454 */
4455 vector_threshold = MIN_MSIX_COUNT;
4456
4457 /* The more we get, the more we will assign to Tx/Rx Cleanup
4458 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4459 * Right now, we simply care about how many we'll get; we'll
4460 * set them up later while requesting irq's.
4461 */
4462 while (vectors >= vector_threshold) {
4463 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004464 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004465 if (!err) /* Success in acquiring all requested vectors. */
4466 break;
4467 else if (err < 0)
4468 vectors = 0; /* Nasty failure, quit now */
4469 else /* err == number of vectors we should try again with */
4470 vectors = err;
4471 }
4472
4473 if (vectors < vector_threshold) {
4474 /* Can't allocate enough MSI-X interrupts? Oh well.
4475 * This just means we'll go with either a single MSI
4476 * vector or fall back to legacy interrupts.
4477 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004478 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4479 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004480 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4481 kfree(adapter->msix_entries);
4482 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004483 } else {
4484 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004485 /*
4486 * Adjust for only the vectors we'll use, which is minimum
4487 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4488 * vectors we were allocated.
4489 */
4490 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004491 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004492 }
4493}
4494
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004495/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004496 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004497 * @adapter: board private structure to initialize
4498 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004499 * Cache the descriptor ring offsets for RSS to the assigned rings.
4500 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004501 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004502static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004503{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004504 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004505
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004506 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4507 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004508
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004509 for (i = 0; i < adapter->num_rx_queues; i++)
4510 adapter->rx_ring[i]->reg_idx = i;
4511 for (i = 0; i < adapter->num_tx_queues; i++)
4512 adapter->tx_ring[i]->reg_idx = i;
4513
4514 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004515}
4516
4517#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004518
4519/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004520static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4521 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004522{
4523 struct net_device *dev = adapter->netdev;
4524 struct ixgbe_hw *hw = &adapter->hw;
4525 u8 num_tcs = netdev_get_num_tc(dev);
4526
4527 *tx = 0;
4528 *rx = 0;
4529
4530 switch (hw->mac.type) {
4531 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004532 *tx = tc << 2;
4533 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004534 break;
4535 case ixgbe_mac_82599EB:
4536 case ixgbe_mac_X540:
4537 if (num_tcs == 8) {
4538 if (tc < 3) {
4539 *tx = tc << 5;
4540 *rx = tc << 4;
4541 } else if (tc < 5) {
4542 *tx = ((tc + 2) << 4);
4543 *rx = tc << 4;
4544 } else if (tc < num_tcs) {
4545 *tx = ((tc + 8) << 3);
4546 *rx = tc << 4;
4547 }
4548 } else if (num_tcs == 4) {
4549 *rx = tc << 5;
4550 switch (tc) {
4551 case 0:
4552 *tx = 0;
4553 break;
4554 case 1:
4555 *tx = 64;
4556 break;
4557 case 2:
4558 *tx = 96;
4559 break;
4560 case 3:
4561 *tx = 112;
4562 break;
4563 default:
4564 break;
4565 }
4566 }
4567 break;
4568 default:
4569 break;
4570 }
4571}
4572
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004573/**
4574 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4575 * @adapter: board private structure to initialize
4576 *
4577 * Cache the descriptor ring offsets for DCB to the assigned rings.
4578 *
4579 **/
4580static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4581{
John Fastabende5b64632011-03-08 03:44:52 +00004582 struct net_device *dev = adapter->netdev;
4583 int i, j, k;
4584 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004585
John Fastabend8b1c0b22011-05-03 02:26:48 +00004586 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004587 return false;
4588
John Fastabende5b64632011-03-08 03:44:52 +00004589 for (i = 0, k = 0; i < num_tcs; i++) {
4590 unsigned int tx_s, rx_s;
4591 u16 count = dev->tc_to_txq[i].count;
4592
4593 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4594 for (j = 0; j < count; j++, k++) {
4595 adapter->tx_ring[k]->reg_idx = tx_s + j;
4596 adapter->rx_ring[k]->reg_idx = rx_s + j;
4597 adapter->tx_ring[k]->dcb_tc = i;
4598 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004599 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004600 }
John Fastabende5b64632011-03-08 03:44:52 +00004601
4602 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004603}
4604#endif
4605
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004606/**
4607 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4608 * @adapter: board private structure to initialize
4609 *
4610 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4611 *
4612 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004613static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004614{
4615 int i;
4616 bool ret = false;
4617
Alexander Duyck03ecf912011-05-20 07:36:17 +00004618 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4619 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004620 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004621 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004622 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004623 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004624 ret = true;
4625 }
4626
4627 return ret;
4628}
4629
Yi Zou0331a832009-05-17 12:33:52 +00004630#ifdef IXGBE_FCOE
4631/**
4632 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4633 * @adapter: board private structure to initialize
4634 *
4635 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4636 *
4637 */
4638static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4639{
Yi Zou0331a832009-05-17 12:33:52 +00004640 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004641 int i;
4642 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004643
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004644 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4645 return false;
4646
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004647 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004648 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004649 ixgbe_cache_ring_fdir(adapter);
4650 else
4651 ixgbe_cache_ring_rss(adapter);
4652
4653 fcoe_rx_i = f->mask;
4654 fcoe_tx_i = f->mask;
4655 }
4656 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4657 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4658 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4659 }
4660 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004661}
4662
4663#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004664/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004665 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4666 * @adapter: board private structure to initialize
4667 *
4668 * SR-IOV doesn't use any descriptor rings but changes the default if
4669 * no other mapping is used.
4670 *
4671 */
4672static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4673{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004674 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4675 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004676 if (adapter->num_vfs)
4677 return true;
4678 else
4679 return false;
4680}
4681
4682/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004683 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4684 * @adapter: board private structure to initialize
4685 *
4686 * Once we know the feature-set enabled for the device, we'll cache
4687 * the register offset the descriptor ring is assigned to.
4688 *
4689 * Note, the order the various feature calls is important. It must start with
4690 * the "most" features enabled at the same time, then trickle down to the
4691 * least amount of features turned on at once.
4692 **/
4693static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4694{
4695 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004696 adapter->rx_ring[0]->reg_idx = 0;
4697 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004698
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004699 if (ixgbe_cache_ring_sriov(adapter))
4700 return;
4701
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004702#ifdef CONFIG_IXGBE_DCB
4703 if (ixgbe_cache_ring_dcb(adapter))
4704 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004705#endif
John Fastabende5b64632011-03-08 03:44:52 +00004706
4707#ifdef IXGBE_FCOE
4708 if (ixgbe_cache_ring_fcoe(adapter))
4709 return;
4710#endif /* IXGBE_FCOE */
4711
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004712 if (ixgbe_cache_ring_fdir(adapter))
4713 return;
4714
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004715 if (ixgbe_cache_ring_rss(adapter))
4716 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004717}
4718
Auke Kok9a799d72007-09-15 14:07:45 -07004719/**
4720 * ixgbe_alloc_queues - Allocate memory for all rings
4721 * @adapter: board private structure to initialize
4722 *
4723 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004724 * number of queues at compile-time. The polling_netdev array is
4725 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004726 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004727static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004728{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004729 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004730
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004731 if (nid < 0 || !node_online(nid))
4732 nid = first_online_node;
4733
4734 for (; tx < adapter->num_tx_queues; tx++) {
4735 struct ixgbe_ring *ring;
4736
4737 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004738 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004739 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004740 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004741 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004742 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004743 ring->queue_index = tx;
4744 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004745 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004746 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004747
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004748 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004749 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004750
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004751 for (; rx < adapter->num_rx_queues; rx++) {
4752 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004753
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004754 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004755 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004756 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004757 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004758 goto err_allocation;
4759 ring->count = adapter->rx_ring_count;
4760 ring->queue_index = rx;
4761 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004762 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004763 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004764
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004765 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004766 }
4767
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004768 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004769
4770 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004771
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004772err_allocation:
4773 while (tx)
4774 kfree(adapter->tx_ring[--tx]);
4775
4776 while (rx)
4777 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004778 return -ENOMEM;
4779}
4780
4781/**
4782 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4783 * @adapter: board private structure to initialize
4784 *
4785 * Attempt to configure the interrupts using the best available
4786 * capabilities of the hardware and the kernel.
4787 **/
Al Virofeea6a52008-11-27 15:34:07 -08004788static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004789{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004790 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004791 int err = 0;
4792 int vector, v_budget;
4793
4794 /*
4795 * It's easy to be greedy for MSI-X vectors, but it really
4796 * doesn't do us much good if we have a lot more vectors
4797 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004798 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004799 */
4800 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004801 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004802
4803 /*
4804 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004805 * hw.mac->max_msix_vectors vectors. With features
4806 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4807 * descriptor queues supported by our device. Thus, we cap it off in
4808 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004809 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004810 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004811
4812 /* A failure in MSI-X entry allocation isn't fatal, but it does
4813 * mean we disable MSI-X capabilities of the adapter. */
4814 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004815 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004816 if (adapter->msix_entries) {
4817 for (vector = 0; vector < v_budget; vector++)
4818 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004819
Alexander Duyck7a921c92009-05-06 10:43:28 +00004820 ixgbe_acquire_msix_vectors(adapter, v_budget);
4821
4822 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4823 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004824 }
David S. Miller26d27842010-05-03 15:18:22 -07004825
Alexander Duyck7a921c92009-05-06 10:43:28 +00004826 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4827 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004828 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004829 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004830 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004831 "queues are disabled. Disabling Flow Director\n");
4832 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004833 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004834 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004835 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4836 ixgbe_disable_sriov(adapter);
4837
Ben Hutchings847f53f2010-09-27 08:28:56 +00004838 err = ixgbe_set_num_queues(adapter);
4839 if (err)
4840 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004841
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842 err = pci_enable_msi(adapter->pdev);
4843 if (!err) {
4844 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4845 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004846 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4847 "Unable to allocate MSI interrupt, "
4848 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004849 /* reset err */
4850 err = 0;
4851 }
4852
4853out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004854 return err;
4855}
4856
Alexander Duyck7a921c92009-05-06 10:43:28 +00004857/**
4858 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4859 * @adapter: board private structure to initialize
4860 *
4861 * We allocate one q_vector per queue interrupt. If allocation fails we
4862 * return -ENOMEM.
4863 **/
4864static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4865{
4866 int q_idx, num_q_vectors;
4867 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004868 int (*poll)(struct napi_struct *, int);
4869
4870 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4871 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004872 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004873 } else {
4874 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004875 poll = &ixgbe_poll;
4876 }
4877
4878 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004879 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004880 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004881 if (!q_vector)
4882 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004883 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004884 if (!q_vector)
4885 goto err_out;
4886 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004887 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004888 q_vector->eitr = adapter->tx_eitr_param;
4889 else
4890 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004891 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004892 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004893 adapter->q_vector[q_idx] = q_vector;
4894 }
4895
4896 return 0;
4897
4898err_out:
4899 while (q_idx) {
4900 q_idx--;
4901 q_vector = adapter->q_vector[q_idx];
4902 netif_napi_del(&q_vector->napi);
4903 kfree(q_vector);
4904 adapter->q_vector[q_idx] = NULL;
4905 }
4906 return -ENOMEM;
4907}
4908
4909/**
4910 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4911 * @adapter: board private structure to initialize
4912 *
4913 * This function frees the memory allocated to the q_vectors. In addition if
4914 * NAPI is enabled it will delete any references to the NAPI struct prior
4915 * to freeing the q_vector.
4916 **/
4917static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4918{
4919 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004920
Alexander Duyck91281fd2009-06-04 16:00:27 +00004921 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004922 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004923 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004924 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004925
4926 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4927 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004928 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004929 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004930 kfree(q_vector);
4931 }
4932}
4933
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004934static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004935{
4936 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4937 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4938 pci_disable_msix(adapter->pdev);
4939 kfree(adapter->msix_entries);
4940 adapter->msix_entries = NULL;
4941 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4942 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4943 pci_disable_msi(adapter->pdev);
4944 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004945}
4946
4947/**
4948 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4949 * @adapter: board private structure to initialize
4950 *
4951 * We determine which interrupt scheme to use based on...
4952 * - Kernel support (MSI, MSI-X)
4953 * - which can be user-defined (via MODULE_PARAM)
4954 * - Hardware queue count (num_*_queues)
4955 * - defined by miscellaneous hardware support/features (RSS, etc.)
4956 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004957int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004958{
4959 int err;
4960
4961 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004962 err = ixgbe_set_num_queues(adapter);
4963 if (err)
4964 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004966 err = ixgbe_set_interrupt_capability(adapter);
4967 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004968 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004969 goto err_set_interrupt;
4970 }
4971
Alexander Duyck7a921c92009-05-06 10:43:28 +00004972 err = ixgbe_alloc_q_vectors(adapter);
4973 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004974 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004975 goto err_alloc_q_vectors;
4976 }
4977
4978 err = ixgbe_alloc_queues(adapter);
4979 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004980 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004981 goto err_alloc_queues;
4982 }
4983
Emil Tantilov849c4542010-06-03 16:53:41 +00004984 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00004985 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4986 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004987
4988 set_bit(__IXGBE_DOWN, &adapter->state);
4989
4990 return 0;
4991
Alexander Duyck7a921c92009-05-06 10:43:28 +00004992err_alloc_queues:
4993 ixgbe_free_q_vectors(adapter);
4994err_alloc_q_vectors:
4995 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004996err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00004997 return err;
4998}
4999
5000/**
5001 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5002 * @adapter: board private structure to clear interrupt scheme on
5003 *
5004 * We go through and clear interrupt specific resources and reset the structure
5005 * to pre-load conditions
5006 **/
5007void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5008{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005009 int i;
5010
5011 for (i = 0; i < adapter->num_tx_queues; i++) {
5012 kfree(adapter->tx_ring[i]);
5013 adapter->tx_ring[i] = NULL;
5014 }
5015 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005016 struct ixgbe_ring *ring = adapter->rx_ring[i];
5017
5018 /* ixgbe_get_stats64() might access this ring, we must wait
5019 * a grace period before freeing it.
5020 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005021 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005022 adapter->rx_ring[i] = NULL;
5023 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005024
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005025 adapter->num_tx_queues = 0;
5026 adapter->num_rx_queues = 0;
5027
Alexander Duyck7a921c92009-05-06 10:43:28 +00005028 ixgbe_free_q_vectors(adapter);
5029 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005030}
5031
5032/**
5033 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5034 * @adapter: board private structure to initialize
5035 *
5036 * ixgbe_sw_init initializes the Adapter private data structure.
5037 * Fields are initialized based on PCI device information and
5038 * OS network device settings (MTU size).
5039 **/
5040static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5041{
5042 struct ixgbe_hw *hw = &adapter->hw;
5043 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005044 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005045 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005046#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005047 int j;
5048 struct tc_configuration *tc;
5049#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005050 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005051
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005052 /* PCI config space info */
5053
5054 hw->vendor_id = pdev->vendor;
5055 hw->device_id = pdev->device;
5056 hw->revision_id = pdev->revision;
5057 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5058 hw->subsystem_device_id = pdev->subsystem_device;
5059
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005060 /* Set capability flags */
5061 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5062 adapter->ring_feature[RING_F_RSS].indices = rss;
5063 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005064 switch (hw->mac.type) {
5065 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005066 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5067 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005068 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005069 break;
5070 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005071 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005072 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005073 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5074 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005075 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5076 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005077 /* Flow Director hash filters enabled */
5078 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5079 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005080 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005081 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005082 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005083#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005084 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5085 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5086 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005087#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005088 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005089 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005090#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005091#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005092 break;
5093 default:
5094 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005095 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005096
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005097 /* n-tuple support exists, always init our spinlock */
5098 spin_lock_init(&adapter->fdir_perfect_lock);
5099
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005100#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005101 /* Configure DCB traffic classes */
5102 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5103 tc = &adapter->dcb_cfg.tc_config[j];
5104 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5105 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5106 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5107 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5108 tc->dcb_pfc = pfc_disabled;
5109 }
5110 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5111 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005112 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005113 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005114 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005115 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005116 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005117
5118#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005119
5120 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005121 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005122 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005123#ifdef CONFIG_DCB
5124 adapter->last_lfc_mode = hw->fc.current_mode;
5125#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005126 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5127 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005128 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5129 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005130 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005131
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005132 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005133 adapter->rx_itr_setting = 1;
5134 adapter->rx_eitr_param = 20000;
5135 adapter->tx_itr_setting = 1;
5136 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005137
5138 /* set defaults for eitr in MegaBytes */
5139 adapter->eitr_low = 10;
5140 adapter->eitr_high = 20;
5141
5142 /* set default ring sizes */
5143 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5144 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5145
Alexander Duyckbd198052011-06-11 01:45:08 +00005146 /* set default work limits */
5147 adapter->tx_work_limit = adapter->tx_ring_count;
5148
Auke Kok9a799d72007-09-15 14:07:45 -07005149 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005150 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005151 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005152 return -EIO;
5153 }
5154
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005155 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005156 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5157
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005158 /* get assigned NUMA node */
5159 adapter->node = dev_to_node(&pdev->dev);
5160
Auke Kok9a799d72007-09-15 14:07:45 -07005161 set_bit(__IXGBE_DOWN, &adapter->state);
5162
5163 return 0;
5164}
5165
5166/**
5167 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005168 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005169 *
5170 * Return 0 on success, negative on failure
5171 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005172int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005173{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005174 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005175 int size;
5176
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005177 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005178 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005179 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005180 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005181 if (!tx_ring->tx_buffer_info)
5182 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005183
5184 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005185 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005186 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005187
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005188 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005189 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005190 if (!tx_ring->desc)
5191 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005192
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005193 tx_ring->next_to_use = 0;
5194 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005195 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005196
5197err:
5198 vfree(tx_ring->tx_buffer_info);
5199 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005200 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005201 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005202}
5203
5204/**
Alexander Duyck69888672008-09-11 20:05:39 -07005205 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5206 * @adapter: board private structure
5207 *
5208 * If this function returns with an error, then it's possible one or
5209 * more of the rings is populated (while the rest are not). It is the
5210 * callers duty to clean those orphaned rings.
5211 *
5212 * Return 0 on success, negative on failure
5213 **/
5214static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5215{
5216 int i, err = 0;
5217
5218 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005219 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005220 if (!err)
5221 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005222 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005223 break;
5224 }
5225
5226 return err;
5227}
5228
5229/**
Auke Kok9a799d72007-09-15 14:07:45 -07005230 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005231 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005232 *
5233 * Returns 0 on success, negative on failure
5234 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005235int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005236{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005237 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005238 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005239
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005240 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005241 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005242 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005243 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005244 if (!rx_ring->rx_buffer_info)
5245 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005246
Auke Kok9a799d72007-09-15 14:07:45 -07005247 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005248 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5249 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005250
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005251 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005252 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005253
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005254 if (!rx_ring->desc)
5255 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005256
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005257 rx_ring->next_to_clean = 0;
5258 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005259
5260 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005261err:
5262 vfree(rx_ring->rx_buffer_info);
5263 rx_ring->rx_buffer_info = NULL;
5264 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005265 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005266}
5267
5268/**
Alexander Duyck69888672008-09-11 20:05:39 -07005269 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5270 * @adapter: board private structure
5271 *
5272 * If this function returns with an error, then it's possible one or
5273 * more of the rings is populated (while the rest are not). It is the
5274 * callers duty to clean those orphaned rings.
5275 *
5276 * Return 0 on success, negative on failure
5277 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005278static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5279{
5280 int i, err = 0;
5281
5282 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005283 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005284 if (!err)
5285 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005286 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005287 break;
5288 }
5289
5290 return err;
5291}
5292
5293/**
Auke Kok9a799d72007-09-15 14:07:45 -07005294 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005295 * @tx_ring: Tx descriptor ring for a specific queue
5296 *
5297 * Free all transmit software resources
5298 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005299void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005300{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005301 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005302
5303 vfree(tx_ring->tx_buffer_info);
5304 tx_ring->tx_buffer_info = NULL;
5305
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005306 /* if not set, then don't free */
5307 if (!tx_ring->desc)
5308 return;
5309
5310 dma_free_coherent(tx_ring->dev, tx_ring->size,
5311 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005312
5313 tx_ring->desc = NULL;
5314}
5315
5316/**
5317 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5318 * @adapter: board private structure
5319 *
5320 * Free all transmit software resources
5321 **/
5322static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5323{
5324 int i;
5325
5326 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005327 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005328 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005329}
5330
5331/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005332 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005333 * @rx_ring: ring to clean the resources from
5334 *
5335 * Free all receive software resources
5336 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005337void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005338{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005339 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005340
5341 vfree(rx_ring->rx_buffer_info);
5342 rx_ring->rx_buffer_info = NULL;
5343
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005344 /* if not set, then don't free */
5345 if (!rx_ring->desc)
5346 return;
5347
5348 dma_free_coherent(rx_ring->dev, rx_ring->size,
5349 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005350
5351 rx_ring->desc = NULL;
5352}
5353
5354/**
5355 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5356 * @adapter: board private structure
5357 *
5358 * Free all receive software resources
5359 **/
5360static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5361{
5362 int i;
5363
5364 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005365 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005366 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005367}
5368
5369/**
Auke Kok9a799d72007-09-15 14:07:45 -07005370 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5371 * @netdev: network interface device structure
5372 * @new_mtu: new value for maximum frame size
5373 *
5374 * Returns 0 on success, negative on failure
5375 **/
5376static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5377{
5378 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005379 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005380 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5381
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005382 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005383 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5384 hw->mac.type != ixgbe_mac_X540) {
5385 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5386 return -EINVAL;
5387 } else {
5388 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5389 return -EINVAL;
5390 }
Auke Kok9a799d72007-09-15 14:07:45 -07005391
Emil Tantilov396e7992010-07-01 20:05:12 +00005392 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005393 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005394 netdev->mtu = new_mtu;
5395
John Fastabend16b61be2010-11-16 19:26:44 -08005396 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5397 hw->fc.low_water = FC_LOW_WATER(max_frame);
5398
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005399 if (netif_running(netdev))
5400 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005401
5402 return 0;
5403}
5404
5405/**
5406 * ixgbe_open - Called when a network interface is made active
5407 * @netdev: network interface device structure
5408 *
5409 * Returns 0 on success, negative value on failure
5410 *
5411 * The open entry point is called when a network interface is made
5412 * active by the system (IFF_UP). At this point all resources needed
5413 * for transmit and receive operations are allocated, the interrupt
5414 * handler is registered with the OS, the watchdog timer is started,
5415 * and the stack is notified that the interface is ready.
5416 **/
5417static int ixgbe_open(struct net_device *netdev)
5418{
5419 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5420 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005421
Auke Kok4bebfaa2008-02-11 09:26:01 -08005422 /* disallow open during test */
5423 if (test_bit(__IXGBE_TESTING, &adapter->state))
5424 return -EBUSY;
5425
Jesse Brandeburg54386462009-04-17 20:44:27 +00005426 netif_carrier_off(netdev);
5427
Auke Kok9a799d72007-09-15 14:07:45 -07005428 /* allocate transmit descriptors */
5429 err = ixgbe_setup_all_tx_resources(adapter);
5430 if (err)
5431 goto err_setup_tx;
5432
Auke Kok9a799d72007-09-15 14:07:45 -07005433 /* allocate receive descriptors */
5434 err = ixgbe_setup_all_rx_resources(adapter);
5435 if (err)
5436 goto err_setup_rx;
5437
5438 ixgbe_configure(adapter);
5439
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005440 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005441 if (err)
5442 goto err_req_irq;
5443
Auke Kok9a799d72007-09-15 14:07:45 -07005444 err = ixgbe_up_complete(adapter);
5445 if (err)
5446 goto err_up;
5447
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005448 netif_tx_start_all_queues(netdev);
5449
Auke Kok9a799d72007-09-15 14:07:45 -07005450 return 0;
5451
5452err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005453 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005454 ixgbe_free_irq(adapter);
5455err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005456err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005457 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005458err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005459 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005460 ixgbe_reset(adapter);
5461
5462 return err;
5463}
5464
5465/**
5466 * ixgbe_close - Disables a network interface
5467 * @netdev: network interface device structure
5468 *
5469 * Returns 0, this is not allowed to fail
5470 *
5471 * The close entry point is called when an interface is de-activated
5472 * by the OS. The hardware is still under the drivers control, but
5473 * needs to be disabled. A global MAC reset is issued to stop the
5474 * hardware, and all transmit and receive resources are freed.
5475 **/
5476static int ixgbe_close(struct net_device *netdev)
5477{
5478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005479
5480 ixgbe_down(adapter);
5481 ixgbe_free_irq(adapter);
5482
Alexander Duycke4911d52011-05-11 07:18:52 +00005483 ixgbe_fdir_filter_exit(adapter);
5484
Auke Kok9a799d72007-09-15 14:07:45 -07005485 ixgbe_free_all_tx_resources(adapter);
5486 ixgbe_free_all_rx_resources(adapter);
5487
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005488 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005489
5490 return 0;
5491}
5492
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005493#ifdef CONFIG_PM
5494static int ixgbe_resume(struct pci_dev *pdev)
5495{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005496 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5497 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005498 u32 err;
5499
5500 pci_set_power_state(pdev, PCI_D0);
5501 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005502 /*
5503 * pci_restore_state clears dev->state_saved so call
5504 * pci_save_state to restore it.
5505 */
5506 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005507
5508 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005509 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005510 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005511 return err;
5512 }
5513 pci_set_master(pdev);
5514
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005515 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005516
5517 err = ixgbe_init_interrupt_scheme(adapter);
5518 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005519 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005520 return err;
5521 }
5522
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005523 ixgbe_reset(adapter);
5524
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005525 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5526
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005527 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005528 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005529 if (err)
5530 return err;
5531 }
5532
5533 netif_device_attach(netdev);
5534
5535 return 0;
5536}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005537#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005538
5539static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005540{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005541 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5542 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005543 struct ixgbe_hw *hw = &adapter->hw;
5544 u32 ctrl, fctrl;
5545 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005546#ifdef CONFIG_PM
5547 int retval = 0;
5548#endif
5549
5550 netif_device_detach(netdev);
5551
5552 if (netif_running(netdev)) {
5553 ixgbe_down(adapter);
5554 ixgbe_free_irq(adapter);
5555 ixgbe_free_all_tx_resources(adapter);
5556 ixgbe_free_all_rx_resources(adapter);
5557 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005558
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005559 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005560#ifdef CONFIG_DCB
5561 kfree(adapter->ixgbe_ieee_pfc);
5562 kfree(adapter->ixgbe_ieee_ets);
5563#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005564
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005565#ifdef CONFIG_PM
5566 retval = pci_save_state(pdev);
5567 if (retval)
5568 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005569
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005570#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005571 if (wufc) {
5572 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005573
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005574 /* turn on all-multi mode if wake on multicast is enabled */
5575 if (wufc & IXGBE_WUFC_MC) {
5576 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5577 fctrl |= IXGBE_FCTRL_MPE;
5578 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5579 }
5580
5581 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5582 ctrl |= IXGBE_CTRL_GIO_DIS;
5583 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5584
5585 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5586 } else {
5587 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5588 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5589 }
5590
Alexander Duyckbd508172010-11-16 19:27:03 -08005591 switch (hw->mac.type) {
5592 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005593 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005594 break;
5595 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005596 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005597 pci_wake_from_d3(pdev, !!wufc);
5598 break;
5599 default:
5600 break;
5601 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005602
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005603 *enable_wake = !!wufc;
5604
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005605 ixgbe_release_hw_control(adapter);
5606
5607 pci_disable_device(pdev);
5608
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005609 return 0;
5610}
5611
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005612#ifdef CONFIG_PM
5613static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5614{
5615 int retval;
5616 bool wake;
5617
5618 retval = __ixgbe_shutdown(pdev, &wake);
5619 if (retval)
5620 return retval;
5621
5622 if (wake) {
5623 pci_prepare_to_sleep(pdev);
5624 } else {
5625 pci_wake_from_d3(pdev, false);
5626 pci_set_power_state(pdev, PCI_D3hot);
5627 }
5628
5629 return 0;
5630}
5631#endif /* CONFIG_PM */
5632
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633static void ixgbe_shutdown(struct pci_dev *pdev)
5634{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005635 bool wake;
5636
5637 __ixgbe_shutdown(pdev, &wake);
5638
5639 if (system_state == SYSTEM_POWER_OFF) {
5640 pci_wake_from_d3(pdev, wake);
5641 pci_set_power_state(pdev, PCI_D3hot);
5642 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005643}
5644
5645/**
Auke Kok9a799d72007-09-15 14:07:45 -07005646 * ixgbe_update_stats - Update the board statistics counters.
5647 * @adapter: board private structure
5648 **/
5649void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5650{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005651 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005652 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005653 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005654 u64 total_mpc = 0;
5655 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005656 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5657 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5658 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005659
Don Skidmored08935c2010-06-11 13:20:29 +00005660 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5661 test_bit(__IXGBE_RESETTING, &adapter->state))
5662 return;
5663
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005664 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005665 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005666 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005667 for (i = 0; i < 16; i++)
5668 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005669 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005670 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005671 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5672 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005673 }
5674 adapter->rsc_total_count = rsc_count;
5675 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005676 }
5677
Alexander Duyck5b7da512010-11-16 19:26:50 -08005678 for (i = 0; i < adapter->num_rx_queues; i++) {
5679 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5680 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5681 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5682 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5683 bytes += rx_ring->stats.bytes;
5684 packets += rx_ring->stats.packets;
5685 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005686 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005687 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5688 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5689 netdev->stats.rx_bytes = bytes;
5690 netdev->stats.rx_packets = packets;
5691
5692 bytes = 0;
5693 packets = 0;
5694 /* gather some stats to the adapter struct that are per queue */
5695 for (i = 0; i < adapter->num_tx_queues; i++) {
5696 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5697 restart_queue += tx_ring->tx_stats.restart_queue;
5698 tx_busy += tx_ring->tx_stats.tx_busy;
5699 bytes += tx_ring->stats.bytes;
5700 packets += tx_ring->stats.packets;
5701 }
5702 adapter->restart_queue = restart_queue;
5703 adapter->tx_busy = tx_busy;
5704 netdev->stats.tx_bytes = bytes;
5705 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005706
Joe Perches7ca647b2010-09-07 21:35:40 +00005707 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005708 for (i = 0; i < 8; i++) {
5709 /* for packet buffers not used, the register should read 0 */
5710 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5711 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005712 hwstats->mpc[i] += mpc;
5713 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005714 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005715 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5716 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5717 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5718 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5719 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005720 switch (hw->mac.type) {
5721 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005722 hwstats->pxonrxc[i] +=
5723 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005724 break;
5725 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005726 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005727 hwstats->pxonrxc[i] +=
5728 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005729 break;
5730 default:
5731 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005732 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005733 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5734 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005735 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005736 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005737 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005738 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005739
John Fastabendc84d3242010-11-16 19:27:12 -08005740 ixgbe_update_xoff_received(adapter);
5741
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005742 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005743 switch (hw->mac.type) {
5744 case ixgbe_mac_82598EB:
5745 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005746 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5747 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5748 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5749 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005750 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005751 /* OS2BMC stats are X540 only*/
5752 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5753 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5754 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5755 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5756 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005757 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005758 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005759 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005760 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005761 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005762 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005763 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005764 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5765 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005766#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005767 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5768 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5769 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5770 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5771 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5772 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005773#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005774 break;
5775 default:
5776 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005777 }
Auke Kok9a799d72007-09-15 14:07:45 -07005778 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005779 hwstats->bprc += bprc;
5780 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005781 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005782 hwstats->mprc -= bprc;
5783 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5784 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5785 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5786 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5787 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5788 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5789 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5790 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005791 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005792 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005793 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005794 hwstats->lxofftxc += lxoff;
5795 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5796 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5797 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005798 /*
5799 * 82598 errata - tx of flow control packets is included in tx counters
5800 */
5801 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005802 hwstats->gptc -= xon_off_tot;
5803 hwstats->mptc -= xon_off_tot;
5804 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5805 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5806 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5807 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5808 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5809 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5810 hwstats->ptc64 -= xon_off_tot;
5811 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5812 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5813 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5814 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5815 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5816 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005817
5818 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005819 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005820
5821 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005822 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005823 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005824 netdev->stats.rx_length_errors = hwstats->rlec;
5825 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005826 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005827}
5828
5829/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005830 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5831 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005832 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005833static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005834{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005835 struct ixgbe_hw *hw = &adapter->hw;
5836 int i;
5837
Alexander Duyckd034acf2011-04-27 09:25:34 +00005838 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5839 return;
5840
5841 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5842
5843 /* if interface is down do nothing */
5844 if (test_bit(__IXGBE_DOWN, &adapter->state))
5845 return;
5846
5847 /* do nothing if we are not using signature filters */
5848 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5849 return;
5850
5851 adapter->fdir_overflow++;
5852
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005853 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5854 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005855 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005856 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005857 /* re-enable flow director interrupts */
5858 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005859 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005860 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005861 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005862 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005863}
5864
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005865/**
5866 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5867 * @adapter - pointer to the device adapter structure
5868 *
5869 * This function serves two purposes. First it strobes the interrupt lines
5870 * in order to make certain interrupts are occuring. Secondly it sets the
5871 * bits needed to check for TX hangs. As a result we should immediately
5872 * determine if a hang has occured.
5873 */
5874static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5875{
Auke Kok9a799d72007-09-15 14:07:45 -07005876 struct ixgbe_hw *hw = &adapter->hw;
5877 u64 eics = 0;
5878 int i;
5879
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005880 /* If we're down or resetting, just bail */
5881 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5882 test_bit(__IXGBE_RESETTING, &adapter->state))
5883 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005884
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005885 /* Force detection of hung controller */
5886 if (netif_carrier_ok(adapter->netdev)) {
5887 for (i = 0; i < adapter->num_tx_queues; i++)
5888 set_check_for_tx_hang(adapter->tx_ring[i]);
5889 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005890
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005891 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005892 /*
5893 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005894 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005895 * would set *both* EIMS and EICS for any bit in EIAM
5896 */
5897 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5898 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005899 } else {
5900 /* get one bit for every active tx/rx interrupt vector */
5901 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5902 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005903 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005904 eics |= ((u64)1 << i);
5905 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005906 }
5907
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005908 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005909 ixgbe_irq_rearm_queues(adapter, eics);
5910
Alexander Duyckfe49f042009-06-04 16:00:09 +00005911}
5912
5913/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005914 * ixgbe_watchdog_update_link - update the link status
5915 * @adapter - pointer to the device adapter structure
5916 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005917 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005918static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005919{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005920 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005921 u32 link_speed = adapter->link_speed;
5922 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005923 int i;
5924
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005925 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5926 return;
5927
5928 if (hw->mac.ops.check_link) {
5929 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005930 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005931 /* always assume link is up, if no check link function */
5932 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5933 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005934 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005935 if (link_up) {
5936 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5937 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5938 hw->mac.ops.fc_enable(hw, i);
5939 } else {
5940 hw->mac.ops.fc_enable(hw, 0);
5941 }
5942 }
5943
5944 if (link_up ||
5945 time_after(jiffies, (adapter->link_check_timeout +
5946 IXGBE_TRY_LINK_TIMEOUT))) {
5947 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5948 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5949 IXGBE_WRITE_FLUSH(hw);
5950 }
5951
5952 adapter->link_up = link_up;
5953 adapter->link_speed = link_speed;
5954}
5955
5956/**
5957 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5958 * print link up message
5959 * @adapter - pointer to the device adapter structure
5960 **/
5961static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5962{
5963 struct net_device *netdev = adapter->netdev;
5964 struct ixgbe_hw *hw = &adapter->hw;
5965 u32 link_speed = adapter->link_speed;
5966 bool flow_rx, flow_tx;
5967
5968 /* only continue if link was previously down */
5969 if (netif_carrier_ok(netdev))
5970 return;
5971
5972 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5973
5974 switch (hw->mac.type) {
5975 case ixgbe_mac_82598EB: {
5976 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5977 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5978 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5979 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5980 }
5981 break;
5982 case ixgbe_mac_X540:
5983 case ixgbe_mac_82599EB: {
5984 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5985 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5986 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5987 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5988 }
5989 break;
5990 default:
5991 flow_tx = false;
5992 flow_rx = false;
5993 break;
5994 }
5995 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5996 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5997 "10 Gbps" :
5998 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
5999 "1 Gbps" :
6000 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6001 "100 Mbps" :
6002 "unknown speed"))),
6003 ((flow_rx && flow_tx) ? "RX/TX" :
6004 (flow_rx ? "RX" :
6005 (flow_tx ? "TX" : "None"))));
6006
6007 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006008 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006009}
6010
6011/**
6012 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6013 * print link down message
6014 * @adapter - pointer to the adapter structure
6015 **/
6016static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6017{
6018 struct net_device *netdev = adapter->netdev;
6019 struct ixgbe_hw *hw = &adapter->hw;
6020
6021 adapter->link_up = false;
6022 adapter->link_speed = 0;
6023
6024 /* only continue if link was up previously */
6025 if (!netif_carrier_ok(netdev))
6026 return;
6027
6028 /* poll for SFP+ cable when link is down */
6029 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6030 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6031
6032 e_info(drv, "NIC Link is Down\n");
6033 netif_carrier_off(netdev);
6034}
6035
6036/**
6037 * ixgbe_watchdog_flush_tx - flush queues on link down
6038 * @adapter - pointer to the device adapter structure
6039 **/
6040static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6041{
6042 int i;
6043 int some_tx_pending = 0;
6044
6045 if (!netif_carrier_ok(adapter->netdev)) {
6046 for (i = 0; i < adapter->num_tx_queues; i++) {
6047 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6048 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6049 some_tx_pending = 1;
6050 break;
6051 }
6052 }
6053
6054 if (some_tx_pending) {
6055 /* We've lost link, so the controller stops DMA,
6056 * but we've got queued Tx work that's never going
6057 * to get done, so reset controller to flush Tx.
6058 * (Do the reset outside of interrupt context).
6059 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006060 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006061 }
6062 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006063}
6064
Greg Rosea985b6c32010-11-18 03:02:52 +00006065static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6066{
6067 u32 ssvpc;
6068
6069 /* Do not perform spoof check for 82598 */
6070 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6071 return;
6072
6073 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6074
6075 /*
6076 * ssvpc register is cleared on read, if zero then no
6077 * spoofed packets in the last interval.
6078 */
6079 if (!ssvpc)
6080 return;
6081
6082 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6083}
6084
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006085/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006086 * ixgbe_watchdog_subtask - check and bring link up
6087 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006088 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006089static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006090{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006091 /* if interface is down do nothing */
6092 if (test_bit(__IXGBE_DOWN, &adapter->state))
6093 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006094
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006095 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006096
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006097 if (adapter->link_up)
6098 ixgbe_watchdog_link_is_up(adapter);
6099 else
6100 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006101
Greg Rosea985b6c32010-11-18 03:02:52 +00006102 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006103 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006104
6105 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006106}
6107
Alexander Duyck70864002011-04-27 09:13:56 +00006108/**
6109 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6110 * @adapter - the ixgbe adapter structure
6111 **/
6112static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6113{
6114 struct ixgbe_hw *hw = &adapter->hw;
6115 s32 err;
6116
6117 /* not searching for SFP so there is nothing to do here */
6118 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6119 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6120 return;
6121
6122 /* someone else is in init, wait until next service event */
6123 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6124 return;
6125
6126 err = hw->phy.ops.identify_sfp(hw);
6127 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6128 goto sfp_out;
6129
6130 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6131 /* If no cable is present, then we need to reset
6132 * the next time we find a good cable. */
6133 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6134 }
6135
6136 /* exit on error */
6137 if (err)
6138 goto sfp_out;
6139
6140 /* exit if reset not needed */
6141 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6142 goto sfp_out;
6143
6144 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6145
6146 /*
6147 * A module may be identified correctly, but the EEPROM may not have
6148 * support for that module. setup_sfp() will fail in that case, so
6149 * we should not allow that module to load.
6150 */
6151 if (hw->mac.type == ixgbe_mac_82598EB)
6152 err = hw->phy.ops.reset(hw);
6153 else
6154 err = hw->mac.ops.setup_sfp(hw);
6155
6156 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6157 goto sfp_out;
6158
6159 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6160 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6161
6162sfp_out:
6163 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6164
6165 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6166 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6167 e_dev_err("failed to initialize because an unsupported "
6168 "SFP+ module type was detected.\n");
6169 e_dev_err("Reload the driver after installing a "
6170 "supported module.\n");
6171 unregister_netdev(adapter->netdev);
6172 }
6173}
6174
6175/**
6176 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6177 * @adapter - the ixgbe adapter structure
6178 **/
6179static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6180{
6181 struct ixgbe_hw *hw = &adapter->hw;
6182 u32 autoneg;
6183 bool negotiation;
6184
6185 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6186 return;
6187
6188 /* someone else is in init, wait until next service event */
6189 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6190 return;
6191
6192 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6193
6194 autoneg = hw->phy.autoneg_advertised;
6195 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6196 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6197 hw->mac.autotry_restart = false;
6198 if (hw->mac.ops.setup_link)
6199 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6200
6201 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6202 adapter->link_check_timeout = jiffies;
6203 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6204}
6205
6206/**
6207 * ixgbe_service_timer - Timer Call-back
6208 * @data: pointer to adapter cast into an unsigned long
6209 **/
6210static void ixgbe_service_timer(unsigned long data)
6211{
6212 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6213 unsigned long next_event_offset;
6214
6215 /* poll faster when waiting for link */
6216 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6217 next_event_offset = HZ / 10;
6218 else
6219 next_event_offset = HZ * 2;
6220
6221 /* Reset the timer */
6222 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6223
6224 ixgbe_service_event_schedule(adapter);
6225}
6226
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006227static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6228{
6229 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6230 return;
6231
6232 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6233
6234 /* If we're already down or resetting, just bail */
6235 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6236 test_bit(__IXGBE_RESETTING, &adapter->state))
6237 return;
6238
6239 ixgbe_dump(adapter);
6240 netdev_err(adapter->netdev, "Reset adapter\n");
6241 adapter->tx_timeout_count++;
6242
6243 ixgbe_reinit_locked(adapter);
6244}
6245
Alexander Duyck70864002011-04-27 09:13:56 +00006246/**
6247 * ixgbe_service_task - manages and runs subtasks
6248 * @work: pointer to work_struct containing our data
6249 **/
6250static void ixgbe_service_task(struct work_struct *work)
6251{
6252 struct ixgbe_adapter *adapter = container_of(work,
6253 struct ixgbe_adapter,
6254 service_task);
6255
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006256 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006257 ixgbe_sfp_detection_subtask(adapter);
6258 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006259 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006260 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006261 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006262 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006263
6264 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006265}
6266
Alexander Duyck897ab152011-05-27 05:31:47 +00006267void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6268 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006269{
6270 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006271 u16 i = tx_ring->next_to_use;
6272
6273 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6274
6275 i++;
6276 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6277
6278 /* set bits to identify this as an advanced context descriptor */
6279 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6280
6281 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6282 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6283 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6284 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6285}
6286
6287static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6288 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6289{
Auke Kok9a799d72007-09-15 14:07:45 -07006290 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006291 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006292 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006293
Alexander Duyck897ab152011-05-27 05:31:47 +00006294 if (!skb_is_gso(skb))
6295 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006296
Alexander Duyck897ab152011-05-27 05:31:47 +00006297 if (skb_header_cloned(skb)) {
6298 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6299 if (err)
6300 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006301 }
6302
Alexander Duyck897ab152011-05-27 05:31:47 +00006303 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6304 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6305
6306 if (protocol == __constant_htons(ETH_P_IP)) {
6307 struct iphdr *iph = ip_hdr(skb);
6308 iph->tot_len = 0;
6309 iph->check = 0;
6310 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6311 iph->daddr, 0,
6312 IPPROTO_TCP,
6313 0);
6314 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6315 } else if (skb_is_gso_v6(skb)) {
6316 ipv6_hdr(skb)->payload_len = 0;
6317 tcp_hdr(skb)->check =
6318 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6319 &ipv6_hdr(skb)->daddr,
6320 0, IPPROTO_TCP, 0);
6321 }
6322
6323 l4len = tcp_hdrlen(skb);
6324 *hdr_len = skb_transport_offset(skb) + l4len;
6325
6326 /* mss_l4len_id: use 1 as index for TSO */
6327 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6328 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6329 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6330
6331 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6332 vlan_macip_lens = skb_network_header_len(skb);
6333 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6334 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6335
6336 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6337 mss_l4len_idx);
6338
6339 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006340}
6341
Alexander Duyck897ab152011-05-27 05:31:47 +00006342static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006343 struct sk_buff *skb, u32 tx_flags,
6344 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006345{
Alexander Duyck897ab152011-05-27 05:31:47 +00006346 u32 vlan_macip_lens = 0;
6347 u32 mss_l4len_idx = 0;
6348 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006349
Alexander Duyck897ab152011-05-27 05:31:47 +00006350 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6351 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6352 return false;
6353 } else {
6354 u8 l4_hdr = 0;
6355 switch (protocol) {
6356 case __constant_htons(ETH_P_IP):
6357 vlan_macip_lens |= skb_network_header_len(skb);
6358 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6359 l4_hdr = ip_hdr(skb)->protocol;
6360 break;
6361 case __constant_htons(ETH_P_IPV6):
6362 vlan_macip_lens |= skb_network_header_len(skb);
6363 l4_hdr = ipv6_hdr(skb)->nexthdr;
6364 break;
6365 default:
6366 if (unlikely(net_ratelimit())) {
6367 dev_warn(tx_ring->dev,
6368 "partial checksum but proto=%x!\n",
6369 skb->protocol);
6370 }
6371 break;
6372 }
Auke Kok9a799d72007-09-15 14:07:45 -07006373
Alexander Duyck897ab152011-05-27 05:31:47 +00006374 switch (l4_hdr) {
6375 case IPPROTO_TCP:
6376 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6377 mss_l4len_idx = tcp_hdrlen(skb) <<
6378 IXGBE_ADVTXD_L4LEN_SHIFT;
6379 break;
6380 case IPPROTO_SCTP:
6381 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6382 mss_l4len_idx = sizeof(struct sctphdr) <<
6383 IXGBE_ADVTXD_L4LEN_SHIFT;
6384 break;
6385 case IPPROTO_UDP:
6386 mss_l4len_idx = sizeof(struct udphdr) <<
6387 IXGBE_ADVTXD_L4LEN_SHIFT;
6388 break;
6389 default:
6390 if (unlikely(net_ratelimit())) {
6391 dev_warn(tx_ring->dev,
6392 "partial checksum but l4 proto=%x!\n",
6393 skb->protocol);
6394 }
6395 break;
6396 }
Auke Kok9a799d72007-09-15 14:07:45 -07006397 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006398
Alexander Duyck897ab152011-05-27 05:31:47 +00006399 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6400 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6401
6402 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6403 type_tucmd, mss_l4len_idx);
6404
6405 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006406}
6407
6408static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006409 struct ixgbe_ring *tx_ring,
6410 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006411 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006412{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006413 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006414 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006415 unsigned int len;
6416 unsigned int total = skb->len;
Alexander Duyck63544e92011-05-27 05:31:42 +00006417 unsigned int offset = 0, size, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006418 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6419 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006420 unsigned int bytecount = skb->len;
6421 u16 gso_segs = 1;
Alexander Duyck63544e92011-05-27 05:31:42 +00006422 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07006423
6424 i = tx_ring->next_to_use;
6425
Yi Zoueacd73f2009-05-13 13:11:06 +00006426 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6427 /* excluding fcoe_crc_eof for FCoE */
6428 total -= sizeof(struct fcoe_crc_eof);
6429
6430 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006431 while (len) {
6432 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6433 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6434
6435 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006436 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006437 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006438 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006439 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006440 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006441 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006442 tx_buffer_info->time_stamp = jiffies;
6443 tx_buffer_info->next_to_watch = i;
6444
6445 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006446 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006447 offset += size;
6448 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006449
6450 if (len) {
6451 i++;
6452 if (i == tx_ring->count)
6453 i = 0;
6454 }
Auke Kok9a799d72007-09-15 14:07:45 -07006455 }
6456
6457 for (f = 0; f < nr_frags; f++) {
6458 struct skb_frag_struct *frag;
6459
6460 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006461 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006462 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006463
6464 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006465 i++;
6466 if (i == tx_ring->count)
6467 i = 0;
6468
Auke Kok9a799d72007-09-15 14:07:45 -07006469 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6470 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6471
6472 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006473 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006474 frag->page,
6475 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006476 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006477 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006478 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006479 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006480 tx_buffer_info->time_stamp = jiffies;
6481 tx_buffer_info->next_to_watch = i;
6482
6483 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006484 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006485 offset += size;
6486 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006487 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006488 if (total == 0)
6489 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006490 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006491
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006492 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6493 gso_segs = skb_shinfo(skb)->gso_segs;
6494#ifdef IXGBE_FCOE
6495 /* adjust for FCoE Sequence Offload */
6496 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6497 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6498 skb_shinfo(skb)->gso_size);
6499#endif /* IXGBE_FCOE */
6500 bytecount += (gso_segs - 1) * hdr_len;
6501
6502 /* multiply data chunks by size of headers */
6503 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6504 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006505 tx_ring->tx_buffer_info[i].skb = skb;
6506 tx_ring->tx_buffer_info[first].next_to_watch = i;
6507
6508 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006509
6510dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006511 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006512
6513 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6514 tx_buffer_info->dma = 0;
6515 tx_buffer_info->time_stamp = 0;
6516 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006517 if (count)
6518 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006519
6520 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006521 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006522 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006523 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006524 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006525 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006526 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006527 }
6528
Anton Blancharde44d38e2010-02-03 13:12:51 +00006529 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006530}
6531
Alexander Duyck84ea2592010-11-16 19:26:49 -08006532static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006533 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006534{
6535 union ixgbe_adv_tx_desc *tx_desc = NULL;
6536 struct ixgbe_tx_buffer *tx_buffer_info;
6537 u32 olinfo_status = 0, cmd_type_len = 0;
6538 unsigned int i;
6539 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6540
6541 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6542
6543 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6544
6545 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6546 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6547
6548 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6549 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6550
6551 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006552 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006553
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006554 /* use index 1 context for tso */
6555 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006556 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6557 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006558 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006559
6560 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6561 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006562 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006563
Yi Zoueacd73f2009-05-13 13:11:06 +00006564 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6565 olinfo_status |= IXGBE_ADVTXD_CC;
6566 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6567 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6568 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6569 }
6570
Auke Kok9a799d72007-09-15 14:07:45 -07006571 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6572
6573 i = tx_ring->next_to_use;
6574 while (count--) {
6575 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006576 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006577 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6578 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006579 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006580 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006581 i++;
6582 if (i == tx_ring->count)
6583 i = 0;
6584 }
6585
6586 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6587
6588 /*
6589 * Force memory writes to complete before letting h/w
6590 * know there are new descriptors to fetch. (Only
6591 * applicable for weak-ordered memory model archs,
6592 * such as IA-64).
6593 */
6594 wmb();
6595
6596 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006597 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006598}
6599
Alexander Duyck69830522011-01-06 14:29:58 +00006600static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6601 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006602{
Alexander Duyck69830522011-01-06 14:29:58 +00006603 struct ixgbe_q_vector *q_vector = ring->q_vector;
6604 union ixgbe_atr_hash_dword input = { .dword = 0 };
6605 union ixgbe_atr_hash_dword common = { .dword = 0 };
6606 union {
6607 unsigned char *network;
6608 struct iphdr *ipv4;
6609 struct ipv6hdr *ipv6;
6610 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006611 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006612 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006613
Alexander Duyck69830522011-01-06 14:29:58 +00006614 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6615 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006616 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006617
Alexander Duyck69830522011-01-06 14:29:58 +00006618 /* do nothing if sampling is disabled */
6619 if (!ring->atr_sample_rate)
6620 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006621
Alexander Duyck69830522011-01-06 14:29:58 +00006622 ring->atr_count++;
6623
6624 /* snag network header to get L4 type and address */
6625 hdr.network = skb_network_header(skb);
6626
6627 /* Currently only IPv4/IPv6 with TCP is supported */
6628 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6629 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6630 (protocol != __constant_htons(ETH_P_IP) ||
6631 hdr.ipv4->protocol != IPPROTO_TCP))
6632 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006633
6634 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006635
Alexander Duyck69830522011-01-06 14:29:58 +00006636 /* skip this packet since the socket is closing */
6637 if (th->fin)
6638 return;
6639
6640 /* sample on all syn packets or once every atr sample count */
6641 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6642 return;
6643
6644 /* reset sample count */
6645 ring->atr_count = 0;
6646
6647 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6648
6649 /*
6650 * src and dst are inverted, think how the receiver sees them
6651 *
6652 * The input is broken into two sections, a non-compressed section
6653 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6654 * is XORed together and stored in the compressed dword.
6655 */
6656 input.formatted.vlan_id = vlan_id;
6657
6658 /*
6659 * since src port and flex bytes occupy the same word XOR them together
6660 * and write the value to source port portion of compressed dword
6661 */
6662 if (vlan_id)
6663 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6664 else
6665 common.port.src ^= th->dest ^ protocol;
6666 common.port.dst ^= th->source;
6667
6668 if (protocol == __constant_htons(ETH_P_IP)) {
6669 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6670 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6671 } else {
6672 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6673 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6674 hdr.ipv6->saddr.s6_addr32[1] ^
6675 hdr.ipv6->saddr.s6_addr32[2] ^
6676 hdr.ipv6->saddr.s6_addr32[3] ^
6677 hdr.ipv6->daddr.s6_addr32[0] ^
6678 hdr.ipv6->daddr.s6_addr32[1] ^
6679 hdr.ipv6->daddr.s6_addr32[2] ^
6680 hdr.ipv6->daddr.s6_addr32[3];
6681 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006682
6683 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006684 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6685 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006686}
6687
Alexander Duyck63544e92011-05-27 05:31:42 +00006688static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006689{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006690 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006691 /* Herbert's original patch had:
6692 * smp_mb__after_netif_stop_queue();
6693 * but since that doesn't exist yet, just open code it. */
6694 smp_mb();
6695
6696 /* We need to check again in a case another CPU has just
6697 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006698 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006699 return -EBUSY;
6700
6701 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006702 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006703 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006704 return 0;
6705}
6706
Alexander Duyck82d4e462011-06-11 01:44:58 +00006707static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006708{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006709 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006710 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006711 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006712}
6713
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006714static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6715{
6716 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006717 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6718 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006719#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006720 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006721
John Fastabende5b64632011-03-08 03:44:52 +00006722 if (((protocol == htons(ETH_P_FCOE)) ||
6723 (protocol == htons(ETH_P_FIP))) &&
6724 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6725 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6726 txq += adapter->ring_feature[RING_F_FCOE].mask;
6727 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006728 }
6729#endif
6730
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006731 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6732 while (unlikely(txq >= dev->real_num_tx_queues))
6733 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006734 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006735 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006736
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006737 return skb_tx_hash(dev, skb);
6738}
6739
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006740netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006741 struct ixgbe_adapter *adapter,
6742 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006743{
Yi Zou5f715822009-12-03 11:32:44 +00006744 int tso;
Alexander Duycka535c302011-05-27 05:31:52 +00006745 u32 tx_flags = 0;
6746#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6747 unsigned short f;
6748#endif
Alexander Duyck63544e92011-05-27 05:31:42 +00006749 u16 first;
Alexander Duycka535c302011-05-27 05:31:52 +00006750 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Hao Zheng5e09a102010-11-11 13:47:59 +00006751 __be16 protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006752 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006753
Alexander Duycka535c302011-05-27 05:31:52 +00006754 /*
6755 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6756 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6757 * + 2 desc gap to keep tail from touching head,
6758 * + 1 desc for context descriptor,
6759 * otherwise try next time
6760 */
6761#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6762 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6763 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6764#else
6765 count += skb_shinfo(skb)->nr_frags;
6766#endif
6767 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6768 tx_ring->tx_stats.tx_busy++;
6769 return NETDEV_TX_BUSY;
6770 }
6771
Hao Zheng5e09a102010-11-11 13:47:59 +00006772 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006773
Jesse Grosseab6d182010-10-20 13:56:03 +00006774 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006775 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006776 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6777 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006778 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006779 }
6780 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6781 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006782 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6783 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006784 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006785 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6786 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006787 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006788
Yi Zou09ad1cc2009-09-03 14:56:10 +00006789#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006790 /* for FCoE with DCB, we force the priority to what
6791 * was specified by the switch */
6792 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006793 (protocol == htons(ETH_P_FCOE)))
6794 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Alexander Duycka535c302011-05-27 05:31:52 +00006795
Robert Loveca77cd52010-03-24 12:45:00 +00006796#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006797 /* record the location of the first descriptor for this packet */
Auke Kok9a799d72007-09-15 14:07:45 -07006798 first = tx_ring->next_to_use;
Alexander Duycka535c302011-05-27 05:31:52 +00006799
Yi Zoueacd73f2009-05-13 13:11:06 +00006800 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6801#ifdef IXGBE_FCOE
6802 /* setup tx offload for FCoE */
Alexander Duyck897ab152011-05-27 05:31:47 +00006803 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6804 if (tso < 0)
6805 goto out_drop;
6806 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006807 tx_flags |= IXGBE_TX_FLAGS_FSO;
6808#endif /* IXGBE_FCOE */
6809 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006810 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006811 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006812 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6813 if (tso < 0)
6814 goto out_drop;
6815 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006816 tx_flags |= IXGBE_TX_FLAGS_TSO;
Alexander Duyck897ab152011-05-27 05:31:47 +00006817 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
Yi Zoueacd73f2009-05-13 13:11:06 +00006818 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006819 }
6820
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006821 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006822 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006823 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006824 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6825 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006826 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006827 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006828
Alexander Duyck44df32c2009-03-31 21:34:23 +00006829 } else {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006830 tx_ring->tx_buffer_info[first].time_stamp = 0;
6831 tx_ring->next_to_use = first;
Alexander Duyck897ab152011-05-27 05:31:47 +00006832 goto out_drop;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006833 }
Auke Kok9a799d72007-09-15 14:07:45 -07006834
6835 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006836
6837out_drop:
6838 dev_kfree_skb_any(skb);
6839 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006840}
6841
Alexander Duyck84418e32010-08-19 13:40:54 +00006842static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6843{
6844 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6845 struct ixgbe_ring *tx_ring;
6846
6847 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006848 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006849}
6850
Auke Kok9a799d72007-09-15 14:07:45 -07006851/**
Auke Kok9a799d72007-09-15 14:07:45 -07006852 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6853 * @netdev: network interface device structure
6854 * @p: pointer to an address structure
6855 *
6856 * Returns 0 on success, negative on failure
6857 **/
6858static int ixgbe_set_mac(struct net_device *netdev, void *p)
6859{
6860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006861 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006862 struct sockaddr *addr = p;
6863
6864 if (!is_valid_ether_addr(addr->sa_data))
6865 return -EADDRNOTAVAIL;
6866
6867 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006868 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006869
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006870 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6871 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006872
6873 return 0;
6874}
6875
Ben Hutchings6b73e102009-04-29 08:08:58 +00006876static int
6877ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6878{
6879 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6880 struct ixgbe_hw *hw = &adapter->hw;
6881 u16 value;
6882 int rc;
6883
6884 if (prtad != hw->phy.mdio.prtad)
6885 return -EINVAL;
6886 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6887 if (!rc)
6888 rc = value;
6889 return rc;
6890}
6891
6892static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6893 u16 addr, u16 value)
6894{
6895 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6896 struct ixgbe_hw *hw = &adapter->hw;
6897
6898 if (prtad != hw->phy.mdio.prtad)
6899 return -EINVAL;
6900 return hw->phy.ops.write_reg(hw, addr, devad, value);
6901}
6902
6903static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6904{
6905 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6906
6907 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6908}
6909
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006910/**
6911 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006912 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006913 * @netdev: network interface device structure
6914 *
6915 * Returns non-zero on failure
6916 **/
6917static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6918{
6919 int err = 0;
6920 struct ixgbe_adapter *adapter = netdev_priv(dev);
6921 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6922
6923 if (is_valid_ether_addr(mac->san_addr)) {
6924 rtnl_lock();
6925 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6926 rtnl_unlock();
6927 }
6928 return err;
6929}
6930
6931/**
6932 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006933 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006934 * @netdev: network interface device structure
6935 *
6936 * Returns non-zero on failure
6937 **/
6938static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6939{
6940 int err = 0;
6941 struct ixgbe_adapter *adapter = netdev_priv(dev);
6942 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6943
6944 if (is_valid_ether_addr(mac->san_addr)) {
6945 rtnl_lock();
6946 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6947 rtnl_unlock();
6948 }
6949 return err;
6950}
6951
Auke Kok9a799d72007-09-15 14:07:45 -07006952#ifdef CONFIG_NET_POLL_CONTROLLER
6953/*
6954 * Polling 'interrupt' - used by things like netconsole to send skbs
6955 * without having to re-enable interrupts. It's not called while
6956 * the interrupt routine is executing.
6957 */
6958static void ixgbe_netpoll(struct net_device *netdev)
6959{
6960 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006961 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006962
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006963 /* if interface is down do nothing */
6964 if (test_bit(__IXGBE_DOWN, &adapter->state))
6965 return;
6966
Auke Kok9a799d72007-09-15 14:07:45 -07006967 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006968 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6969 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6970 for (i = 0; i < num_q_vectors; i++) {
6971 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
6972 ixgbe_msix_clean_many(0, q_vector);
6973 }
6974 } else {
6975 ixgbe_intr(adapter->pdev->irq, netdev);
6976 }
Auke Kok9a799d72007-09-15 14:07:45 -07006977 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006978}
6979#endif
6980
Eric Dumazetde1036b2010-10-20 23:00:04 +00006981static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6982 struct rtnl_link_stats64 *stats)
6983{
6984 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6985 int i;
6986
Eric Dumazet1a515022010-11-16 19:26:42 -08006987 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006988 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006989 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006990 u64 bytes, packets;
6991 unsigned int start;
6992
Eric Dumazet1a515022010-11-16 19:26:42 -08006993 if (ring) {
6994 do {
6995 start = u64_stats_fetch_begin_bh(&ring->syncp);
6996 packets = ring->stats.packets;
6997 bytes = ring->stats.bytes;
6998 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
6999 stats->rx_packets += packets;
7000 stats->rx_bytes += bytes;
7001 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007002 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007003
7004 for (i = 0; i < adapter->num_tx_queues; i++) {
7005 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7006 u64 bytes, packets;
7007 unsigned int start;
7008
7009 if (ring) {
7010 do {
7011 start = u64_stats_fetch_begin_bh(&ring->syncp);
7012 packets = ring->stats.packets;
7013 bytes = ring->stats.bytes;
7014 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7015 stats->tx_packets += packets;
7016 stats->tx_bytes += bytes;
7017 }
7018 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007019 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007020 /* following stats updated by ixgbe_watchdog_task() */
7021 stats->multicast = netdev->stats.multicast;
7022 stats->rx_errors = netdev->stats.rx_errors;
7023 stats->rx_length_errors = netdev->stats.rx_length_errors;
7024 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7025 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7026 return stats;
7027}
7028
John Fastabend8b1c0b22011-05-03 02:26:48 +00007029/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7030 * #adapter: pointer to ixgbe_adapter
7031 * @tc: number of traffic classes currently enabled
7032 *
7033 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7034 * 802.1Q priority maps to a packet buffer that exists.
7035 */
7036static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7037{
7038 struct ixgbe_hw *hw = &adapter->hw;
7039 u32 reg, rsave;
7040 int i;
7041
7042 /* 82598 have a static priority to TC mapping that can not
7043 * be changed so no validation is needed.
7044 */
7045 if (hw->mac.type == ixgbe_mac_82598EB)
7046 return;
7047
7048 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7049 rsave = reg;
7050
7051 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7052 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7053
7054 /* If up2tc is out of bounds default to zero */
7055 if (up2tc > tc)
7056 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7057 }
7058
7059 if (reg != rsave)
7060 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7061
7062 return;
7063}
7064
7065
7066/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7067 * classes.
7068 *
7069 * @netdev: net device to configure
7070 * @tc: number of traffic classes to enable
7071 */
7072int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7073{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007074 struct ixgbe_adapter *adapter = netdev_priv(dev);
7075 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007076
7077 /* If DCB is anabled do not remove traffic classes, multiple
7078 * traffic classes are required to implement DCB
7079 */
7080 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7081 return 0;
7082
7083 /* Hardware supports up to 8 traffic classes */
7084 if (tc > MAX_TRAFFIC_CLASS ||
7085 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7086 return -EINVAL;
7087
7088 /* Hardware has to reinitialize queues and interrupts to
7089 * match packet buffer alignment. Unfortunantly, the
7090 * hardware is not flexible enough to do this dynamically.
7091 */
7092 if (netif_running(dev))
7093 ixgbe_close(dev);
7094 ixgbe_clear_interrupt_scheme(adapter);
7095
7096 if (tc)
7097 netdev_set_num_tc(dev, tc);
7098 else
7099 netdev_reset_tc(dev);
7100
John Fastabend8b1c0b22011-05-03 02:26:48 +00007101 ixgbe_init_interrupt_scheme(adapter);
7102 ixgbe_validate_rtr(adapter, tc);
7103 if (netif_running(dev))
7104 ixgbe_open(dev);
7105
7106 return 0;
7107}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007108
Don Skidmore082757a2011-07-21 05:55:00 +00007109void ixgbe_do_reset(struct net_device *netdev)
7110{
7111 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7112
7113 if (netif_running(netdev))
7114 ixgbe_reinit_locked(adapter);
7115 else
7116 ixgbe_reset(adapter);
7117}
7118
7119static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7120{
7121 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7122
7123#ifdef CONFIG_DCB
7124 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7125 data &= ~NETIF_F_HW_VLAN_RX;
7126#endif
7127
7128 /* return error if RXHASH is being enabled when RSS is not supported */
7129 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7130 data &= ~NETIF_F_RXHASH;
7131
7132 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7133 if (!(data & NETIF_F_RXCSUM))
7134 data &= ~NETIF_F_LRO;
7135
7136 /* Turn off LRO if not RSC capable or invalid ITR settings */
7137 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7138 data &= ~NETIF_F_LRO;
7139 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7140 (adapter->rx_itr_setting != 1 &&
7141 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7142 data &= ~NETIF_F_LRO;
7143 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7144 }
7145
7146 return data;
7147}
7148
7149static int ixgbe_set_features(struct net_device *netdev, u32 data)
7150{
7151 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7152 bool need_reset = false;
7153
7154 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7155 if (!(data & NETIF_F_RXCSUM))
7156 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7157 else
7158 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7159
7160 /* Make sure RSC matches LRO, reset if change */
7161 if (!!(data & NETIF_F_LRO) !=
7162 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7163 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7164 switch (adapter->hw.mac.type) {
7165 case ixgbe_mac_X540:
7166 case ixgbe_mac_82599EB:
7167 need_reset = true;
7168 break;
7169 default:
7170 break;
7171 }
7172 }
7173
7174 /*
7175 * Check if Flow Director n-tuple support was enabled or disabled. If
7176 * the state changed, we need to reset.
7177 */
7178 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7179 /* turn off ATR, enable perfect filters and reset */
7180 if (data & NETIF_F_NTUPLE) {
7181 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7182 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7183 need_reset = true;
7184 }
7185 } else if (!(data & NETIF_F_NTUPLE)) {
7186 /* turn off Flow Director, set ATR and reset */
7187 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7188 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7189 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7190 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7191 need_reset = true;
7192 }
7193
7194 if (need_reset)
7195 ixgbe_do_reset(netdev);
7196
7197 return 0;
7198
7199}
7200
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007201static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007202 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007203 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007204 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007205 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007206 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007207 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7208 .ndo_validate_addr = eth_validate_addr,
7209 .ndo_set_mac_address = ixgbe_set_mac,
7210 .ndo_change_mtu = ixgbe_change_mtu,
7211 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007212 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7213 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007214 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007215 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7216 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7217 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7218 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007219 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007220 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007221#ifdef CONFIG_NET_POLL_CONTROLLER
7222 .ndo_poll_controller = ixgbe_netpoll,
7223#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007224#ifdef IXGBE_FCOE
7225 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007226 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007227 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007228 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7229 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007230 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007231#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007232 .ndo_set_features = ixgbe_set_features,
7233 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007234};
7235
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007236static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7237 const struct ixgbe_info *ii)
7238{
7239#ifdef CONFIG_PCI_IOV
7240 struct ixgbe_hw *hw = &adapter->hw;
7241 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007242 int num_vf_macvlans, i;
7243 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007244
Greg Rose3377eba792010-12-07 08:16:45 +00007245 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007246 return;
7247
7248 /* The 82599 supports up to 64 VFs per physical function
7249 * but this implementation limits allocation to 63 so that
7250 * basic networking resources are still available to the
7251 * physical function
7252 */
7253 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7254 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7255 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7256 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007257 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007258 goto err_novfs;
7259 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007260
7261 num_vf_macvlans = hw->mac.num_rar_entries -
7262 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7263
7264 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7265 sizeof(struct vf_macvlans),
7266 GFP_KERNEL);
7267 if (mv_list) {
7268 /* Initialize list of VF macvlans */
7269 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7270 for (i = 0; i < num_vf_macvlans; i++) {
7271 mv_list->vf = -1;
7272 mv_list->free = true;
7273 mv_list->rar_entry = hw->mac.num_rar_entries -
7274 (i + adapter->num_vfs + 1);
7275 list_add(&mv_list->l, &adapter->vf_mvs.l);
7276 mv_list++;
7277 }
7278 }
7279
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007280 /* If call to enable VFs succeeded then allocate memory
7281 * for per VF control structures.
7282 */
7283 adapter->vfinfo =
7284 kcalloc(adapter->num_vfs,
7285 sizeof(struct vf_data_storage), GFP_KERNEL);
7286 if (adapter->vfinfo) {
7287 /* Now that we're sure SR-IOV is enabled
7288 * and memory allocated set up the mailbox parameters
7289 */
7290 ixgbe_init_mbx_params_pf(hw);
7291 memcpy(&hw->mbx.ops, ii->mbx_ops,
7292 sizeof(hw->mbx.ops));
7293
7294 /* Disable RSC when in SR-IOV mode */
7295 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7296 IXGBE_FLAG2_RSC_ENABLED);
7297 return;
7298 }
7299
7300 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007301 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7302 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007303 pci_disable_sriov(adapter->pdev);
7304
7305err_novfs:
7306 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7307 adapter->num_vfs = 0;
7308#endif /* CONFIG_PCI_IOV */
7309}
7310
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007311/**
Auke Kok9a799d72007-09-15 14:07:45 -07007312 * ixgbe_probe - Device Initialization Routine
7313 * @pdev: PCI device information struct
7314 * @ent: entry in ixgbe_pci_tbl
7315 *
7316 * Returns 0 on success, negative on failure
7317 *
7318 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7319 * The OS initialization, configuring of the adapter private structure,
7320 * and a hardware reset occur.
7321 **/
7322static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007323 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007324{
7325 struct net_device *netdev;
7326 struct ixgbe_adapter *adapter = NULL;
7327 struct ixgbe_hw *hw;
7328 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007329 static int cards_found;
7330 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007331 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007332 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007333#ifdef IXGBE_FCOE
7334 u16 device_caps;
7335#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007336 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007337
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007338 /* Catch broken hardware that put the wrong VF device ID in
7339 * the PCIe SR-IOV capability.
7340 */
7341 if (pdev->is_virtfn) {
7342 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7343 pci_name(pdev), pdev->vendor, pdev->device);
7344 return -EINVAL;
7345 }
7346
gouji-new9ce77662009-05-06 10:44:45 +00007347 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007348 if (err)
7349 return err;
7350
Nick Nunley1b507732010-04-27 13:10:27 +00007351 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7352 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007353 pci_using_dac = 1;
7354 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007355 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007356 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007357 err = dma_set_coherent_mask(&pdev->dev,
7358 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007359 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007360 dev_err(&pdev->dev,
7361 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007362 goto err_dma;
7363 }
7364 }
7365 pci_using_dac = 0;
7366 }
7367
gouji-new9ce77662009-05-06 10:44:45 +00007368 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007369 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007370 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007371 dev_err(&pdev->dev,
7372 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007373 goto err_pci_reg;
7374 }
7375
Frans Pop19d5afd2009-10-02 10:04:12 -07007376 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007377
Auke Kok9a799d72007-09-15 14:07:45 -07007378 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007379 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007380
John Fastabende901acd2011-04-26 07:26:08 +00007381#ifdef CONFIG_IXGBE_DCB
7382 indices *= MAX_TRAFFIC_CLASS;
7383#endif
7384
John Fastabendc85a2612010-02-25 23:15:21 +00007385 if (ii->mac == ixgbe_mac_82598EB)
7386 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7387 else
7388 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7389
John Fastabende901acd2011-04-26 07:26:08 +00007390#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007391 indices += min_t(unsigned int, num_possible_cpus(),
7392 IXGBE_MAX_FCOE_INDICES);
7393#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007394 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007395 if (!netdev) {
7396 err = -ENOMEM;
7397 goto err_alloc_etherdev;
7398 }
7399
Auke Kok9a799d72007-09-15 14:07:45 -07007400 SET_NETDEV_DEV(netdev, &pdev->dev);
7401
Auke Kok9a799d72007-09-15 14:07:45 -07007402 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007403 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007404
7405 adapter->netdev = netdev;
7406 adapter->pdev = pdev;
7407 hw = &adapter->hw;
7408 hw->back = adapter;
7409 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7410
Jeff Kirsher05857982008-09-11 19:57:00 -07007411 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007412 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007413 if (!hw->hw_addr) {
7414 err = -EIO;
7415 goto err_ioremap;
7416 }
7417
7418 for (i = 1; i <= 5; i++) {
7419 if (pci_resource_len(pdev, i) == 0)
7420 continue;
7421 }
7422
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007423 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007424 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007425 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007426 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007427
Auke Kok9a799d72007-09-15 14:07:45 -07007428 adapter->bd_number = cards_found;
7429
Auke Kok9a799d72007-09-15 14:07:45 -07007430 /* Setup hw api */
7431 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007432 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007433
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007434 /* EEPROM */
7435 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7436 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7437 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7438 if (!(eec & (1 << 8)))
7439 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7440
7441 /* PHY */
7442 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007443 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007444 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7445 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7446 hw->phy.mdio.mmds = 0;
7447 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7448 hw->phy.mdio.dev = netdev;
7449 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7450 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007451
Don Skidmore8ca783a2009-05-26 20:40:47 -07007452 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007453
7454 /* setup the private structure */
7455 err = ixgbe_sw_init(adapter);
7456 if (err)
7457 goto err_sw_init;
7458
Don Skidmoree86bff02010-02-11 04:14:08 +00007459 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007460 switch (adapter->hw.mac.type) {
7461 case ixgbe_mac_82599EB:
7462 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007463 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007464 break;
7465 default:
7466 break;
7467 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007468
Don Skidmorebf069c92009-05-07 10:39:54 +00007469 /*
7470 * If there is a fan on this device and it has failed log the
7471 * failure.
7472 */
7473 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7474 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7475 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007476 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007477 }
7478
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007479 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007480 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007481 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007482 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007483 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7484 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007485 err = 0;
7486 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007487 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007488 "module type was detected.\n");
7489 e_dev_err("Reload the driver after installing a supported "
7490 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007491 goto err_sw_init;
7492 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007493 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007494 goto err_sw_init;
7495 }
7496
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007497 ixgbe_probe_vf(adapter, ii);
7498
Emil Tantilov396e7992010-07-01 20:05:12 +00007499 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007500 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007501 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007502 NETIF_F_HW_VLAN_TX |
7503 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007504 NETIF_F_HW_VLAN_FILTER |
7505 NETIF_F_TSO |
7506 NETIF_F_TSO6 |
7507 NETIF_F_GRO |
7508 NETIF_F_RXHASH |
7509 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007510
Don Skidmore082757a2011-07-21 05:55:00 +00007511 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007512
Don Skidmore58be7662011-04-12 09:42:11 +00007513 switch (adapter->hw.mac.type) {
7514 case ixgbe_mac_82599EB:
7515 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007516 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007517 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7518 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007519 break;
7520 default:
7521 break;
7522 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007523
Jeff Kirsherad31c402008-06-05 04:05:30 -07007524 netdev->vlan_features |= NETIF_F_TSO;
7525 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007526 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007527 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007528 netdev->vlan_features |= NETIF_F_SG;
7529
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007530 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7531 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7532 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007533
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007534#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007535 netdev->dcbnl_ops = &dcbnl_ops;
7536#endif
7537
Yi Zoueacd73f2009-05-13 13:11:06 +00007538#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007539 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007540 if (hw->mac.ops.get_device_caps) {
7541 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007542 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7543 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007544 }
7545 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007546 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7547 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7548 netdev->vlan_features |= NETIF_F_FSO;
7549 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7550 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007551#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007552 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007553 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007554 netdev->vlan_features |= NETIF_F_HIGHDMA;
7555 }
Auke Kok9a799d72007-09-15 14:07:45 -07007556
Don Skidmore082757a2011-07-21 05:55:00 +00007557 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7558 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007559 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007560 netdev->features |= NETIF_F_LRO;
7561
Auke Kok9a799d72007-09-15 14:07:45 -07007562 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007563 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007564 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007565 err = -EIO;
7566 goto err_eeprom;
7567 }
7568
7569 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7570 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7571
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007572 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007573 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007574 err = -EIO;
7575 goto err_eeprom;
7576 }
7577
Don Skidmorec6ecf392010-12-03 03:31:51 +00007578 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7579 if (hw->mac.ops.disable_tx_laser &&
7580 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007581 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007582 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007583 hw->mac.ops.disable_tx_laser(hw);
7584
Alexander Duyck70864002011-04-27 09:13:56 +00007585 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7586 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007587
Alexander Duyck70864002011-04-27 09:13:56 +00007588 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7589 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007590
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007591 err = ixgbe_init_interrupt_scheme(adapter);
7592 if (err)
7593 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007594
Don Skidmore082757a2011-07-21 05:55:00 +00007595 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7596 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007597 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007598 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007599
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007600 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007601 case IXGBE_DEV_ID_82599_SFP:
7602 /* Only this subdevice supports WOL */
7603 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007604 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007605 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007606 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7607 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007608 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007609 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007610 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007611 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007612 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007613 break;
7614 default:
7615 adapter->wol = 0;
7616 break;
7617 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007618 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7619
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007620 /* pick up the PCI bus settings for reporting later */
7621 hw->mac.ops.get_bus_info(hw);
7622
Auke Kok9a799d72007-09-15 14:07:45 -07007623 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007624 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007625 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7626 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007627 "Unknown"),
7628 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7629 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7630 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7631 "Unknown"),
7632 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007633
7634 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7635 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007636 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007637 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007638 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007639 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007640 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007641 else
Don Skidmore289700db2010-12-03 03:32:58 +00007642 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7643 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007644
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007645 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007646 e_dev_warn("PCI-Express bandwidth available for this card is "
7647 "not sufficient for optimal performance.\n");
7648 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7649 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007650 }
7651
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007652 /* save off EEPROM version number */
7653 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7654
Auke Kok9a799d72007-09-15 14:07:45 -07007655 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007656 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007657
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007658 if (err == IXGBE_ERR_EEPROM_VERSION) {
7659 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007660 e_dev_warn("This device is a pre-production adapter/LOM. "
7661 "Please be aware there may be issues associated "
7662 "with your hardware. If you are experiencing "
7663 "problems please contact your Intel or hardware "
7664 "representative who provided you with this "
7665 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007666 }
Auke Kok9a799d72007-09-15 14:07:45 -07007667 strcpy(netdev->name, "eth%d");
7668 err = register_netdev(netdev);
7669 if (err)
7670 goto err_register;
7671
Jesse Brandeburg54386462009-04-17 20:44:27 +00007672 /* carrier off reporting is important to ethtool even BEFORE open */
7673 netif_carrier_off(netdev);
7674
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007675#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007676 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007677 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007678 ixgbe_setup_dca(adapter);
7679 }
7680#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007681 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007682 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007683 for (i = 0; i < adapter->num_vfs; i++)
7684 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7685 }
7686
Emil Tantilov9612de92011-05-07 07:40:20 +00007687 /* Inform firmware of driver version */
7688 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007689 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7690 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007691
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007692 /* add san mac addr to netdev */
7693 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007694
Emil Tantilov849c4542010-06-03 16:53:41 +00007695 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007696 cards_found++;
7697 return 0;
7698
7699err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007700 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007701 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007702err_sw_init:
7703err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007704 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7705 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007706 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007707 iounmap(hw->hw_addr);
7708err_ioremap:
7709 free_netdev(netdev);
7710err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007711 pci_release_selected_regions(pdev,
7712 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007713err_pci_reg:
7714err_dma:
7715 pci_disable_device(pdev);
7716 return err;
7717}
7718
7719/**
7720 * ixgbe_remove - Device Removal Routine
7721 * @pdev: PCI device information struct
7722 *
7723 * ixgbe_remove is called by the PCI subsystem to alert the driver
7724 * that it should release a PCI device. The could be caused by a
7725 * Hot-Plug event, or because the driver is going to be removed from
7726 * memory.
7727 **/
7728static void __devexit ixgbe_remove(struct pci_dev *pdev)
7729{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007730 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7731 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007732
7733 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007734 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007735
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007736#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007737 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7738 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7739 dca_remove_requester(&pdev->dev);
7740 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7741 }
7742
7743#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007744#ifdef IXGBE_FCOE
7745 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7746 ixgbe_cleanup_fcoe(adapter);
7747
7748#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007749
7750 /* remove the added san mac */
7751 ixgbe_del_sanmac_netdev(netdev);
7752
Donald Skidmorec4900be2008-11-20 21:11:42 -08007753 if (netdev->reg_state == NETREG_REGISTERED)
7754 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007755
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007756 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7757 ixgbe_disable_sriov(adapter);
7758
Alexander Duyck7a921c92009-05-06 10:43:28 +00007759 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007760
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007761 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007762
7763 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007764 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007765 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007766
Emil Tantilov849c4542010-06-03 16:53:41 +00007767 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007768
Auke Kok9a799d72007-09-15 14:07:45 -07007769 free_netdev(netdev);
7770
Frans Pop19d5afd2009-10-02 10:04:12 -07007771 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007772
Auke Kok9a799d72007-09-15 14:07:45 -07007773 pci_disable_device(pdev);
7774}
7775
7776/**
7777 * ixgbe_io_error_detected - called when PCI error is detected
7778 * @pdev: Pointer to PCI device
7779 * @state: The current pci connection state
7780 *
7781 * This function is called after a PCI bus error affecting
7782 * this device has been detected.
7783 */
7784static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007785 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007786{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007787 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7788 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007789
7790 netif_device_detach(netdev);
7791
Breno Leitao3044b8d2009-05-06 10:44:26 +00007792 if (state == pci_channel_io_perm_failure)
7793 return PCI_ERS_RESULT_DISCONNECT;
7794
Auke Kok9a799d72007-09-15 14:07:45 -07007795 if (netif_running(netdev))
7796 ixgbe_down(adapter);
7797 pci_disable_device(pdev);
7798
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007799 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007800 return PCI_ERS_RESULT_NEED_RESET;
7801}
7802
7803/**
7804 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7805 * @pdev: Pointer to PCI device
7806 *
7807 * Restart the card from scratch, as if from a cold-boot.
7808 */
7809static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7810{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007811 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007812 pci_ers_result_t result;
7813 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007814
gouji-new9ce77662009-05-06 10:44:45 +00007815 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007816 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007817 result = PCI_ERS_RESULT_DISCONNECT;
7818 } else {
7819 pci_set_master(pdev);
7820 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007821 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007822
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007823 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007824
7825 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007826 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007827 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007828 }
Auke Kok9a799d72007-09-15 14:07:45 -07007829
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007830 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7831 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007832 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7833 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007834 /* non-fatal, continue */
7835 }
Auke Kok9a799d72007-09-15 14:07:45 -07007836
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007837 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007838}
7839
7840/**
7841 * ixgbe_io_resume - called when traffic can start flowing again.
7842 * @pdev: Pointer to PCI device
7843 *
7844 * This callback is called when the error recovery driver tells us that
7845 * its OK to resume normal operation.
7846 */
7847static void ixgbe_io_resume(struct pci_dev *pdev)
7848{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007849 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7850 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007851
7852 if (netif_running(netdev)) {
7853 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007854 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007855 return;
7856 }
7857 }
7858
7859 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007860}
7861
7862static struct pci_error_handlers ixgbe_err_handler = {
7863 .error_detected = ixgbe_io_error_detected,
7864 .slot_reset = ixgbe_io_slot_reset,
7865 .resume = ixgbe_io_resume,
7866};
7867
7868static struct pci_driver ixgbe_driver = {
7869 .name = ixgbe_driver_name,
7870 .id_table = ixgbe_pci_tbl,
7871 .probe = ixgbe_probe,
7872 .remove = __devexit_p(ixgbe_remove),
7873#ifdef CONFIG_PM
7874 .suspend = ixgbe_suspend,
7875 .resume = ixgbe_resume,
7876#endif
7877 .shutdown = ixgbe_shutdown,
7878 .err_handler = &ixgbe_err_handler
7879};
7880
7881/**
7882 * ixgbe_init_module - Driver Registration Routine
7883 *
7884 * ixgbe_init_module is the first routine called when the driver is
7885 * loaded. All it does is register with the PCI subsystem.
7886 **/
7887static int __init ixgbe_init_module(void)
7888{
7889 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007890 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007891 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007892
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007893#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007894 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007895#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007896
Auke Kok9a799d72007-09-15 14:07:45 -07007897 ret = pci_register_driver(&ixgbe_driver);
7898 return ret;
7899}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007900
Auke Kok9a799d72007-09-15 14:07:45 -07007901module_init(ixgbe_init_module);
7902
7903/**
7904 * ixgbe_exit_module - Driver Exit Cleanup Routine
7905 *
7906 * ixgbe_exit_module is called just before the driver is removed
7907 * from memory.
7908 **/
7909static void __exit ixgbe_exit_module(void)
7910{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007911#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007912 dca_unregister_notify(&dca_notifier);
7913#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007914 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007915 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007916}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007917
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007918#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007919static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007920 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007921{
7922 int ret_val;
7923
7924 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007925 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007926
7927 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7928}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007929
Alexander Duyckb4533682009-03-31 21:32:42 +00007930#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007931
Auke Kok9a799d72007-09-15 14:07:45 -07007932module_exit(ixgbe_exit_module);
7933
7934/* ixgbe_main.c */