blob: 22790394318a06085290e179f88647e97480271b [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 Skidmorefe15e8e2010-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
Don Skidmore2a72c312011-07-20 02:27:05 +00001009 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001010 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);
Alexander Duyck63d635b2011-06-02 04:29:23 +00001462 if (!ddp_bytes) {
1463 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001464 goto next_desc;
Alexander Duyck63d635b2011-06-02 04:29:23 +00001465 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001466 }
Yi Zou332d4a72009-05-13 13:11:53 +00001467#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001468 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001469
1470next_desc:
1471 rx_desc->wb.upper.status_error = 0;
1472
Alexander Duyckc267fc12010-11-16 19:27:00 -08001473 (*work_done)++;
1474 if (*work_done >= work_to_do)
1475 break;
1476
Auke Kok9a799d72007-09-15 14:07:45 -07001477 /* return some buffers to hardware, one at a time is too slow */
1478 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001479 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001480 cleaned_count = 0;
1481 }
1482
1483 /* use prefetched values */
1484 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001485 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001486 }
1487
Auke Kok9a799d72007-09-15 14:07:45 -07001488 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001489 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001490
1491 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001492 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001493
Yi Zou3d8fd382009-06-08 14:38:44 +00001494#ifdef IXGBE_FCOE
1495 /* include DDPed FCoE data */
1496 if (ddp_bytes > 0) {
1497 unsigned int mss;
1498
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001499 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001500 sizeof(struct fc_frame_header) -
1501 sizeof(struct fcoe_crc_eof);
1502 if (mss > 512)
1503 mss &= ~511;
1504 total_rx_bytes += ddp_bytes;
1505 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1506 }
1507#endif /* IXGBE_FCOE */
1508
Alexander Duyckc267fc12010-11-16 19:27:00 -08001509 u64_stats_update_begin(&rx_ring->syncp);
1510 rx_ring->stats.packets += total_rx_packets;
1511 rx_ring->stats.bytes += total_rx_bytes;
1512 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001513 q_vector->rx.total_packets += total_rx_packets;
1514 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001515}
1516
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001517static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001518/**
1519 * ixgbe_configure_msix - Configure MSI-X hardware
1520 * @adapter: board private structure
1521 *
1522 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1523 * interrupts.
1524 **/
1525static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1526{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001527 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001528 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001529 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001530
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001531 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1532
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001533 /*
1534 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001535 * corresponding register.
1536 */
1537 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001538 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001539 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001540 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001541 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001542
Alexander Duyck08c88332011-06-11 01:45:03 +00001543 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001544 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1545 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001546 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001547 adapter->num_rx_queues,
1548 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001549 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001550 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001551 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001552
Alexander Duyck08c88332011-06-11 01:45:03 +00001553 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001554 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1555 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001556 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001557 adapter->num_tx_queues,
1558 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001559 }
1560
Alexander Duyck08c88332011-06-11 01:45:03 +00001561 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001562 /* tx only */
1563 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001564 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001565 /* rx or mixed */
1566 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001567
Alexander Duyckfe49f042009-06-04 16:00:09 +00001568 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001569 /* If ATR is enabled, set interrupt affinity */
1570 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001571 /*
1572 * Allocate the affinity_hint cpumask, assign the mask
1573 * for this vector, and set our affinity_hint for
1574 * this irq.
1575 */
1576 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1577 GFP_KERNEL))
1578 return;
1579 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1580 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1581 q_vector->affinity_mask);
1582 }
Auke Kok9a799d72007-09-15 14:07:45 -07001583 }
1584
Alexander Duyckbd508172010-11-16 19:27:03 -08001585 switch (adapter->hw.mac.type) {
1586 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001587 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001588 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001589 break;
1590 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001591 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001592 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001593 break;
1594
1595 default:
1596 break;
1597 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001598 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001599
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001600 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001601 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001602 if (adapter->num_vfs)
1603 mask &= ~(IXGBE_EIMS_OTHER |
1604 IXGBE_EIMS_MAILBOX |
1605 IXGBE_EIMS_LSC);
1606 else
1607 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001608 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001609}
1610
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001611enum latency_range {
1612 lowest_latency = 0,
1613 low_latency = 1,
1614 bulk_latency = 2,
1615 latency_invalid = 255
1616};
1617
1618/**
1619 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001620 * @q_vector: structure containing interrupt and ring information
1621 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001622 *
1623 * Stores a new ITR value based on packets and byte
1624 * counts during the last interrupt. The advantage of per interrupt
1625 * computation is faster updates and more accurate ITR for the current
1626 * traffic pattern. Constants in this function were computed
1627 * based on theoretical maximum wire speed and thresholds were set based
1628 * on testing data as well as attempting to minimize response time
1629 * while increasing bulk throughput.
1630 * this functionality is controlled by the InterruptThrottleRate module
1631 * parameter (see ixgbe_param.c)
1632 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001633static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1634 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001635{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001636 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001637 struct ixgbe_adapter *adapter = q_vector->adapter;
1638 int bytes = ring_container->total_bytes;
1639 int packets = ring_container->total_packets;
1640 u32 timepassed_us;
1641 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001642
1643 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001644 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001645
1646 /* simple throttlerate management
1647 * 0-20MB/s lowest (100000 ints/s)
1648 * 20-100MB/s low (20000 ints/s)
1649 * 100-1249MB/s bulk (8000 ints/s)
1650 */
1651 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001652 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001653 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1654
1655 switch (itr_setting) {
1656 case lowest_latency:
1657 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001658 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001659 break;
1660 case low_latency:
1661 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001662 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001663 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001664 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001665 break;
1666 case bulk_latency:
1667 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001668 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001669 break;
1670 }
1671
Alexander Duyckbd198052011-06-11 01:45:08 +00001672 /* clear work counters since we have the values we need */
1673 ring_container->total_bytes = 0;
1674 ring_container->total_packets = 0;
1675
1676 /* write updated itr to ring container */
1677 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001678}
1679
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001680/**
1681 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001682 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001683 *
1684 * This function is made to be called by ethtool and by the driver
1685 * when it needs to update EITR registers at runtime. Hardware
1686 * specific quirks/differences are taken care of here.
1687 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001688void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001689{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001690 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001691 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001692 int v_idx = q_vector->v_idx;
1693 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1694
Alexander Duyckbd508172010-11-16 19:27:03 -08001695 switch (adapter->hw.mac.type) {
1696 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001697 /* must write high and low 16 bits to reset counter */
1698 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001699 break;
1700 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001701 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001702 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001703 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001704 * max interrupt rate, but there is an errata where it can
1705 * not be zero with RSC
1706 */
1707 if (itr_reg == 8 &&
1708 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1709 itr_reg = 0;
1710
1711 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001712 * set the WDIS bit to not clear the timer bits and cause an
1713 * immediate assertion of the interrupt
1714 */
1715 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001716 break;
1717 default:
1718 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001719 }
1720 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1721}
1722
Alexander Duyckbd198052011-06-11 01:45:08 +00001723static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001724{
Alexander Duyckbd198052011-06-11 01:45:08 +00001725 u32 new_itr = q_vector->eitr;
1726 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001727
Alexander Duyckbd198052011-06-11 01:45:08 +00001728 ixgbe_update_itr(q_vector, &q_vector->tx);
1729 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001730
Alexander Duyck08c88332011-06-11 01:45:03 +00001731 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001732
1733 switch (current_itr) {
1734 /* counts and packets in update_itr are dependent on these numbers */
1735 case lowest_latency:
1736 new_itr = 100000;
1737 break;
1738 case low_latency:
1739 new_itr = 20000; /* aka hwitr = ~200 */
1740 break;
1741 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001742 new_itr = 8000;
1743 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001744 default:
1745 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001746 }
1747
1748 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001749 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001750 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001751
Alexander Duyckbd198052011-06-11 01:45:08 +00001752 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001753 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001754
1755 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001756 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001757}
1758
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001759/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001760 * ixgbe_check_overtemp_subtask - check for over tempurature
1761 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001762 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001763static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001764{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001765 struct ixgbe_hw *hw = &adapter->hw;
1766 u32 eicr = adapter->interrupt_event;
1767
Alexander Duyckf0f97782011-04-22 04:08:09 +00001768 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001769 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001770
Alexander Duyckf0f97782011-04-22 04:08:09 +00001771 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1772 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1773 return;
1774
1775 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1776
Joe Perches7ca647b2010-09-07 21:35:40 +00001777 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001778 case IXGBE_DEV_ID_82599_T3_LOM:
1779 /*
1780 * Since the warning interrupt is for both ports
1781 * we don't have to check if:
1782 * - This interrupt wasn't for our port.
1783 * - We may have missed the interrupt so always have to
1784 * check if we got a LSC
1785 */
1786 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1787 !(eicr & IXGBE_EICR_LSC))
1788 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001789
Alexander Duyckf0f97782011-04-22 04:08:09 +00001790 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1791 u32 autoneg;
1792 bool link_up = false;
1793
Joe Perches7ca647b2010-09-07 21:35:40 +00001794 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1795
Alexander Duyckf0f97782011-04-22 04:08:09 +00001796 if (link_up)
1797 return;
1798 }
1799
1800 /* Check if this is not due to overtemp */
1801 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1802 return;
1803
1804 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001805 default:
1806 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1807 return;
1808 break;
1809 }
1810 e_crit(drv,
1811 "Network adapter has been stopped because it has over heated. "
1812 "Restart the computer. If the problem persists, "
1813 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001814
1815 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001816}
1817
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001818static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1819{
1820 struct ixgbe_hw *hw = &adapter->hw;
1821
1822 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1823 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001824 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001825 /* write to clear the interrupt */
1826 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1827 }
1828}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001829
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001830static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1831{
1832 struct ixgbe_hw *hw = &adapter->hw;
1833
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001834 if (eicr & IXGBE_EICR_GPI_SDP2) {
1835 /* Clear the interrupt */
1836 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001837 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1838 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1839 ixgbe_service_event_schedule(adapter);
1840 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001841 }
1842
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001843 if (eicr & IXGBE_EICR_GPI_SDP1) {
1844 /* Clear the interrupt */
1845 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001846 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1847 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1848 ixgbe_service_event_schedule(adapter);
1849 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001850 }
1851}
1852
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001853static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1854{
1855 struct ixgbe_hw *hw = &adapter->hw;
1856
1857 adapter->lsc_int++;
1858 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1859 adapter->link_check_timeout = jiffies;
1860 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1861 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001862 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001863 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001864 }
1865}
1866
Auke Kok9a799d72007-09-15 14:07:45 -07001867static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1868{
Alexander Duycka65151b2011-05-27 05:31:32 +00001869 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001870 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001871 u32 eicr;
1872
1873 /*
1874 * Workaround for Silicon errata. Use clear-by-write instead
1875 * of clear-by-read. Reading with EICS will return the
1876 * interrupt causes without clearing, which later be done
1877 * with the write to EICR.
1878 */
1879 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1880 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001881
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001882 if (eicr & IXGBE_EICR_LSC)
1883 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001884
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001885 if (eicr & IXGBE_EICR_MAILBOX)
1886 ixgbe_msg_task(adapter);
1887
Alexander Duyckbd508172010-11-16 19:27:03 -08001888 switch (hw->mac.type) {
1889 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001890 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001891 /* Handle Flow Director Full threshold interrupt */
1892 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001893 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001894 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001895 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001896 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001897 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001898 &ring->state))
1899 reinit_count++;
1900 }
1901 if (reinit_count) {
1902 /* no more flow director interrupts until after init */
1903 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1904 eicr &= ~IXGBE_EICR_FLOW_DIR;
1905 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1906 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001907 }
1908 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001909 ixgbe_check_sfp_event(adapter, eicr);
1910 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1911 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1912 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1913 adapter->interrupt_event = eicr;
1914 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1915 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001916 }
1917 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001918 break;
1919 default:
1920 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001921 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001922
1923 ixgbe_check_fan_failure(adapter, eicr);
1924
Alexander Duyck70864002011-04-27 09:13:56 +00001925 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001926 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001927 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1928 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001929
1930 return IRQ_HANDLED;
1931}
1932
Alexander Duyckfe49f042009-06-04 16:00:09 +00001933static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1934 u64 qmask)
1935{
1936 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001937 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001938
Alexander Duyckbd508172010-11-16 19:27:03 -08001939 switch (hw->mac.type) {
1940 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001941 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001942 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1943 break;
1944 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001945 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001946 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001947 if (mask)
1948 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001949 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001950 if (mask)
1951 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1952 break;
1953 default:
1954 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001955 }
1956 /* skip the flush */
1957}
1958
1959static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001960 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001961{
1962 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001963 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001964
Alexander Duyckbd508172010-11-16 19:27:03 -08001965 switch (hw->mac.type) {
1966 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001967 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001968 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1969 break;
1970 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001971 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001972 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001973 if (mask)
1974 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001975 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001976 if (mask)
1977 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1978 break;
1979 default:
1980 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001981 }
1982 /* skip the flush */
1983}
1984
Auke Kok9a799d72007-09-15 14:07:45 -07001985static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1986{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001987 struct ixgbe_q_vector *q_vector = data;
1988 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001989 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001990 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001991
Alexander Duyck08c88332011-06-11 01:45:03 +00001992 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001993 return IRQ_HANDLED;
1994
Alexander Duyck08c88332011-06-11 01:45:03 +00001995 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
1996 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00001997 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00001998 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001999 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002000 }
2001
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002002 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002003 napi_schedule(&q_vector->napi);
2004
Auke Kok9a799d72007-09-15 14:07:45 -07002005 return IRQ_HANDLED;
2006}
2007
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002008/**
2009 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2010 * @irq: unused
2011 * @data: pointer to our q_vector struct for this interrupt vector
2012 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002013static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2014{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002015 struct ixgbe_q_vector *q_vector = data;
2016 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002017 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002018 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002019 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002020
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002021#ifdef CONFIG_IXGBE_DCA
2022 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2023 ixgbe_update_dca(q_vector);
2024#endif
2025
Alexander Duyck08c88332011-06-11 01:45:03 +00002026 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2027 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002028 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002029 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002030 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002031 }
2032
Alexander Duyck08c88332011-06-11 01:45:03 +00002033 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002034 return IRQ_HANDLED;
2035
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002036 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002037 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002038
Auke Kok9a799d72007-09-15 14:07:45 -07002039 return IRQ_HANDLED;
2040}
2041
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002042static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2043{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002044 struct ixgbe_q_vector *q_vector = data;
2045 struct ixgbe_adapter *adapter = q_vector->adapter;
2046 struct ixgbe_ring *ring;
2047 int r_idx;
2048 int i;
2049
Alexander Duyck08c88332011-06-11 01:45:03 +00002050 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002051 return IRQ_HANDLED;
2052
Alexander Duyck08c88332011-06-11 01:45:03 +00002053 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2054 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002055 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002056 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002057 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002058 }
2059
Alexander Duyck08c88332011-06-11 01:45:03 +00002060 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2061 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002062 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002063 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002064 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002065 }
2066
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002067 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002068 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002069
2070 return IRQ_HANDLED;
2071}
2072
2073/**
2074 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2075 * @napi: napi struct with our devices info in it
2076 * @budget: amount of work driver is allowed to do this pass, in packets
2077 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002078 * This function is optimized for cleaning one queue only on a single
2079 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002080 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002081static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2082{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002083 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002084 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002085 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002086 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002087 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002088 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002089
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002090#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002091 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002092 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002093#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002094
Alexander Duyck08c88332011-06-11 01:45:03 +00002095 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002096 rx_ring = adapter->rx_ring[r_idx];
2097
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002098 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002099
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002100 /* If all Rx work done, exit the polling mode */
2101 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002102 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002103 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002104 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002105 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002106 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002107 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002108 }
2109
2110 return work_done;
2111}
2112
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002113/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002114 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002115 * @napi: napi struct with our devices info in it
2116 * @budget: amount of work driver is allowed to do this pass, in packets
2117 *
2118 * This function will clean more than one rx queue associated with a
2119 * q_vector.
2120 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002121static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002122{
2123 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002124 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002125 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002126 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002127 int work_done = 0, i;
2128 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002129 bool tx_clean_complete = true;
2130
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002131#ifdef CONFIG_IXGBE_DCA
2132 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2133 ixgbe_update_dca(q_vector);
2134#endif
2135
Alexander Duyck08c88332011-06-11 01:45:03 +00002136 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2137 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002138 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002139 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002140 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002141 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002142 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002143
2144 /* attempt to distribute budget to each queue fairly, but don't allow
2145 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002146 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002147 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002148 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2149 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002150 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002151 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002152 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002153 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002154 }
2155
Alexander Duyck08c88332011-06-11 01:45:03 +00002156 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002157 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002158 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002159 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002160 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002161 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002162 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002163 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002164 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002165 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002166 return 0;
2167 }
2168
2169 return work_done;
2170}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002171
2172/**
2173 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2174 * @napi: napi struct with our devices info in it
2175 * @budget: amount of work driver is allowed to do this pass, in packets
2176 *
2177 * This function is optimized for cleaning one queue only on a single
2178 * q_vector!!!
2179 **/
2180static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2181{
2182 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002183 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002184 struct ixgbe_adapter *adapter = q_vector->adapter;
2185 struct ixgbe_ring *tx_ring = NULL;
2186 int work_done = 0;
2187 long r_idx;
2188
Alexander Duyck91281fd2009-06-04 16:00:27 +00002189#ifdef CONFIG_IXGBE_DCA
2190 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002191 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002192#endif
2193
Alexander Duyck08c88332011-06-11 01:45:03 +00002194 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002195 tx_ring = adapter->tx_ring[r_idx];
2196
Alexander Duyck91281fd2009-06-04 16:00:27 +00002197 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2198 work_done = budget;
2199
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002200 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002201 if (work_done < budget) {
2202 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002203 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002204 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002205 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002206 ixgbe_irq_enable_queues(adapter,
2207 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002208 }
2209
2210 return work_done;
2211}
2212
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002213static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002214 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002215{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002216 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002217 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002218
Alexander Duyck08c88332011-06-11 01:45:03 +00002219 set_bit(r_idx, q_vector->rx.idx);
2220 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002221 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002222}
Auke Kok9a799d72007-09-15 14:07:45 -07002223
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002224static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002225 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002226{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002227 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002228 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002229
Alexander Duyck08c88332011-06-11 01:45:03 +00002230 set_bit(t_idx, q_vector->tx.idx);
2231 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002232 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002233 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002234}
Auke Kok9a799d72007-09-15 14:07:45 -07002235
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236/**
2237 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2238 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002239 *
2240 * This function maps descriptor rings to the queue-specific vectors
2241 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2242 * one vector per ring/queue, but on a constrained vector budget, we
2243 * group the rings as "efficiently" as possible. You would add new
2244 * mapping configurations in here.
2245 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002246static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002248 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002249 int v_start = 0;
2250 int rxr_idx = 0, txr_idx = 0;
2251 int rxr_remaining = adapter->num_rx_queues;
2252 int txr_remaining = adapter->num_tx_queues;
2253 int i, j;
2254 int rqpv, tqpv;
2255 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002256
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257 /* No mapping required if MSI-X is disabled. */
2258 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002259 goto out;
2260
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002261 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2262
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002263 /*
2264 * The ideal configuration...
2265 * We have enough vectors to map one per queue.
2266 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002267 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2269 map_vector_to_rxq(adapter, v_start, rxr_idx);
2270
2271 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2272 map_vector_to_txq(adapter, v_start, txr_idx);
2273
2274 goto out;
2275 }
2276
2277 /*
2278 * If we don't have enough vectors for a 1-to-1
2279 * mapping, we'll have to group them so there are
2280 * multiple queues per vector.
2281 */
2282 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002283 for (i = v_start; i < q_vectors; i++) {
2284 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 for (j = 0; j < rqpv; j++) {
2286 map_vector_to_rxq(adapter, i, rxr_idx);
2287 rxr_idx++;
2288 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002289 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002290 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291 for (j = 0; j < tqpv; j++) {
2292 map_vector_to_txq(adapter, i, txr_idx);
2293 txr_idx++;
2294 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002295 }
Auke Kok9a799d72007-09-15 14:07:45 -07002296 }
Auke Kok9a799d72007-09-15 14:07:45 -07002297out:
Auke Kok9a799d72007-09-15 14:07:45 -07002298 return err;
2299}
2300
2301/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002302 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2303 * @adapter: board private structure
2304 *
2305 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2306 * interrupts from the kernel.
2307 **/
2308static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2309{
2310 struct net_device *netdev = adapter->netdev;
2311 irqreturn_t (*handler)(int, void *);
2312 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002313 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314
2315 /* Decrement for Other and TCP Timer vectors */
2316 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2317
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002318 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002319 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002320 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002321
Alexander Duyck08c88332011-06-11 01:45:03 +00002322#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002323 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002324 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2325 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002326 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002328 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2329 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002330
Joe Perchese8e9f692010-09-07 21:34:53 +00002331 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002332 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2333 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002334 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002335 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2336 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002337 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002338 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2339 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002340 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002341 } else {
2342 /* skip this unused q_vector */
2343 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002344 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002345 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002346 handler, 0, q_vector->name,
2347 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002349 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002350 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002351 goto free_queue_irqs;
2352 }
2353 }
2354
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002355 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151b2011-05-27 05:31:32 +00002357 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002358 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002359 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002360 goto free_queue_irqs;
2361 }
2362
2363 return 0;
2364
2365free_queue_irqs:
2366 for (i = vector - 1; i >= 0; i--)
2367 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002368 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2370 pci_disable_msix(adapter->pdev);
2371 kfree(adapter->msix_entries);
2372 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002373 return err;
2374}
2375
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002376/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002377 * ixgbe_irq_enable - Enable default interrupt generation settings
2378 * @adapter: board private structure
2379 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002380static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2381 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002382{
2383 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002384
2385 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002386 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2387 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002388 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2389 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002390 switch (adapter->hw.mac.type) {
2391 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002392 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002393 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002394 mask |= IXGBE_EIMS_GPI_SDP1;
2395 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002396 if (adapter->num_vfs)
2397 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002398 break;
2399 default:
2400 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002401 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002402 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002403 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002404
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002405 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002406 if (queues)
2407 ixgbe_irq_enable_queues(adapter, ~0);
2408 if (flush)
2409 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002410
2411 if (adapter->num_vfs > 32) {
2412 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2413 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2414 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002415}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002416
2417/**
2418 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002419 * @irq: interrupt number
2420 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002421 **/
2422static irqreturn_t ixgbe_intr(int irq, void *data)
2423{
Alexander Duycka65151b2011-05-27 05:31:32 +00002424 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002425 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002426 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002427 u32 eicr;
2428
Don Skidmore54037502009-02-21 15:42:56 -08002429 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002430 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002431 * before the read of EICR.
2432 */
2433 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2434
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2436 * therefore no explict interrupt disable is necessary */
2437 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002438 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002439 /*
2440 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002441 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002442 * have disabled interrupts due to EIAM
2443 * finish the workaround of silicon errata on 82598. Unmask
2444 * the interrupt that we masked before the EICR read.
2445 */
2446 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2447 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002448 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002449 }
Auke Kok9a799d72007-09-15 14:07:45 -07002450
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002451 if (eicr & IXGBE_EICR_LSC)
2452 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002453
Alexander Duyckbd508172010-11-16 19:27:03 -08002454 switch (hw->mac.type) {
2455 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002456 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002457 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2458 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002459 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2460 adapter->interrupt_event = eicr;
2461 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2462 ixgbe_service_event_schedule(adapter);
2463 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002464 }
2465 break;
2466 default:
2467 break;
2468 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002469
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002470 ixgbe_check_fan_failure(adapter, eicr);
2471
Alexander Duyck7a921c92009-05-06 10:43:28 +00002472 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002473 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002474 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002475 }
2476
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002477 /*
2478 * re-enable link(maybe) and non-queue interrupts, no flush.
2479 * ixgbe_poll will re-enable the queue interrupts
2480 */
2481
2482 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2483 ixgbe_irq_enable(adapter, false, false);
2484
Auke Kok9a799d72007-09-15 14:07:45 -07002485 return IRQ_HANDLED;
2486}
2487
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002488static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2489{
2490 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2491
2492 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002493 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002494 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2495 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2496 q_vector->rx.count = 0;
2497 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002498 }
2499}
2500
Auke Kok9a799d72007-09-15 14:07:45 -07002501/**
2502 * ixgbe_request_irq - initialize interrupts
2503 * @adapter: board private structure
2504 *
2505 * Attempts to configure interrupts using the best available
2506 * capabilities of the hardware and kernel.
2507 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002508static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002509{
2510 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002511 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002512
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002513 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2514 err = ixgbe_request_msix_irqs(adapter);
2515 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002516 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151b2011-05-27 05:31:32 +00002517 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002518 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002519 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151b2011-05-27 05:31:32 +00002520 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002521 }
2522
Auke Kok9a799d72007-09-15 14:07:45 -07002523 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002524 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002525
Auke Kok9a799d72007-09-15 14:07:45 -07002526 return err;
2527}
2528
2529static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2530{
Auke Kok9a799d72007-09-15 14:07:45 -07002531 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002533
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002534 q_vectors = adapter->num_msix_vectors;
2535
2536 i = q_vectors - 1;
Alexander Duycka65151b2011-05-27 05:31:32 +00002537 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002538
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002539 i--;
2540 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002541 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002542 if (!adapter->q_vector[i]->rx.count &&
2543 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002544 continue;
2545
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002546 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002547 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002548 }
2549
2550 ixgbe_reset_q_vectors(adapter);
2551 } else {
Alexander Duycka65151b2011-05-27 05:31:32 +00002552 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002553 }
2554}
2555
2556/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002557 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2558 * @adapter: board private structure
2559 **/
2560static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2561{
Alexander Duyckbd508172010-11-16 19:27:03 -08002562 switch (adapter->hw.mac.type) {
2563 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002564 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002565 break;
2566 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002567 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2569 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002571 if (adapter->num_vfs > 32)
2572 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002573 break;
2574 default:
2575 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002576 }
2577 IXGBE_WRITE_FLUSH(&adapter->hw);
2578 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2579 int i;
2580 for (i = 0; i < adapter->num_msix_vectors; i++)
2581 synchronize_irq(adapter->msix_entries[i].vector);
2582 } else {
2583 synchronize_irq(adapter->pdev->irq);
2584 }
2585}
2586
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002587/**
Auke Kok9a799d72007-09-15 14:07:45 -07002588 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2589 *
2590 **/
2591static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2592{
Auke Kok9a799d72007-09-15 14:07:45 -07002593 struct ixgbe_hw *hw = &adapter->hw;
2594
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002595 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002596 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002597
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002598 ixgbe_set_ivar(adapter, 0, 0, 0);
2599 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600
2601 map_vector_to_rxq(adapter, 0, 0);
2602 map_vector_to_txq(adapter, 0, 0);
2603
Emil Tantilov396e7992010-07-01 20:05:12 +00002604 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002605}
2606
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002607/**
2608 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2609 * @adapter: board private structure
2610 * @ring: structure containing ring specific data
2611 *
2612 * Configure the Tx descriptor ring after a reset.
2613 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002614void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2615 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002616{
2617 struct ixgbe_hw *hw = &adapter->hw;
2618 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002619 int wait_loop = 10;
2620 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002621 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002622
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002623 /* disable queue to avoid issues while updating state */
2624 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2625 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2626 txdctl & ~IXGBE_TXDCTL_ENABLE);
2627 IXGBE_WRITE_FLUSH(hw);
2628
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002629 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002630 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002631 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2632 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2633 ring->count * sizeof(union ixgbe_adv_tx_desc));
2634 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2635 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002636 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002637
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002638 /* configure fetching thresholds */
2639 if (adapter->rx_itr_setting == 0) {
2640 /* cannot set wthresh when itr==0 */
2641 txdctl &= ~0x007F0000;
2642 } else {
2643 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2644 txdctl |= (8 << 16);
2645 }
2646 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2647 /* PThresh workaround for Tx hang with DFP enabled. */
2648 txdctl |= 32;
2649 }
2650
2651 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002652 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2653 adapter->atr_sample_rate) {
2654 ring->atr_sample_rate = adapter->atr_sample_rate;
2655 ring->atr_count = 0;
2656 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2657 } else {
2658 ring->atr_sample_rate = 0;
2659 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002660
John Fastabendc84d3242010-11-16 19:27:12 -08002661 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2662
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002663 /* enable queue */
2664 txdctl |= IXGBE_TXDCTL_ENABLE;
2665 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2666
2667 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2668 if (hw->mac.type == ixgbe_mac_82598EB &&
2669 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2670 return;
2671
2672 /* poll to verify queue is enabled */
2673 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002674 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002675 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2676 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2677 if (!wait_loop)
2678 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002679}
2680
Alexander Duyck120ff942010-08-19 13:34:50 +00002681static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2682{
2683 struct ixgbe_hw *hw = &adapter->hw;
2684 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002685 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002686 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002687
2688 if (hw->mac.type == ixgbe_mac_82598EB)
2689 return;
2690
2691 /* disable the arbiter while setting MTQC */
2692 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2693 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2694 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2695
2696 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002697 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002698 case (IXGBE_FLAG_SRIOV_ENABLED):
2699 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2700 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2701 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002702 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002703 if (!tcs)
2704 reg = IXGBE_MTQC_64Q_1PB;
2705 else if (tcs <= 4)
2706 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2707 else
2708 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2709
2710 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2711
2712 /* Enable Security TX Buffer IFG for multiple pb */
2713 if (tcs) {
2714 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2715 reg |= IXGBE_SECTX_DCB;
2716 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2717 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002718 break;
2719 }
2720
2721 /* re-enable the arbiter */
2722 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2723 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2724}
2725
Auke Kok9a799d72007-09-15 14:07:45 -07002726/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002727 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002728 * @adapter: board private structure
2729 *
2730 * Configure the Tx unit of the MAC after a reset.
2731 **/
2732static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2733{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002734 struct ixgbe_hw *hw = &adapter->hw;
2735 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002736 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002737
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002738 ixgbe_setup_mtqc(adapter);
2739
2740 if (hw->mac.type != ixgbe_mac_82598EB) {
2741 /* DMATXCTL.EN must be before Tx queues are enabled */
2742 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2743 dmatxctl |= IXGBE_DMATXCTL_TE;
2744 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2745 }
2746
Auke Kok9a799d72007-09-15 14:07:45 -07002747 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002748 for (i = 0; i < adapter->num_tx_queues; i++)
2749 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002750}
2751
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002752#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002753
Yi Zoua6616b42009-08-06 13:05:23 +00002754static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002755 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002756{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002757 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002758 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002759
Alexander Duyckbd508172010-11-16 19:27:03 -08002760 switch (adapter->hw.mac.type) {
2761 case ixgbe_mac_82598EB: {
2762 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2763 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002764 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002765 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002766 break;
2767 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002768 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002769 default:
2770 break;
2771 }
2772
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002773 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002774
2775 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2776 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002777 if (adapter->num_vfs)
2778 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002779
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002780 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2781 IXGBE_SRRCTL_BSIZEHDR_MASK;
2782
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002783 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002784#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2785 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2786#else
2787 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2788#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002789 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002790 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002791 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2792 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002793 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002794 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002795
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002796 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002797}
2798
Alexander Duyck05abb122010-08-19 13:35:41 +00002799static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002800{
Alexander Duyck05abb122010-08-19 13:35:41 +00002801 struct ixgbe_hw *hw = &adapter->hw;
2802 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002803 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2804 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002805 u32 mrqc = 0, reta = 0;
2806 u32 rxcsum;
2807 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002808 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002809 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2810
2811 if (tcs)
2812 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002813
Alexander Duyck05abb122010-08-19 13:35:41 +00002814 /* Fill out hash function seeds */
2815 for (i = 0; i < 10; i++)
2816 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002817
Alexander Duyck05abb122010-08-19 13:35:41 +00002818 /* Fill out redirection table */
2819 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002820 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002821 j = 0;
2822 /* reta = 4-byte sliding window of
2823 * 0x00..(indices-1)(indices-1)00..etc. */
2824 reta = (reta << 8) | (j * 0x11);
2825 if ((i & 3) == 3)
2826 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2827 }
2828
2829 /* Disable indicating checksum in descriptor, enables RSS hash */
2830 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2831 rxcsum |= IXGBE_RXCSUM_PCSD;
2832 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2833
John Fastabend8b1c0b22011-05-03 02:26:48 +00002834 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2835 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002836 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002837 } else {
2838 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2839 | IXGBE_FLAG_SRIOV_ENABLED);
2840
2841 switch (mask) {
2842 case (IXGBE_FLAG_RSS_ENABLED):
2843 if (!tcs)
2844 mrqc = IXGBE_MRQC_RSSEN;
2845 else if (tcs <= 4)
2846 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2847 else
2848 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2849 break;
2850 case (IXGBE_FLAG_SRIOV_ENABLED):
2851 mrqc = IXGBE_MRQC_VMDQEN;
2852 break;
2853 default:
2854 break;
2855 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002856 }
2857
Alexander Duyck05abb122010-08-19 13:35:41 +00002858 /* Perform hash on these packet types */
2859 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2860 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2861 | IXGBE_MRQC_RSS_FIELD_IPV6
2862 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2863
2864 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002865}
2866
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002867/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002868 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2869 * @adapter: address of board private structure
2870 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002871 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002872static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002873 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002874{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002875 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002876 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002877 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002878 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002879
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002880 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002881 return;
2882
2883 rx_buf_len = ring->rx_buf_len;
2884 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002885 rscctrl |= IXGBE_RSCCTL_RSCEN;
2886 /*
2887 * we must limit the number of descriptors so that the
2888 * total size of max desc * buf_len is not greater
2889 * than 65535
2890 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002891 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002892#if (MAX_SKB_FRAGS > 16)
2893 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2894#elif (MAX_SKB_FRAGS > 8)
2895 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2896#elif (MAX_SKB_FRAGS > 4)
2897 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2898#else
2899 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2900#endif
2901 } else {
2902 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2903 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2904 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2905 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2906 else
2907 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2908 }
Alexander Duyck73670962010-08-19 13:38:34 +00002909 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002910}
2911
Alexander Duyck9e10e042010-08-19 13:40:06 +00002912/**
2913 * ixgbe_set_uta - Set unicast filter table address
2914 * @adapter: board private structure
2915 *
2916 * The unicast table address is a register array of 32-bit registers.
2917 * The table is meant to be used in a way similar to how the MTA is used
2918 * however due to certain limitations in the hardware it is necessary to
2919 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2920 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2921 **/
2922static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2923{
2924 struct ixgbe_hw *hw = &adapter->hw;
2925 int i;
2926
2927 /* The UTA table only exists on 82599 hardware and newer */
2928 if (hw->mac.type < ixgbe_mac_82599EB)
2929 return;
2930
2931 /* we only need to do this if VMDq is enabled */
2932 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2933 return;
2934
2935 for (i = 0; i < 128; i++)
2936 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2937}
2938
2939#define IXGBE_MAX_RX_DESC_POLL 10
2940static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2941 struct ixgbe_ring *ring)
2942{
2943 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002944 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2945 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002946 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002947
2948 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2949 if (hw->mac.type == ixgbe_mac_82598EB &&
2950 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2951 return;
2952
2953 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002954 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002955 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2956 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2957
2958 if (!wait_loop) {
2959 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2960 "the polling period\n", reg_idx);
2961 }
2962}
2963
Yi Zou2d39d572011-01-06 14:29:56 +00002964void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2965 struct ixgbe_ring *ring)
2966{
2967 struct ixgbe_hw *hw = &adapter->hw;
2968 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2969 u32 rxdctl;
2970 u8 reg_idx = ring->reg_idx;
2971
2972 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2973 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2974
2975 /* write value back with RXDCTL.ENABLE bit cleared */
2976 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2977
2978 if (hw->mac.type == ixgbe_mac_82598EB &&
2979 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2980 return;
2981
2982 /* the hardware may take up to 100us to really disable the rx queue */
2983 do {
2984 udelay(10);
2985 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2986 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2987
2988 if (!wait_loop) {
2989 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2990 "the polling period\n", reg_idx);
2991 }
2992}
2993
Alexander Duyck84418e32010-08-19 13:40:54 +00002994void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2995 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002996{
2997 struct ixgbe_hw *hw = &adapter->hw;
2998 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002999 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003000 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003001
Alexander Duyck9e10e042010-08-19 13:40:06 +00003002 /* disable queue to avoid issues while updating state */
3003 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003004 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003005
Alexander Duyckacd37172010-08-19 13:36:05 +00003006 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3007 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3008 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3009 ring->count * sizeof(union ixgbe_adv_rx_desc));
3010 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3011 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003012 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003013
3014 ixgbe_configure_srrctl(adapter, ring);
3015 ixgbe_configure_rscctl(adapter, ring);
3016
Greg Rosee9f98072011-01-26 01:06:07 +00003017 /* If operating in IOV mode set RLPML for X540 */
3018 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3019 hw->mac.type == ixgbe_mac_X540) {
3020 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3021 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3022 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3023 }
3024
Alexander Duyck9e10e042010-08-19 13:40:06 +00003025 if (hw->mac.type == ixgbe_mac_82598EB) {
3026 /*
3027 * enable cache line friendly hardware writes:
3028 * PTHRESH=32 descriptors (half the internal cache),
3029 * this also removes ugly rx_no_buffer_count increment
3030 * HTHRESH=4 descriptors (to minimize latency on fetch)
3031 * WTHRESH=8 burst writeback up to two cache lines
3032 */
3033 rxdctl &= ~0x3FFFFF;
3034 rxdctl |= 0x080420;
3035 }
3036
3037 /* enable receive descriptor ring */
3038 rxdctl |= IXGBE_RXDCTL_ENABLE;
3039 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3040
3041 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003042 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003043}
3044
Alexander Duyck48654522010-08-19 13:36:27 +00003045static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3046{
3047 struct ixgbe_hw *hw = &adapter->hw;
3048 int p;
3049
3050 /* PSRTYPE must be initialized in non 82598 adapters */
3051 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003052 IXGBE_PSRTYPE_UDPHDR |
3053 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003054 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003055 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003056
3057 if (hw->mac.type == ixgbe_mac_82598EB)
3058 return;
3059
3060 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3061 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3062
3063 for (p = 0; p < adapter->num_rx_pools; p++)
3064 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3065 psrtype);
3066}
3067
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003068static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3069{
3070 struct ixgbe_hw *hw = &adapter->hw;
3071 u32 gcr_ext;
3072 u32 vt_reg_bits;
3073 u32 reg_offset, vf_shift;
3074 u32 vmdctl;
3075
3076 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3077 return;
3078
3079 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3080 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3081 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3082 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3083
3084 vf_shift = adapter->num_vfs % 32;
3085 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3086
3087 /* Enable only the PF's pool for Tx/Rx */
3088 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3089 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3090 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3091 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3092 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3093
3094 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3095 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3096
3097 /*
3098 * Set up VF register offsets for selected VT Mode,
3099 * i.e. 32 or 64 VFs for SR-IOV
3100 */
3101 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3102 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3103 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3104 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3105
3106 /* enable Tx loopback for VF/PF communication */
3107 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003108 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003109 hw->mac.ops.set_mac_anti_spoofing(hw,
3110 (adapter->antispoofing_enabled =
3111 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003112 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003113}
3114
Alexander Duyck477de6e2010-08-19 13:38:11 +00003115static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003116{
Auke Kok9a799d72007-09-15 14:07:45 -07003117 struct ixgbe_hw *hw = &adapter->hw;
3118 struct net_device *netdev = adapter->netdev;
3119 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003120 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003121 struct ixgbe_ring *rx_ring;
3122 int i;
3123 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003124
Auke Kok9a799d72007-09-15 14:07:45 -07003125 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003126 /* On by default */
3127 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3128
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003129 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003130 if (adapter->num_vfs)
3131 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3132
3133 /* Disable packet split due to 82599 erratum #45 */
3134 if (hw->mac.type == ixgbe_mac_82599EB)
3135 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003136
3137 /* Set the RX buffer length according to the mode */
3138 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003139 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003140 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003141 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003142 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003143 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003144 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003145 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3146 }
3147
3148#ifdef IXGBE_FCOE
3149 /* adjust max frame to be able to do baby jumbo for FCoE */
3150 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3151 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3152 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3153
3154#endif /* IXGBE_FCOE */
3155 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3156 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3157 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3158 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3159
3160 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003161 }
3162
Auke Kok9a799d72007-09-15 14:07:45 -07003163 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003164 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3165 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003166 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3167
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003168 /*
3169 * Setup the HW Rx Head and Tail Descriptor Pointers and
3170 * the Base and Length of the Rx Descriptor Ring
3171 */
Auke Kok9a799d72007-09-15 14:07:45 -07003172 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003173 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003174 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003175
Yi Zou6e455b892009-08-06 13:05:44 +00003176 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003177 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003178 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003179 clear_ring_ps_enabled(rx_ring);
3180
3181 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3182 set_ring_rsc_enabled(rx_ring);
3183 else
3184 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003185
Yi Zou63f39bd2009-05-17 12:34:35 +00003186#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003187 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003188 struct ixgbe_ring_feature *f;
3189 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003190 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003191 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003192 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3193 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003194 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003195 } else if (!ring_is_rsc_enabled(rx_ring) &&
3196 !ring_is_ps_enabled(rx_ring)) {
3197 rx_ring->rx_buf_len =
3198 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003199 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003200 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003201#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003202 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003203}
3204
Alexander Duyck73670962010-08-19 13:38:34 +00003205static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3206{
3207 struct ixgbe_hw *hw = &adapter->hw;
3208 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3209
3210 switch (hw->mac.type) {
3211 case ixgbe_mac_82598EB:
3212 /*
3213 * For VMDq support of different descriptor types or
3214 * buffer sizes through the use of multiple SRRCTL
3215 * registers, RDRXCTL.MVMEN must be set to 1
3216 *
3217 * also, the manual doesn't mention it clearly but DCA hints
3218 * will only use queue 0's tags unless this bit is set. Side
3219 * effects of setting this bit are only that SRRCTL must be
3220 * fully programmed [0..15]
3221 */
3222 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3223 break;
3224 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003225 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003226 /* Disable RSC for ACK packets */
3227 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3228 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3229 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3230 /* hardware requires some bits to be set by default */
3231 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3232 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3233 break;
3234 default:
3235 /* We should do nothing since we don't know this hardware */
3236 return;
3237 }
3238
3239 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3240}
3241
Alexander Duyck477de6e2010-08-19 13:38:11 +00003242/**
3243 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3244 * @adapter: board private structure
3245 *
3246 * Configure the Rx unit of the MAC after a reset.
3247 **/
3248static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3249{
3250 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003251 int i;
3252 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003253
3254 /* disable receives while setting up the descriptors */
3255 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3256 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3257
3258 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003259 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003260
Alexander Duyck9e10e042010-08-19 13:40:06 +00003261 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003262 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003263
Alexander Duyck9e10e042010-08-19 13:40:06 +00003264 ixgbe_set_uta(adapter);
3265
Alexander Duyck477de6e2010-08-19 13:38:11 +00003266 /* set_rx_buffer_len must be called before ring initialization */
3267 ixgbe_set_rx_buffer_len(adapter);
3268
3269 /*
3270 * Setup the HW Rx Head and Tail Descriptor Pointers and
3271 * the Base and Length of the Rx Descriptor Ring
3272 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003273 for (i = 0; i < adapter->num_rx_queues; i++)
3274 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003275
Alexander Duyck9e10e042010-08-19 13:40:06 +00003276 /* disable drop enable for 82598 parts */
3277 if (hw->mac.type == ixgbe_mac_82598EB)
3278 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3279
3280 /* enable all receives */
3281 rxctrl |= IXGBE_RXCTRL_RXEN;
3282 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003283}
3284
Auke Kok9a799d72007-09-15 14:07:45 -07003285static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3286{
3287 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003288 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003289 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003290
3291 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003292 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003293 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003294}
3295
3296static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3297{
3298 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003299 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003300 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003301
Auke Kok9a799d72007-09-15 14:07:45 -07003302 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003303 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003304 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003305}
3306
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003307/**
3308 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3309 * @adapter: driver data
3310 */
3311static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3312{
3313 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003314 u32 vlnctrl;
3315
3316 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3317 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3318 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3319}
3320
3321/**
3322 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3323 * @adapter: driver data
3324 */
3325static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3326{
3327 struct ixgbe_hw *hw = &adapter->hw;
3328 u32 vlnctrl;
3329
3330 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3331 vlnctrl |= IXGBE_VLNCTRL_VFE;
3332 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3333 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3334}
3335
3336/**
3337 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3338 * @adapter: driver data
3339 */
3340static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3341{
3342 struct ixgbe_hw *hw = &adapter->hw;
3343 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003344 int i, j;
3345
3346 switch (hw->mac.type) {
3347 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003348 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3349 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003350 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3351 break;
3352 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003353 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003354 for (i = 0; i < adapter->num_rx_queues; i++) {
3355 j = adapter->rx_ring[i]->reg_idx;
3356 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3357 vlnctrl &= ~IXGBE_RXDCTL_VME;
3358 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3359 }
3360 break;
3361 default:
3362 break;
3363 }
3364}
3365
3366/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003367 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003368 * @adapter: driver data
3369 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003370static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003371{
3372 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003373 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003374 int i, j;
3375
3376 switch (hw->mac.type) {
3377 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003378 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3379 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003380 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3381 break;
3382 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003383 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003384 for (i = 0; i < adapter->num_rx_queues; i++) {
3385 j = adapter->rx_ring[i]->reg_idx;
3386 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3387 vlnctrl |= IXGBE_RXDCTL_VME;
3388 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3389 }
3390 break;
3391 default:
3392 break;
3393 }
3394}
3395
Auke Kok9a799d72007-09-15 14:07:45 -07003396static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3397{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003398 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003399
Jesse Grossf62bbb52010-10-20 13:56:10 +00003400 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3401
3402 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3403 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003404}
3405
3406/**
Alexander Duyck28500622010-06-15 09:25:48 +00003407 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3408 * @netdev: network interface device structure
3409 *
3410 * Writes unicast address list to the RAR table.
3411 * Returns: -ENOMEM on failure/insufficient address space
3412 * 0 on no addresses written
3413 * X on writing X addresses to the RAR table
3414 **/
3415static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3416{
3417 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3418 struct ixgbe_hw *hw = &adapter->hw;
3419 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003420 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003421 int count = 0;
3422
3423 /* return ENOMEM indicating insufficient memory for addresses */
3424 if (netdev_uc_count(netdev) > rar_entries)
3425 return -ENOMEM;
3426
3427 if (!netdev_uc_empty(netdev) && rar_entries) {
3428 struct netdev_hw_addr *ha;
3429 /* return error if we do not support writing to RAR table */
3430 if (!hw->mac.ops.set_rar)
3431 return -ENOMEM;
3432
3433 netdev_for_each_uc_addr(ha, netdev) {
3434 if (!rar_entries)
3435 break;
3436 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3437 vfn, IXGBE_RAH_AV);
3438 count++;
3439 }
3440 }
3441 /* write the addresses in reverse order to avoid write combining */
3442 for (; rar_entries > 0 ; rar_entries--)
3443 hw->mac.ops.clear_rar(hw, rar_entries);
3444
3445 return count;
3446}
3447
3448/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003449 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003450 * @netdev: network interface device structure
3451 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003452 * The set_rx_method entry point is called whenever the unicast/multicast
3453 * address list or the network interface flags are updated. This routine is
3454 * responsible for configuring the hardware for proper unicast, multicast and
3455 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003456 **/
Greg Rose7f870472010-01-09 02:25:29 +00003457void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003458{
3459 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3460 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003461 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3462 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003463
3464 /* Check for Promiscuous and All Multicast modes */
3465
3466 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3467
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003468 /* set all bits that we expect to always be set */
3469 fctrl |= IXGBE_FCTRL_BAM;
3470 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3471 fctrl |= IXGBE_FCTRL_PMCF;
3472
Alexander Duyck28500622010-06-15 09:25:48 +00003473 /* clear the bits we are changing the status of */
3474 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3475
Auke Kok9a799d72007-09-15 14:07:45 -07003476 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003477 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003478 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003479 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003480 /* don't hardware filter vlans in promisc mode */
3481 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003482 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003483 if (netdev->flags & IFF_ALLMULTI) {
3484 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003485 vmolr |= IXGBE_VMOLR_MPE;
3486 } else {
3487 /*
3488 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003489 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003490 * that we can at least receive multicast traffic
3491 */
3492 hw->mac.ops.update_mc_addr_list(hw, netdev);
3493 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003494 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003495 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003496 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003497 /*
3498 * Write addresses to available RAR registers, if there is not
3499 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003500 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003501 */
3502 count = ixgbe_write_uc_addr_list(netdev);
3503 if (count < 0) {
3504 fctrl |= IXGBE_FCTRL_UPE;
3505 vmolr |= IXGBE_VMOLR_ROPE;
3506 }
3507 }
3508
3509 if (adapter->num_vfs) {
3510 ixgbe_restore_vf_multicasts(adapter);
3511 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3512 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3513 IXGBE_VMOLR_ROPE);
3514 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003515 }
3516
3517 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003518
3519 if (netdev->features & NETIF_F_HW_VLAN_RX)
3520 ixgbe_vlan_strip_enable(adapter);
3521 else
3522 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003523}
3524
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003525static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3526{
3527 int q_idx;
3528 struct ixgbe_q_vector *q_vector;
3529 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3530
3531 /* legacy and MSI only use one vector */
3532 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3533 q_vectors = 1;
3534
3535 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003536 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003537 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003538 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003539 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003540 if (!q_vector->rx.count || !q_vector->tx.count) {
3541 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003542 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003543 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003544 napi->poll = &ixgbe_clean_rxonly;
3545 }
3546 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003547
3548 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003549 }
3550}
3551
3552static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3553{
3554 int q_idx;
3555 struct ixgbe_q_vector *q_vector;
3556 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3557
3558 /* legacy and MSI only use one vector */
3559 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3560 q_vectors = 1;
3561
3562 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003563 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003564 napi_disable(&q_vector->napi);
3565 }
3566}
3567
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003568#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003569/*
3570 * ixgbe_configure_dcb - Configure DCB hardware
3571 * @adapter: ixgbe adapter struct
3572 *
3573 * This is called by the driver on open to configure the DCB hardware.
3574 * This is also called by the gennetlink interface when reconfiguring
3575 * the DCB state.
3576 */
3577static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3578{
3579 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003580 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003581
Alexander Duyck67ebd792010-08-19 13:34:04 +00003582 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3583 if (hw->mac.type == ixgbe_mac_82598EB)
3584 netif_set_gso_max_size(adapter->netdev, 65536);
3585 return;
3586 }
3587
3588 if (hw->mac.type == ixgbe_mac_82598EB)
3589 netif_set_gso_max_size(adapter->netdev, 32768);
3590
Alexander Duyck2f90b862008-11-20 20:52:10 -08003591
Alexander Duyck2f90b862008-11-20 20:52:10 -08003592 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003593 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003594
Alexander Duyck2f90b862008-11-20 20:52:10 -08003595 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003596
3597 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003598 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003599#ifdef CONFIG_FCOE
3600 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3601 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3602#endif
3603 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3604 DCB_TX_CONFIG);
3605 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3606 DCB_RX_CONFIG);
3607 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3608 } else {
3609 struct net_device *dev = adapter->netdev;
3610
3611 if (adapter->ixgbe_ieee_ets)
3612 dev->dcbnl_ops->ieee_setets(dev,
3613 adapter->ixgbe_ieee_ets);
3614 if (adapter->ixgbe_ieee_pfc)
3615 dev->dcbnl_ops->ieee_setpfc(dev,
3616 adapter->ixgbe_ieee_pfc);
3617 }
John Fastabend8187cd42011-02-23 05:58:08 +00003618
3619 /* Enable RSS Hash per TC */
3620 if (hw->mac.type != ixgbe_mac_82598EB) {
3621 int i;
3622 u32 reg = 0;
3623
3624 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3625 u8 msb = 0;
3626 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3627
3628 while (cnt >>= 1)
3629 msb++;
3630
3631 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3632 }
3633 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3634 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003635}
3636
3637#endif
John Fastabend80605c652011-05-02 12:34:10 +00003638
3639static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3640{
3641 int hdrm = 0;
3642 int num_tc = netdev_get_num_tc(adapter->netdev);
3643 struct ixgbe_hw *hw = &adapter->hw;
3644
3645 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3646 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3647 hdrm = 64 << adapter->fdir_pballoc;
3648
3649 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3650}
3651
Alexander Duycke4911d52011-05-11 07:18:52 +00003652static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3653{
3654 struct ixgbe_hw *hw = &adapter->hw;
3655 struct hlist_node *node, *node2;
3656 struct ixgbe_fdir_filter *filter;
3657
3658 spin_lock(&adapter->fdir_perfect_lock);
3659
3660 if (!hlist_empty(&adapter->fdir_filter_list))
3661 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3662
3663 hlist_for_each_entry_safe(filter, node, node2,
3664 &adapter->fdir_filter_list, fdir_node) {
3665 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003666 &filter->filter,
3667 filter->sw_idx,
3668 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3669 IXGBE_FDIR_DROP_QUEUE :
3670 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003671 }
3672
3673 spin_unlock(&adapter->fdir_perfect_lock);
3674}
3675
Auke Kok9a799d72007-09-15 14:07:45 -07003676static void ixgbe_configure(struct ixgbe_adapter *adapter)
3677{
3678 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003679 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003680 int i;
3681
John Fastabend80605c652011-05-02 12:34:10 +00003682 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003683#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003684 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003685#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003686
Jesse Grossf62bbb52010-10-20 13:56:10 +00003687 ixgbe_set_rx_mode(netdev);
3688 ixgbe_restore_vlan(adapter);
3689
Yi Zoueacd73f2009-05-13 13:11:06 +00003690#ifdef IXGBE_FCOE
3691 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3692 ixgbe_configure_fcoe(adapter);
3693
3694#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003695 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3696 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003697 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003698 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003699 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003700 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3701 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3702 adapter->fdir_pballoc);
3703 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003704 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003705 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003706
Auke Kok9a799d72007-09-15 14:07:45 -07003707 ixgbe_configure_tx(adapter);
3708 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003709}
3710
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003711static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3712{
3713 switch (hw->phy.type) {
3714 case ixgbe_phy_sfp_avago:
3715 case ixgbe_phy_sfp_ftl:
3716 case ixgbe_phy_sfp_intel:
3717 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003718 case ixgbe_phy_sfp_passive_tyco:
3719 case ixgbe_phy_sfp_passive_unknown:
3720 case ixgbe_phy_sfp_active_unknown:
3721 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003722 return true;
3723 default:
3724 return false;
3725 }
3726}
3727
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003728/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003729 * ixgbe_sfp_link_config - set up SFP+ link
3730 * @adapter: pointer to private adapter struct
3731 **/
3732static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3733{
Alexander Duyck70864002011-04-27 09:13:56 +00003734 /*
3735 * We are assuming the worst case scenerio here, and that
3736 * is that an SFP was inserted/removed after the reset
3737 * but before SFP detection was enabled. As such the best
3738 * solution is to just start searching as soon as we start
3739 */
3740 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3741 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003742
Alexander Duyck70864002011-04-27 09:13:56 +00003743 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003744}
3745
3746/**
3747 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003748 * @hw: pointer to private hardware struct
3749 *
3750 * Returns 0 on success, negative on failure
3751 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003752static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003753{
3754 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003755 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003756 u32 ret = IXGBE_ERR_LINK_SETUP;
3757
3758 if (hw->mac.ops.check_link)
3759 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3760
3761 if (ret)
3762 goto link_cfg_out;
3763
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003764 autoneg = hw->phy.autoneg_advertised;
3765 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003766 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3767 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003768 if (ret)
3769 goto link_cfg_out;
3770
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003771 if (hw->mac.ops.setup_link)
3772 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003773link_cfg_out:
3774 return ret;
3775}
3776
Alexander Duycka34bcff2010-08-19 13:39:20 +00003777static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003778{
Auke Kok9a799d72007-09-15 14:07:45 -07003779 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003780 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003781
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003782 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003783 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3784 IXGBE_GPIE_OCD;
3785 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003786 /*
3787 * use EIAM to auto-mask when MSI-X interrupt is asserted
3788 * this saves a register write for every interrupt
3789 */
3790 switch (hw->mac.type) {
3791 case ixgbe_mac_82598EB:
3792 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3793 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003794 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003795 case ixgbe_mac_X540:
3796 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003797 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3798 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3799 break;
3800 }
3801 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003802 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3803 * specifically only auto mask tx and rx interrupts */
3804 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003805 }
3806
Alexander Duycka34bcff2010-08-19 13:39:20 +00003807 /* XXX: to interrupt immediately for EICS writes, enable this */
3808 /* gpie |= IXGBE_GPIE_EIMEN; */
3809
3810 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3811 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3812 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003813 }
3814
Alexander Duycka34bcff2010-08-19 13:39:20 +00003815 /* Enable fan failure interrupt */
3816 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003817 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003818
Don Skidmore2698b202011-04-13 07:01:52 +00003819 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003820 gpie |= IXGBE_SDP1_GPIEN;
3821 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003822 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003823
3824 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3825}
3826
3827static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3828{
3829 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003830 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003831 u32 ctrl_ext;
3832
3833 ixgbe_get_hw_control(adapter);
3834 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003835
Auke Kok9a799d72007-09-15 14:07:45 -07003836 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3837 ixgbe_configure_msix(adapter);
3838 else
3839 ixgbe_configure_msi_and_legacy(adapter);
3840
Don Skidmorec6ecf392010-12-03 03:31:51 +00003841 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3842 if (hw->mac.ops.enable_tx_laser &&
3843 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003844 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003845 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003846 hw->mac.ops.enable_tx_laser(hw);
3847
Auke Kok9a799d72007-09-15 14:07:45 -07003848 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003849 ixgbe_napi_enable_all(adapter);
3850
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003851 if (ixgbe_is_sfp(hw)) {
3852 ixgbe_sfp_link_config(adapter);
3853 } else {
3854 err = ixgbe_non_sfp_link_config(hw);
3855 if (err)
3856 e_err(probe, "link_config FAILED %d\n", err);
3857 }
3858
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003859 /* clear any pending interrupts, may auto mask */
3860 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003861 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003862
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003863 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003864 * If this adapter has a fan, check to see if we had a failure
3865 * before we enabled the interrupt.
3866 */
3867 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3868 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3869 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003870 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003871 }
3872
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003873 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003874 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003875
Auke Kok9a799d72007-09-15 14:07:45 -07003876 /* bring the link up in the watchdog, this could race with our first
3877 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003878 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3879 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003880 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003881
3882 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3883 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3884 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3885 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3886
Auke Kok9a799d72007-09-15 14:07:45 -07003887 return 0;
3888}
3889
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003890void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3891{
3892 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003893 /* put off any impending NetWatchDogTimeout */
3894 adapter->netdev->trans_start = jiffies;
3895
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003896 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003897 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003898 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003899 /*
3900 * If SR-IOV enabled then wait a bit before bringing the adapter
3901 * back up to give the VFs time to respond to the reset. The
3902 * two second wait is based upon the watchdog timer cycle in
3903 * the VF driver.
3904 */
3905 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3906 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003907 ixgbe_up(adapter);
3908 clear_bit(__IXGBE_RESETTING, &adapter->state);
3909}
3910
Auke Kok9a799d72007-09-15 14:07:45 -07003911int ixgbe_up(struct ixgbe_adapter *adapter)
3912{
3913 /* hardware has been reset, we need to reload some things */
3914 ixgbe_configure(adapter);
3915
3916 return ixgbe_up_complete(adapter);
3917}
3918
3919void ixgbe_reset(struct ixgbe_adapter *adapter)
3920{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003921 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003922 int err;
3923
Alexander Duyck70864002011-04-27 09:13:56 +00003924 /* lock SFP init bit to prevent race conditions with the watchdog */
3925 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3926 usleep_range(1000, 2000);
3927
3928 /* clear all SFP and link config related flags while holding SFP_INIT */
3929 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3930 IXGBE_FLAG2_SFP_NEEDS_RESET);
3931 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3932
Don Skidmore8ca783a2009-05-26 20:40:47 -07003933 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003934 switch (err) {
3935 case 0:
3936 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003937 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003938 break;
3939 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003940 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003941 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003942 case IXGBE_ERR_EEPROM_VERSION:
3943 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003944 e_dev_warn("This device is a pre-production adapter/LOM. "
3945 "Please be aware there may be issuesassociated with "
3946 "your hardware. If you are experiencing problems "
3947 "please contact your Intel or hardware "
3948 "representative who provided you with this "
3949 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003950 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003951 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003952 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003953 }
Auke Kok9a799d72007-09-15 14:07:45 -07003954
Alexander Duyck70864002011-04-27 09:13:56 +00003955 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3956
Auke Kok9a799d72007-09-15 14:07:45 -07003957 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003958 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3959 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003960}
3961
Auke Kok9a799d72007-09-15 14:07:45 -07003962/**
3963 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003964 * @rx_ring: ring to free buffers from
3965 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003966static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003967{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003968 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003969 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003970 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003971
Alexander Duyck84418e32010-08-19 13:40:54 +00003972 /* ring already cleared, nothing to do */
3973 if (!rx_ring->rx_buffer_info)
3974 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003975
Alexander Duyck84418e32010-08-19 13:40:54 +00003976 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003977 for (i = 0; i < rx_ring->count; i++) {
3978 struct ixgbe_rx_buffer *rx_buffer_info;
3979
3980 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3981 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003982 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003983 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003984 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003985 rx_buffer_info->dma = 0;
3986 }
3987 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00003988 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07003989 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003990 do {
3991 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003992 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003993 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00003994 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003995 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003996 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003997 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003998 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003999 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004000 skb = skb->prev;
4001 dev_kfree_skb(this);
4002 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004003 }
4004 if (!rx_buffer_info->page)
4005 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004006 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004007 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004008 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004009 rx_buffer_info->page_dma = 0;
4010 }
Auke Kok9a799d72007-09-15 14:07:45 -07004011 put_page(rx_buffer_info->page);
4012 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004013 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004014 }
4015
4016 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4017 memset(rx_ring->rx_buffer_info, 0, size);
4018
4019 /* Zero out the descriptor ring */
4020 memset(rx_ring->desc, 0, rx_ring->size);
4021
4022 rx_ring->next_to_clean = 0;
4023 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004024}
4025
4026/**
4027 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004028 * @tx_ring: ring to be cleaned
4029 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004030static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004031{
4032 struct ixgbe_tx_buffer *tx_buffer_info;
4033 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004034 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004035
Alexander Duyck84418e32010-08-19 13:40:54 +00004036 /* ring already cleared, nothing to do */
4037 if (!tx_ring->tx_buffer_info)
4038 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004039
Alexander Duyck84418e32010-08-19 13:40:54 +00004040 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004041 for (i = 0; i < tx_ring->count; i++) {
4042 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004043 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004044 }
4045
4046 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4047 memset(tx_ring->tx_buffer_info, 0, size);
4048
4049 /* Zero out the descriptor ring */
4050 memset(tx_ring->desc, 0, tx_ring->size);
4051
4052 tx_ring->next_to_use = 0;
4053 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004054}
4055
4056/**
Auke Kok9a799d72007-09-15 14:07:45 -07004057 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4058 * @adapter: board private structure
4059 **/
4060static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4061{
4062 int i;
4063
4064 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004065 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004066}
4067
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004068/**
4069 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4070 * @adapter: board private structure
4071 **/
4072static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4073{
4074 int i;
4075
4076 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004077 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004078}
4079
Alexander Duycke4911d52011-05-11 07:18:52 +00004080static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4081{
4082 struct hlist_node *node, *node2;
4083 struct ixgbe_fdir_filter *filter;
4084
4085 spin_lock(&adapter->fdir_perfect_lock);
4086
4087 hlist_for_each_entry_safe(filter, node, node2,
4088 &adapter->fdir_filter_list, fdir_node) {
4089 hlist_del(&filter->fdir_node);
4090 kfree(filter);
4091 }
4092 adapter->fdir_filter_count = 0;
4093
4094 spin_unlock(&adapter->fdir_perfect_lock);
4095}
4096
Auke Kok9a799d72007-09-15 14:07:45 -07004097void ixgbe_down(struct ixgbe_adapter *adapter)
4098{
4099 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004100 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004101 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004102 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004103 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004104
4105 /* signal that we are down to the interrupt handler */
4106 set_bit(__IXGBE_DOWN, &adapter->state);
4107
4108 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004109 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4110 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004111
Yi Zou2d39d572011-01-06 14:29:56 +00004112 /* disable all enabled rx queues */
4113 for (i = 0; i < adapter->num_rx_queues; i++)
4114 /* this call also flushes the previous write */
4115 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4116
Don Skidmore032b4322011-03-18 09:32:53 +00004117 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004118
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004119 netif_tx_stop_all_queues(netdev);
4120
Alexander Duyck70864002011-04-27 09:13:56 +00004121 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004122 netif_carrier_off(netdev);
4123 netif_tx_disable(netdev);
4124
4125 ixgbe_irq_disable(adapter);
4126
4127 ixgbe_napi_disable_all(adapter);
4128
Alexander Duyckd034acf2011-04-27 09:25:34 +00004129 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4130 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004131 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4132
4133 del_timer_sync(&adapter->service_timer);
4134
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004135 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004136 if (adapter->num_vfs) {
4137 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004138 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004139
Auke Kok9a799d72007-09-15 14:07:45 -07004140 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004141 ixgbe_disable_tx_rx(adapter);
4142
4143 /* Mark all the VFs as inactive */
4144 for (i = 0 ; i < adapter->num_vfs; i++)
4145 adapter->vfinfo[i].clear_to_send = 0;
4146 }
4147
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004148 /* Cleanup the affinity_hint CPU mask memory and callback */
4149 for (i = 0; i < num_q_vectors; i++) {
4150 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4151 /* clear the affinity_mask in the IRQ descriptor */
4152 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4153 /* release the CPU mask memory */
4154 free_cpumask_var(q_vector->affinity_mask);
4155 }
4156
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004157 /* disable transmits in the hardware now that interrupts are off */
4158 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004159 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004160 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004161 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004162
4163 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004164 switch (hw->mac.type) {
4165 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004166 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004167 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004168 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4169 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004170 break;
4171 default:
4172 break;
4173 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004174
Paul Larson6f4a0e42008-06-24 17:00:56 -07004175 if (!pci_channel_offline(adapter->pdev))
4176 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004177
4178 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4179 if (hw->mac.ops.disable_tx_laser &&
4180 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004181 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004182 (hw->mac.type == ixgbe_mac_82599EB))))
4183 hw->mac.ops.disable_tx_laser(hw);
4184
Auke Kok9a799d72007-09-15 14:07:45 -07004185 ixgbe_clean_all_tx_rings(adapter);
4186 ixgbe_clean_all_rx_rings(adapter);
4187
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004188#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004189 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004190 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004191#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004192}
4193
Auke Kok9a799d72007-09-15 14:07:45 -07004194/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004195 * ixgbe_poll - NAPI Rx polling callback
4196 * @napi: structure for representing this polling device
4197 * @budget: how many packets driver is allowed to clean
4198 *
4199 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004200 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004201static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004202{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004203 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004204 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004205 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004206 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004207
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004208#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004209 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4210 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004211#endif
4212
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004213 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4214 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004215
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004216 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004217 work_done = budget;
4218
David S. Miller53e52c72008-01-07 21:06:12 -08004219 /* If budget not fully consumed, exit the polling mode */
4220 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004221 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004222 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004223 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004224 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004225 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004226 }
Auke Kok9a799d72007-09-15 14:07:45 -07004227 return work_done;
4228}
4229
4230/**
4231 * ixgbe_tx_timeout - Respond to a Tx Hang
4232 * @netdev: network interface device structure
4233 **/
4234static void ixgbe_tx_timeout(struct net_device *netdev)
4235{
4236 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4237
4238 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004239 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004240}
4241
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004242/**
4243 * ixgbe_set_rss_queues: Allocate queues for RSS
4244 * @adapter: board private structure to initialize
4245 *
4246 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4247 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4248 *
4249 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004250static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4251{
4252 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004253 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004254
4255 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004256 f->mask = 0xF;
4257 adapter->num_rx_queues = f->indices;
4258 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004259 ret = true;
4260 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004261 ret = false;
4262 }
4263
4264 return ret;
4265}
4266
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004267/**
4268 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4269 * @adapter: board private structure to initialize
4270 *
4271 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4272 * to the original CPU that initiated the Tx session. This runs in addition
4273 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4274 * Rx load across CPUs using RSS.
4275 *
4276 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004277static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004278{
4279 bool ret = false;
4280 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4281
4282 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4283 f_fdir->mask = 0;
4284
4285 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004286 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4287 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004288 adapter->num_tx_queues = f_fdir->indices;
4289 adapter->num_rx_queues = f_fdir->indices;
4290 ret = true;
4291 } else {
4292 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004293 }
4294 return ret;
4295}
4296
Yi Zou0331a832009-05-17 12:33:52 +00004297#ifdef IXGBE_FCOE
4298/**
4299 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4300 * @adapter: board private structure to initialize
4301 *
4302 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4303 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4304 * rx queues out of the max number of rx queues, instead, it is used as the
4305 * index of the first rx queue used by FCoE.
4306 *
4307 **/
4308static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4309{
Yi Zou0331a832009-05-17 12:33:52 +00004310 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4311
John Fastabende5b64632011-03-08 03:44:52 +00004312 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4313 return false;
4314
John Fastabende901acd2011-04-26 07:26:08 +00004315 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004316
John Fastabende901acd2011-04-26 07:26:08 +00004317 adapter->num_rx_queues = 1;
4318 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004319
John Fastabende901acd2011-04-26 07:26:08 +00004320 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4321 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004322 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004323 ixgbe_set_fdir_queues(adapter);
4324 else
4325 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004326 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004327
John Fastabende901acd2011-04-26 07:26:08 +00004328 /* adding FCoE rx rings to the end */
4329 f->mask = adapter->num_rx_queues;
4330 adapter->num_rx_queues += f->indices;
4331 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004332
John Fastabende5b64632011-03-08 03:44:52 +00004333 return true;
4334}
4335#endif /* IXGBE_FCOE */
4336
John Fastabende901acd2011-04-26 07:26:08 +00004337/* Artificial max queue cap per traffic class in DCB mode */
4338#define DCB_QUEUE_CAP 8
4339
John Fastabende5b64632011-03-08 03:44:52 +00004340#ifdef CONFIG_IXGBE_DCB
4341static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4342{
John Fastabende901acd2011-04-26 07:26:08 +00004343 int per_tc_q, q, i, offset = 0;
4344 struct net_device *dev = adapter->netdev;
4345 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004346
John Fastabende901acd2011-04-26 07:26:08 +00004347 if (!tcs)
4348 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004349
John Fastabende901acd2011-04-26 07:26:08 +00004350 /* Map queue offset and counts onto allocated tx queues */
4351 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4352 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004353
John Fastabend8b1c0b22011-05-03 02:26:48 +00004354 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004355 netdev_set_prio_tc_map(dev, i, i);
4356 netdev_set_tc_queue(dev, i, q, offset);
4357 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004358 }
4359
John Fastabende901acd2011-04-26 07:26:08 +00004360 adapter->num_tx_queues = q * tcs;
4361 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004362
4363#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004364 /* FCoE enabled queues require special configuration indexed
4365 * by feature specific indices and mask. Here we map FCoE
4366 * indices onto the DCB queue pairs allowing FCoE to own
4367 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004368 */
John Fastabende901acd2011-04-26 07:26:08 +00004369 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4370 int tc;
4371 struct ixgbe_ring_feature *f =
4372 &adapter->ring_feature[RING_F_FCOE];
4373
4374 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4375 f->indices = dev->tc_to_txq[tc].count;
4376 f->mask = dev->tc_to_txq[tc].offset;
4377 }
John Fastabende5b64632011-03-08 03:44:52 +00004378#endif
4379
John Fastabende901acd2011-04-26 07:26:08 +00004380 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004381}
John Fastabende5b64632011-03-08 03:44:52 +00004382#endif
Yi Zou0331a832009-05-17 12:33:52 +00004383
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004384/**
4385 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4386 * @adapter: board private structure to initialize
4387 *
4388 * IOV doesn't actually use anything, so just NAK the
4389 * request for now and let the other queue routines
4390 * figure out what to do.
4391 */
4392static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4393{
4394 return false;
4395}
4396
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004397/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004398 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004399 * @adapter: board private structure to initialize
4400 *
4401 * This is the top level queue allocation routine. The order here is very
4402 * important, starting with the "most" number of features turned on at once,
4403 * and ending with the smallest set of features. This way large combinations
4404 * can be allocated if they're turned on, and smaller combinations are the
4405 * fallthrough conditions.
4406 *
4407 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004408static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004409{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004410 /* Start with base case */
4411 adapter->num_rx_queues = 1;
4412 adapter->num_tx_queues = 1;
4413 adapter->num_rx_pools = adapter->num_rx_queues;
4414 adapter->num_rx_queues_per_pool = 1;
4415
4416 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004417 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004418
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004419#ifdef CONFIG_IXGBE_DCB
4420 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004421 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004422
4423#endif
John Fastabende5b64632011-03-08 03:44:52 +00004424#ifdef IXGBE_FCOE
4425 if (ixgbe_set_fcoe_queues(adapter))
4426 goto done;
4427
4428#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004429 if (ixgbe_set_fdir_queues(adapter))
4430 goto done;
4431
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004432 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004433 goto done;
4434
4435 /* fallback to base case */
4436 adapter->num_rx_queues = 1;
4437 adapter->num_tx_queues = 1;
4438
4439done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004440 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004441 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004442 return netif_set_real_num_rx_queues(adapter->netdev,
4443 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004444}
4445
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004446static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004447 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004448{
4449 int err, vector_threshold;
4450
4451 /* We'll want at least 3 (vector_threshold):
4452 * 1) TxQ[0] Cleanup
4453 * 2) RxQ[0] Cleanup
4454 * 3) Other (Link Status Change, etc.)
4455 * 4) TCP Timer (optional)
4456 */
4457 vector_threshold = MIN_MSIX_COUNT;
4458
4459 /* The more we get, the more we will assign to Tx/Rx Cleanup
4460 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4461 * Right now, we simply care about how many we'll get; we'll
4462 * set them up later while requesting irq's.
4463 */
4464 while (vectors >= vector_threshold) {
4465 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004466 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004467 if (!err) /* Success in acquiring all requested vectors. */
4468 break;
4469 else if (err < 0)
4470 vectors = 0; /* Nasty failure, quit now */
4471 else /* err == number of vectors we should try again with */
4472 vectors = err;
4473 }
4474
4475 if (vectors < vector_threshold) {
4476 /* Can't allocate enough MSI-X interrupts? Oh well.
4477 * This just means we'll go with either a single MSI
4478 * vector or fall back to legacy interrupts.
4479 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004480 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4481 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004482 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4483 kfree(adapter->msix_entries);
4484 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004485 } else {
4486 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004487 /*
4488 * Adjust for only the vectors we'll use, which is minimum
4489 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4490 * vectors we were allocated.
4491 */
4492 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004493 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004494 }
4495}
4496
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004497/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004498 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004499 * @adapter: board private structure to initialize
4500 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004501 * Cache the descriptor ring offsets for RSS to the assigned rings.
4502 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004503 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004504static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004505{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004506 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004507
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004508 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4509 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004510
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004511 for (i = 0; i < adapter->num_rx_queues; i++)
4512 adapter->rx_ring[i]->reg_idx = i;
4513 for (i = 0; i < adapter->num_tx_queues; i++)
4514 adapter->tx_ring[i]->reg_idx = i;
4515
4516 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004517}
4518
4519#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004520
4521/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004522static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4523 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004524{
4525 struct net_device *dev = adapter->netdev;
4526 struct ixgbe_hw *hw = &adapter->hw;
4527 u8 num_tcs = netdev_get_num_tc(dev);
4528
4529 *tx = 0;
4530 *rx = 0;
4531
4532 switch (hw->mac.type) {
4533 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004534 *tx = tc << 2;
4535 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004536 break;
4537 case ixgbe_mac_82599EB:
4538 case ixgbe_mac_X540:
4539 if (num_tcs == 8) {
4540 if (tc < 3) {
4541 *tx = tc << 5;
4542 *rx = tc << 4;
4543 } else if (tc < 5) {
4544 *tx = ((tc + 2) << 4);
4545 *rx = tc << 4;
4546 } else if (tc < num_tcs) {
4547 *tx = ((tc + 8) << 3);
4548 *rx = tc << 4;
4549 }
4550 } else if (num_tcs == 4) {
4551 *rx = tc << 5;
4552 switch (tc) {
4553 case 0:
4554 *tx = 0;
4555 break;
4556 case 1:
4557 *tx = 64;
4558 break;
4559 case 2:
4560 *tx = 96;
4561 break;
4562 case 3:
4563 *tx = 112;
4564 break;
4565 default:
4566 break;
4567 }
4568 }
4569 break;
4570 default:
4571 break;
4572 }
4573}
4574
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004575/**
4576 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4577 * @adapter: board private structure to initialize
4578 *
4579 * Cache the descriptor ring offsets for DCB to the assigned rings.
4580 *
4581 **/
4582static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4583{
John Fastabende5b64632011-03-08 03:44:52 +00004584 struct net_device *dev = adapter->netdev;
4585 int i, j, k;
4586 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004587
John Fastabend8b1c0b22011-05-03 02:26:48 +00004588 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004589 return false;
4590
John Fastabende5b64632011-03-08 03:44:52 +00004591 for (i = 0, k = 0; i < num_tcs; i++) {
4592 unsigned int tx_s, rx_s;
4593 u16 count = dev->tc_to_txq[i].count;
4594
4595 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4596 for (j = 0; j < count; j++, k++) {
4597 adapter->tx_ring[k]->reg_idx = tx_s + j;
4598 adapter->rx_ring[k]->reg_idx = rx_s + j;
4599 adapter->tx_ring[k]->dcb_tc = i;
4600 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004601 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004602 }
John Fastabende5b64632011-03-08 03:44:52 +00004603
4604 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004605}
4606#endif
4607
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004608/**
4609 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4610 * @adapter: board private structure to initialize
4611 *
4612 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4613 *
4614 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004615static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004616{
4617 int i;
4618 bool ret = false;
4619
Alexander Duyck03ecf912011-05-20 07:36:17 +00004620 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4621 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004622 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004623 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004624 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004625 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004626 ret = true;
4627 }
4628
4629 return ret;
4630}
4631
Yi Zou0331a832009-05-17 12:33:52 +00004632#ifdef IXGBE_FCOE
4633/**
4634 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4635 * @adapter: board private structure to initialize
4636 *
4637 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4638 *
4639 */
4640static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4641{
Yi Zou0331a832009-05-17 12:33:52 +00004642 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004643 int i;
4644 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004645
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004646 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4647 return false;
4648
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004649 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004650 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004651 ixgbe_cache_ring_fdir(adapter);
4652 else
4653 ixgbe_cache_ring_rss(adapter);
4654
4655 fcoe_rx_i = f->mask;
4656 fcoe_tx_i = f->mask;
4657 }
4658 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4659 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4660 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4661 }
4662 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004663}
4664
4665#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004666/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004667 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4668 * @adapter: board private structure to initialize
4669 *
4670 * SR-IOV doesn't use any descriptor rings but changes the default if
4671 * no other mapping is used.
4672 *
4673 */
4674static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4675{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004676 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4677 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004678 if (adapter->num_vfs)
4679 return true;
4680 else
4681 return false;
4682}
4683
4684/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004685 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4686 * @adapter: board private structure to initialize
4687 *
4688 * Once we know the feature-set enabled for the device, we'll cache
4689 * the register offset the descriptor ring is assigned to.
4690 *
4691 * Note, the order the various feature calls is important. It must start with
4692 * the "most" features enabled at the same time, then trickle down to the
4693 * least amount of features turned on at once.
4694 **/
4695static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4696{
4697 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004698 adapter->rx_ring[0]->reg_idx = 0;
4699 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004700
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004701 if (ixgbe_cache_ring_sriov(adapter))
4702 return;
4703
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004704#ifdef CONFIG_IXGBE_DCB
4705 if (ixgbe_cache_ring_dcb(adapter))
4706 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004707#endif
John Fastabende5b64632011-03-08 03:44:52 +00004708
4709#ifdef IXGBE_FCOE
4710 if (ixgbe_cache_ring_fcoe(adapter))
4711 return;
4712#endif /* IXGBE_FCOE */
4713
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004714 if (ixgbe_cache_ring_fdir(adapter))
4715 return;
4716
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004717 if (ixgbe_cache_ring_rss(adapter))
4718 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004719}
4720
Auke Kok9a799d72007-09-15 14:07:45 -07004721/**
4722 * ixgbe_alloc_queues - Allocate memory for all rings
4723 * @adapter: board private structure to initialize
4724 *
4725 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004726 * number of queues at compile-time. The polling_netdev array is
4727 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004728 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004729static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004730{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004731 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004732
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004733 if (nid < 0 || !node_online(nid))
4734 nid = first_online_node;
4735
4736 for (; tx < adapter->num_tx_queues; tx++) {
4737 struct ixgbe_ring *ring;
4738
4739 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004740 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004741 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004742 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004743 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004744 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004745 ring->queue_index = tx;
4746 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004747 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004748 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004749
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004750 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004751 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004752
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004753 for (; rx < adapter->num_rx_queues; rx++) {
4754 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004755
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004756 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004757 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004758 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004759 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004760 goto err_allocation;
4761 ring->count = adapter->rx_ring_count;
4762 ring->queue_index = rx;
4763 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004764 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004765 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004766
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004767 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004768 }
4769
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004770 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004771
4772 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004773
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004774err_allocation:
4775 while (tx)
4776 kfree(adapter->tx_ring[--tx]);
4777
4778 while (rx)
4779 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004780 return -ENOMEM;
4781}
4782
4783/**
4784 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4785 * @adapter: board private structure to initialize
4786 *
4787 * Attempt to configure the interrupts using the best available
4788 * capabilities of the hardware and the kernel.
4789 **/
Al Virofeea6a52008-11-27 15:34:07 -08004790static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004791{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004792 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004793 int err = 0;
4794 int vector, v_budget;
4795
4796 /*
4797 * It's easy to be greedy for MSI-X vectors, but it really
4798 * doesn't do us much good if we have a lot more vectors
4799 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004800 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004801 */
4802 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004803 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004804
4805 /*
4806 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004807 * hw.mac->max_msix_vectors vectors. With features
4808 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4809 * descriptor queues supported by our device. Thus, we cap it off in
4810 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004811 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004812 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004813
4814 /* A failure in MSI-X entry allocation isn't fatal, but it does
4815 * mean we disable MSI-X capabilities of the adapter. */
4816 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004817 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004818 if (adapter->msix_entries) {
4819 for (vector = 0; vector < v_budget; vector++)
4820 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004821
Alexander Duyck7a921c92009-05-06 10:43:28 +00004822 ixgbe_acquire_msix_vectors(adapter, v_budget);
4823
4824 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4825 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826 }
David S. Miller26d27842010-05-03 15:18:22 -07004827
Alexander Duyck7a921c92009-05-06 10:43:28 +00004828 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4829 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004830 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004831 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004832 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004833 "queues are disabled. Disabling Flow Director\n");
4834 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004835 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004836 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004837 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4838 ixgbe_disable_sriov(adapter);
4839
Ben Hutchings847f53f2010-09-27 08:28:56 +00004840 err = ixgbe_set_num_queues(adapter);
4841 if (err)
4842 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004843
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004844 err = pci_enable_msi(adapter->pdev);
4845 if (!err) {
4846 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4847 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004848 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4849 "Unable to allocate MSI interrupt, "
4850 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004851 /* reset err */
4852 err = 0;
4853 }
4854
4855out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004856 return err;
4857}
4858
Alexander Duyck7a921c92009-05-06 10:43:28 +00004859/**
4860 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4861 * @adapter: board private structure to initialize
4862 *
4863 * We allocate one q_vector per queue interrupt. If allocation fails we
4864 * return -ENOMEM.
4865 **/
4866static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4867{
4868 int q_idx, num_q_vectors;
4869 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004870 int (*poll)(struct napi_struct *, int);
4871
4872 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4873 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004874 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004875 } else {
4876 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004877 poll = &ixgbe_poll;
4878 }
4879
4880 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004881 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004882 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004883 if (!q_vector)
4884 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004885 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004886 if (!q_vector)
4887 goto err_out;
4888 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004889 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004890 q_vector->eitr = adapter->tx_eitr_param;
4891 else
4892 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004893 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004894 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004895 adapter->q_vector[q_idx] = q_vector;
4896 }
4897
4898 return 0;
4899
4900err_out:
4901 while (q_idx) {
4902 q_idx--;
4903 q_vector = adapter->q_vector[q_idx];
4904 netif_napi_del(&q_vector->napi);
4905 kfree(q_vector);
4906 adapter->q_vector[q_idx] = NULL;
4907 }
4908 return -ENOMEM;
4909}
4910
4911/**
4912 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4913 * @adapter: board private structure to initialize
4914 *
4915 * This function frees the memory allocated to the q_vectors. In addition if
4916 * NAPI is enabled it will delete any references to the NAPI struct prior
4917 * to freeing the q_vector.
4918 **/
4919static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4920{
4921 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004922
Alexander Duyck91281fd2009-06-04 16:00:27 +00004923 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004924 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004925 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004926 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004927
4928 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4929 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004930 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004931 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004932 kfree(q_vector);
4933 }
4934}
4935
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004936static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004937{
4938 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4939 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4940 pci_disable_msix(adapter->pdev);
4941 kfree(adapter->msix_entries);
4942 adapter->msix_entries = NULL;
4943 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4944 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4945 pci_disable_msi(adapter->pdev);
4946 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004947}
4948
4949/**
4950 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4951 * @adapter: board private structure to initialize
4952 *
4953 * We determine which interrupt scheme to use based on...
4954 * - Kernel support (MSI, MSI-X)
4955 * - which can be user-defined (via MODULE_PARAM)
4956 * - Hardware queue count (num_*_queues)
4957 * - defined by miscellaneous hardware support/features (RSS, etc.)
4958 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004959int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004960{
4961 int err;
4962
4963 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004964 err = ixgbe_set_num_queues(adapter);
4965 if (err)
4966 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004967
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004968 err = ixgbe_set_interrupt_capability(adapter);
4969 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004970 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004971 goto err_set_interrupt;
4972 }
4973
Alexander Duyck7a921c92009-05-06 10:43:28 +00004974 err = ixgbe_alloc_q_vectors(adapter);
4975 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004976 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004977 goto err_alloc_q_vectors;
4978 }
4979
4980 err = ixgbe_alloc_queues(adapter);
4981 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004982 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004983 goto err_alloc_queues;
4984 }
4985
Emil Tantilov849c4542010-06-03 16:53:41 +00004986 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00004987 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4988 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004989
4990 set_bit(__IXGBE_DOWN, &adapter->state);
4991
4992 return 0;
4993
Alexander Duyck7a921c92009-05-06 10:43:28 +00004994err_alloc_queues:
4995 ixgbe_free_q_vectors(adapter);
4996err_alloc_q_vectors:
4997 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004998err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00004999 return err;
5000}
5001
5002/**
5003 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5004 * @adapter: board private structure to clear interrupt scheme on
5005 *
5006 * We go through and clear interrupt specific resources and reset the structure
5007 * to pre-load conditions
5008 **/
5009void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5010{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005011 int i;
5012
5013 for (i = 0; i < adapter->num_tx_queues; i++) {
5014 kfree(adapter->tx_ring[i]);
5015 adapter->tx_ring[i] = NULL;
5016 }
5017 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005018 struct ixgbe_ring *ring = adapter->rx_ring[i];
5019
5020 /* ixgbe_get_stats64() might access this ring, we must wait
5021 * a grace period before freeing it.
5022 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005023 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005024 adapter->rx_ring[i] = NULL;
5025 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005026
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005027 adapter->num_tx_queues = 0;
5028 adapter->num_rx_queues = 0;
5029
Alexander Duyck7a921c92009-05-06 10:43:28 +00005030 ixgbe_free_q_vectors(adapter);
5031 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005032}
5033
5034/**
5035 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5036 * @adapter: board private structure to initialize
5037 *
5038 * ixgbe_sw_init initializes the Adapter private data structure.
5039 * Fields are initialized based on PCI device information and
5040 * OS network device settings (MTU size).
5041 **/
5042static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5043{
5044 struct ixgbe_hw *hw = &adapter->hw;
5045 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005046 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005047 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005048#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005049 int j;
5050 struct tc_configuration *tc;
5051#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005052 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005053
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005054 /* PCI config space info */
5055
5056 hw->vendor_id = pdev->vendor;
5057 hw->device_id = pdev->device;
5058 hw->revision_id = pdev->revision;
5059 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5060 hw->subsystem_device_id = pdev->subsystem_device;
5061
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005062 /* Set capability flags */
5063 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5064 adapter->ring_feature[RING_F_RSS].indices = rss;
5065 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005066 switch (hw->mac.type) {
5067 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005068 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5069 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005070 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005071 break;
5072 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005073 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005074 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005075 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5076 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005077 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5078 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005079 /* Flow Director hash filters enabled */
5080 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5081 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005082 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005083 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005084 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005085#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005086 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5087 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5088 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005089#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005090 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005091 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005092#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005093#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005094 break;
5095 default:
5096 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005097 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005098
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005099 /* n-tuple support exists, always init our spinlock */
5100 spin_lock_init(&adapter->fdir_perfect_lock);
5101
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005102#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005103 /* Configure DCB traffic classes */
5104 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5105 tc = &adapter->dcb_cfg.tc_config[j];
5106 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5107 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5108 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5109 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5110 tc->dcb_pfc = pfc_disabled;
5111 }
5112 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5113 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005114 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005115 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005116 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005117 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005118 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005119
5120#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005121
5122 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005123 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005124 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005125#ifdef CONFIG_DCB
5126 adapter->last_lfc_mode = hw->fc.current_mode;
5127#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005128 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5129 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005130 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5131 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005132 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005133
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005134 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005135 adapter->rx_itr_setting = 1;
5136 adapter->rx_eitr_param = 20000;
5137 adapter->tx_itr_setting = 1;
5138 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005139
5140 /* set defaults for eitr in MegaBytes */
5141 adapter->eitr_low = 10;
5142 adapter->eitr_high = 20;
5143
5144 /* set default ring sizes */
5145 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5146 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5147
Alexander Duyckbd198052011-06-11 01:45:08 +00005148 /* set default work limits */
5149 adapter->tx_work_limit = adapter->tx_ring_count;
5150
Auke Kok9a799d72007-09-15 14:07:45 -07005151 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005152 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005153 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005154 return -EIO;
5155 }
5156
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005157 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005158 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5159
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005160 /* get assigned NUMA node */
5161 adapter->node = dev_to_node(&pdev->dev);
5162
Auke Kok9a799d72007-09-15 14:07:45 -07005163 set_bit(__IXGBE_DOWN, &adapter->state);
5164
5165 return 0;
5166}
5167
5168/**
5169 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005170 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005171 *
5172 * Return 0 on success, negative on failure
5173 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005174int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005175{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005176 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005177 int size;
5178
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005179 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005180 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005181 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005182 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005183 if (!tx_ring->tx_buffer_info)
5184 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005185
5186 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005187 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005188 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005189
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005190 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005191 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005192 if (!tx_ring->desc)
5193 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005194
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005195 tx_ring->next_to_use = 0;
5196 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005197 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005198
5199err:
5200 vfree(tx_ring->tx_buffer_info);
5201 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005202 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005203 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005204}
5205
5206/**
Alexander Duyck69888672008-09-11 20:05:39 -07005207 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5208 * @adapter: board private structure
5209 *
5210 * If this function returns with an error, then it's possible one or
5211 * more of the rings is populated (while the rest are not). It is the
5212 * callers duty to clean those orphaned rings.
5213 *
5214 * Return 0 on success, negative on failure
5215 **/
5216static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5217{
5218 int i, err = 0;
5219
5220 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005221 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005222 if (!err)
5223 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005224 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005225 break;
5226 }
5227
5228 return err;
5229}
5230
5231/**
Auke Kok9a799d72007-09-15 14:07:45 -07005232 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005233 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005234 *
5235 * Returns 0 on success, negative on failure
5236 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005237int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005238{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005239 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005240 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005241
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005242 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005243 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005244 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005245 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005246 if (!rx_ring->rx_buffer_info)
5247 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005248
Auke Kok9a799d72007-09-15 14:07:45 -07005249 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005250 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5251 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005252
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005253 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005254 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005255
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005256 if (!rx_ring->desc)
5257 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005258
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005259 rx_ring->next_to_clean = 0;
5260 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005261
5262 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005263err:
5264 vfree(rx_ring->rx_buffer_info);
5265 rx_ring->rx_buffer_info = NULL;
5266 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005267 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005268}
5269
5270/**
Alexander Duyck69888672008-09-11 20:05:39 -07005271 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5272 * @adapter: board private structure
5273 *
5274 * If this function returns with an error, then it's possible one or
5275 * more of the rings is populated (while the rest are not). It is the
5276 * callers duty to clean those orphaned rings.
5277 *
5278 * Return 0 on success, negative on failure
5279 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005280static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5281{
5282 int i, err = 0;
5283
5284 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005285 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005286 if (!err)
5287 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005288 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005289 break;
5290 }
5291
5292 return err;
5293}
5294
5295/**
Auke Kok9a799d72007-09-15 14:07:45 -07005296 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005297 * @tx_ring: Tx descriptor ring for a specific queue
5298 *
5299 * Free all transmit software resources
5300 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005301void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005302{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005303 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005304
5305 vfree(tx_ring->tx_buffer_info);
5306 tx_ring->tx_buffer_info = NULL;
5307
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005308 /* if not set, then don't free */
5309 if (!tx_ring->desc)
5310 return;
5311
5312 dma_free_coherent(tx_ring->dev, tx_ring->size,
5313 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005314
5315 tx_ring->desc = NULL;
5316}
5317
5318/**
5319 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5320 * @adapter: board private structure
5321 *
5322 * Free all transmit software resources
5323 **/
5324static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5325{
5326 int i;
5327
5328 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005329 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005330 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005331}
5332
5333/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005334 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005335 * @rx_ring: ring to clean the resources from
5336 *
5337 * Free all receive software resources
5338 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005339void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005340{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005341 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005342
5343 vfree(rx_ring->rx_buffer_info);
5344 rx_ring->rx_buffer_info = NULL;
5345
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005346 /* if not set, then don't free */
5347 if (!rx_ring->desc)
5348 return;
5349
5350 dma_free_coherent(rx_ring->dev, rx_ring->size,
5351 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005352
5353 rx_ring->desc = NULL;
5354}
5355
5356/**
5357 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5358 * @adapter: board private structure
5359 *
5360 * Free all receive software resources
5361 **/
5362static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5363{
5364 int i;
5365
5366 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005367 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005368 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005369}
5370
5371/**
Auke Kok9a799d72007-09-15 14:07:45 -07005372 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5373 * @netdev: network interface device structure
5374 * @new_mtu: new value for maximum frame size
5375 *
5376 * Returns 0 on success, negative on failure
5377 **/
5378static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5379{
5380 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005381 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005382 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5383
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005384 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005385 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5386 hw->mac.type != ixgbe_mac_X540) {
5387 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5388 return -EINVAL;
5389 } else {
5390 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5391 return -EINVAL;
5392 }
Auke Kok9a799d72007-09-15 14:07:45 -07005393
Emil Tantilov396e7992010-07-01 20:05:12 +00005394 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005395 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005396 netdev->mtu = new_mtu;
5397
John Fastabend16b61be2010-11-16 19:26:44 -08005398 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5399 hw->fc.low_water = FC_LOW_WATER(max_frame);
5400
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005401 if (netif_running(netdev))
5402 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005403
5404 return 0;
5405}
5406
5407/**
5408 * ixgbe_open - Called when a network interface is made active
5409 * @netdev: network interface device structure
5410 *
5411 * Returns 0 on success, negative value on failure
5412 *
5413 * The open entry point is called when a network interface is made
5414 * active by the system (IFF_UP). At this point all resources needed
5415 * for transmit and receive operations are allocated, the interrupt
5416 * handler is registered with the OS, the watchdog timer is started,
5417 * and the stack is notified that the interface is ready.
5418 **/
5419static int ixgbe_open(struct net_device *netdev)
5420{
5421 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5422 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005423
Auke Kok4bebfaa2008-02-11 09:26:01 -08005424 /* disallow open during test */
5425 if (test_bit(__IXGBE_TESTING, &adapter->state))
5426 return -EBUSY;
5427
Jesse Brandeburg54386462009-04-17 20:44:27 +00005428 netif_carrier_off(netdev);
5429
Auke Kok9a799d72007-09-15 14:07:45 -07005430 /* allocate transmit descriptors */
5431 err = ixgbe_setup_all_tx_resources(adapter);
5432 if (err)
5433 goto err_setup_tx;
5434
Auke Kok9a799d72007-09-15 14:07:45 -07005435 /* allocate receive descriptors */
5436 err = ixgbe_setup_all_rx_resources(adapter);
5437 if (err)
5438 goto err_setup_rx;
5439
5440 ixgbe_configure(adapter);
5441
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005442 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005443 if (err)
5444 goto err_req_irq;
5445
Auke Kok9a799d72007-09-15 14:07:45 -07005446 err = ixgbe_up_complete(adapter);
5447 if (err)
5448 goto err_up;
5449
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005450 netif_tx_start_all_queues(netdev);
5451
Auke Kok9a799d72007-09-15 14:07:45 -07005452 return 0;
5453
5454err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005455 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005456 ixgbe_free_irq(adapter);
5457err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005458err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005459 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005460err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005461 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005462 ixgbe_reset(adapter);
5463
5464 return err;
5465}
5466
5467/**
5468 * ixgbe_close - Disables a network interface
5469 * @netdev: network interface device structure
5470 *
5471 * Returns 0, this is not allowed to fail
5472 *
5473 * The close entry point is called when an interface is de-activated
5474 * by the OS. The hardware is still under the drivers control, but
5475 * needs to be disabled. A global MAC reset is issued to stop the
5476 * hardware, and all transmit and receive resources are freed.
5477 **/
5478static int ixgbe_close(struct net_device *netdev)
5479{
5480 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005481
5482 ixgbe_down(adapter);
5483 ixgbe_free_irq(adapter);
5484
Alexander Duycke4911d52011-05-11 07:18:52 +00005485 ixgbe_fdir_filter_exit(adapter);
5486
Auke Kok9a799d72007-09-15 14:07:45 -07005487 ixgbe_free_all_tx_resources(adapter);
5488 ixgbe_free_all_rx_resources(adapter);
5489
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005490 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005491
5492 return 0;
5493}
5494
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005495#ifdef CONFIG_PM
5496static int ixgbe_resume(struct pci_dev *pdev)
5497{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005498 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5499 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005500 u32 err;
5501
5502 pci_set_power_state(pdev, PCI_D0);
5503 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005504 /*
5505 * pci_restore_state clears dev->state_saved so call
5506 * pci_save_state to restore it.
5507 */
5508 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005509
5510 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005511 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005512 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005513 return err;
5514 }
5515 pci_set_master(pdev);
5516
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005517 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005518
5519 err = ixgbe_init_interrupt_scheme(adapter);
5520 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005521 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005522 return err;
5523 }
5524
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005525 ixgbe_reset(adapter);
5526
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005527 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5528
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005529 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005530 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005531 if (err)
5532 return err;
5533 }
5534
5535 netif_device_attach(netdev);
5536
5537 return 0;
5538}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005539#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005540
5541static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005542{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005543 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5544 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005545 struct ixgbe_hw *hw = &adapter->hw;
5546 u32 ctrl, fctrl;
5547 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005548#ifdef CONFIG_PM
5549 int retval = 0;
5550#endif
5551
5552 netif_device_detach(netdev);
5553
5554 if (netif_running(netdev)) {
5555 ixgbe_down(adapter);
5556 ixgbe_free_irq(adapter);
5557 ixgbe_free_all_tx_resources(adapter);
5558 ixgbe_free_all_rx_resources(adapter);
5559 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005560
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005561 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005562#ifdef CONFIG_DCB
5563 kfree(adapter->ixgbe_ieee_pfc);
5564 kfree(adapter->ixgbe_ieee_ets);
5565#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005566
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005567#ifdef CONFIG_PM
5568 retval = pci_save_state(pdev);
5569 if (retval)
5570 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005571
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005572#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005573 if (wufc) {
5574 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005575
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005576 /* turn on all-multi mode if wake on multicast is enabled */
5577 if (wufc & IXGBE_WUFC_MC) {
5578 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5579 fctrl |= IXGBE_FCTRL_MPE;
5580 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5581 }
5582
5583 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5584 ctrl |= IXGBE_CTRL_GIO_DIS;
5585 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5586
5587 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5588 } else {
5589 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5590 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5591 }
5592
Alexander Duyckbd508172010-11-16 19:27:03 -08005593 switch (hw->mac.type) {
5594 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005595 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005596 break;
5597 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005598 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005599 pci_wake_from_d3(pdev, !!wufc);
5600 break;
5601 default:
5602 break;
5603 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005604
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005605 *enable_wake = !!wufc;
5606
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005607 ixgbe_release_hw_control(adapter);
5608
5609 pci_disable_device(pdev);
5610
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005611 return 0;
5612}
5613
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005614#ifdef CONFIG_PM
5615static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5616{
5617 int retval;
5618 bool wake;
5619
5620 retval = __ixgbe_shutdown(pdev, &wake);
5621 if (retval)
5622 return retval;
5623
5624 if (wake) {
5625 pci_prepare_to_sleep(pdev);
5626 } else {
5627 pci_wake_from_d3(pdev, false);
5628 pci_set_power_state(pdev, PCI_D3hot);
5629 }
5630
5631 return 0;
5632}
5633#endif /* CONFIG_PM */
5634
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005635static void ixgbe_shutdown(struct pci_dev *pdev)
5636{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005637 bool wake;
5638
5639 __ixgbe_shutdown(pdev, &wake);
5640
5641 if (system_state == SYSTEM_POWER_OFF) {
5642 pci_wake_from_d3(pdev, wake);
5643 pci_set_power_state(pdev, PCI_D3hot);
5644 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005645}
5646
5647/**
Auke Kok9a799d72007-09-15 14:07:45 -07005648 * ixgbe_update_stats - Update the board statistics counters.
5649 * @adapter: board private structure
5650 **/
5651void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5652{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005653 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005654 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005655 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005656 u64 total_mpc = 0;
5657 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005658 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5659 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5660 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005661
Don Skidmored08935c2010-06-11 13:20:29 +00005662 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5663 test_bit(__IXGBE_RESETTING, &adapter->state))
5664 return;
5665
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005666 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005667 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005668 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005669 for (i = 0; i < 16; i++)
5670 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005671 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005672 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005673 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5674 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005675 }
5676 adapter->rsc_total_count = rsc_count;
5677 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005678 }
5679
Alexander Duyck5b7da512010-11-16 19:26:50 -08005680 for (i = 0; i < adapter->num_rx_queues; i++) {
5681 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5682 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5683 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5684 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5685 bytes += rx_ring->stats.bytes;
5686 packets += rx_ring->stats.packets;
5687 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005688 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005689 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5690 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5691 netdev->stats.rx_bytes = bytes;
5692 netdev->stats.rx_packets = packets;
5693
5694 bytes = 0;
5695 packets = 0;
5696 /* gather some stats to the adapter struct that are per queue */
5697 for (i = 0; i < adapter->num_tx_queues; i++) {
5698 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5699 restart_queue += tx_ring->tx_stats.restart_queue;
5700 tx_busy += tx_ring->tx_stats.tx_busy;
5701 bytes += tx_ring->stats.bytes;
5702 packets += tx_ring->stats.packets;
5703 }
5704 adapter->restart_queue = restart_queue;
5705 adapter->tx_busy = tx_busy;
5706 netdev->stats.tx_bytes = bytes;
5707 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005708
Joe Perches7ca647b2010-09-07 21:35:40 +00005709 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005710 for (i = 0; i < 8; i++) {
5711 /* for packet buffers not used, the register should read 0 */
5712 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5713 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005714 hwstats->mpc[i] += mpc;
5715 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005716 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005717 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5718 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5719 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5720 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5721 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005722 switch (hw->mac.type) {
5723 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005724 hwstats->pxonrxc[i] +=
5725 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005726 break;
5727 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005728 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005729 hwstats->pxonrxc[i] +=
5730 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005731 break;
5732 default:
5733 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005734 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005735 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5736 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005737 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005738 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005739 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005740 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005741
John Fastabendc84d3242010-11-16 19:27:12 -08005742 ixgbe_update_xoff_received(adapter);
5743
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005744 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005745 switch (hw->mac.type) {
5746 case ixgbe_mac_82598EB:
5747 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005748 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5749 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5750 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5751 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005752 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005753 /* OS2BMC stats are X540 only*/
5754 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5755 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5756 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5757 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5758 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005759 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005760 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005761 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005762 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005763 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005764 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005765 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005766 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5767 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005768#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005769 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5770 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5771 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5772 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5773 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5774 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005775#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005776 break;
5777 default:
5778 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005779 }
Auke Kok9a799d72007-09-15 14:07:45 -07005780 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005781 hwstats->bprc += bprc;
5782 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005783 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005784 hwstats->mprc -= bprc;
5785 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5786 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5787 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5788 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5789 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5790 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5791 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5792 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005793 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005794 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005795 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005796 hwstats->lxofftxc += lxoff;
5797 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5798 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5799 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005800 /*
5801 * 82598 errata - tx of flow control packets is included in tx counters
5802 */
5803 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005804 hwstats->gptc -= xon_off_tot;
5805 hwstats->mptc -= xon_off_tot;
5806 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5807 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5808 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5809 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5810 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5811 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5812 hwstats->ptc64 -= xon_off_tot;
5813 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5814 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5815 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5816 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5817 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5818 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005819
5820 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005821 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005822
5823 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005824 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005825 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005826 netdev->stats.rx_length_errors = hwstats->rlec;
5827 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005828 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005829}
5830
5831/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005832 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5833 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005834 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005835static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005836{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005837 struct ixgbe_hw *hw = &adapter->hw;
5838 int i;
5839
Alexander Duyckd034acf2011-04-27 09:25:34 +00005840 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5841 return;
5842
5843 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5844
5845 /* if interface is down do nothing */
5846 if (test_bit(__IXGBE_DOWN, &adapter->state))
5847 return;
5848
5849 /* do nothing if we are not using signature filters */
5850 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5851 return;
5852
5853 adapter->fdir_overflow++;
5854
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005855 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5856 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005857 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005858 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005859 /* re-enable flow director interrupts */
5860 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005861 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005862 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005863 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005864 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005865}
5866
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005867/**
5868 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5869 * @adapter - pointer to the device adapter structure
5870 *
5871 * This function serves two purposes. First it strobes the interrupt lines
5872 * in order to make certain interrupts are occuring. Secondly it sets the
5873 * bits needed to check for TX hangs. As a result we should immediately
5874 * determine if a hang has occured.
5875 */
5876static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5877{
Auke Kok9a799d72007-09-15 14:07:45 -07005878 struct ixgbe_hw *hw = &adapter->hw;
5879 u64 eics = 0;
5880 int i;
5881
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005882 /* If we're down or resetting, just bail */
5883 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5884 test_bit(__IXGBE_RESETTING, &adapter->state))
5885 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005886
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005887 /* Force detection of hung controller */
5888 if (netif_carrier_ok(adapter->netdev)) {
5889 for (i = 0; i < adapter->num_tx_queues; i++)
5890 set_check_for_tx_hang(adapter->tx_ring[i]);
5891 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005892
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005893 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005894 /*
5895 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005896 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005897 * would set *both* EIMS and EICS for any bit in EIAM
5898 */
5899 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5900 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005901 } else {
5902 /* get one bit for every active tx/rx interrupt vector */
5903 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5904 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005905 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005906 eics |= ((u64)1 << i);
5907 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005908 }
5909
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005910 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005911 ixgbe_irq_rearm_queues(adapter, eics);
5912
Alexander Duyckfe49f042009-06-04 16:00:09 +00005913}
5914
5915/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005916 * ixgbe_watchdog_update_link - update the link status
5917 * @adapter - pointer to the device adapter structure
5918 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005919 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005920static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005921{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005922 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005923 u32 link_speed = adapter->link_speed;
5924 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005925 int i;
5926
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005927 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5928 return;
5929
5930 if (hw->mac.ops.check_link) {
5931 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005932 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005933 /* always assume link is up, if no check link function */
5934 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5935 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005936 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005937 if (link_up) {
5938 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5939 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5940 hw->mac.ops.fc_enable(hw, i);
5941 } else {
5942 hw->mac.ops.fc_enable(hw, 0);
5943 }
5944 }
5945
5946 if (link_up ||
5947 time_after(jiffies, (adapter->link_check_timeout +
5948 IXGBE_TRY_LINK_TIMEOUT))) {
5949 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5950 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5951 IXGBE_WRITE_FLUSH(hw);
5952 }
5953
5954 adapter->link_up = link_up;
5955 adapter->link_speed = link_speed;
5956}
5957
5958/**
5959 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5960 * print link up message
5961 * @adapter - pointer to the device adapter structure
5962 **/
5963static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5964{
5965 struct net_device *netdev = adapter->netdev;
5966 struct ixgbe_hw *hw = &adapter->hw;
5967 u32 link_speed = adapter->link_speed;
5968 bool flow_rx, flow_tx;
5969
5970 /* only continue if link was previously down */
5971 if (netif_carrier_ok(netdev))
5972 return;
5973
5974 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5975
5976 switch (hw->mac.type) {
5977 case ixgbe_mac_82598EB: {
5978 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5979 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5980 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5981 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5982 }
5983 break;
5984 case ixgbe_mac_X540:
5985 case ixgbe_mac_82599EB: {
5986 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5987 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5988 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5989 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5990 }
5991 break;
5992 default:
5993 flow_tx = false;
5994 flow_rx = false;
5995 break;
5996 }
5997 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5998 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5999 "10 Gbps" :
6000 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6001 "1 Gbps" :
6002 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6003 "100 Mbps" :
6004 "unknown speed"))),
6005 ((flow_rx && flow_tx) ? "RX/TX" :
6006 (flow_rx ? "RX" :
6007 (flow_tx ? "TX" : "None"))));
6008
6009 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006010 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006011}
6012
6013/**
6014 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6015 * print link down message
6016 * @adapter - pointer to the adapter structure
6017 **/
6018static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6019{
6020 struct net_device *netdev = adapter->netdev;
6021 struct ixgbe_hw *hw = &adapter->hw;
6022
6023 adapter->link_up = false;
6024 adapter->link_speed = 0;
6025
6026 /* only continue if link was up previously */
6027 if (!netif_carrier_ok(netdev))
6028 return;
6029
6030 /* poll for SFP+ cable when link is down */
6031 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6032 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6033
6034 e_info(drv, "NIC Link is Down\n");
6035 netif_carrier_off(netdev);
6036}
6037
6038/**
6039 * ixgbe_watchdog_flush_tx - flush queues on link down
6040 * @adapter - pointer to the device adapter structure
6041 **/
6042static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6043{
6044 int i;
6045 int some_tx_pending = 0;
6046
6047 if (!netif_carrier_ok(adapter->netdev)) {
6048 for (i = 0; i < adapter->num_tx_queues; i++) {
6049 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6050 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6051 some_tx_pending = 1;
6052 break;
6053 }
6054 }
6055
6056 if (some_tx_pending) {
6057 /* We've lost link, so the controller stops DMA,
6058 * but we've got queued Tx work that's never going
6059 * to get done, so reset controller to flush Tx.
6060 * (Do the reset outside of interrupt context).
6061 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006062 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006063 }
6064 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006065}
6066
Greg Rosea985b6c32010-11-18 03:02:52 +00006067static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6068{
6069 u32 ssvpc;
6070
6071 /* Do not perform spoof check for 82598 */
6072 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6073 return;
6074
6075 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6076
6077 /*
6078 * ssvpc register is cleared on read, if zero then no
6079 * spoofed packets in the last interval.
6080 */
6081 if (!ssvpc)
6082 return;
6083
6084 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6085}
6086
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006087/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006088 * ixgbe_watchdog_subtask - check and bring link up
6089 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006090 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006091static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006092{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006093 /* if interface is down do nothing */
6094 if (test_bit(__IXGBE_DOWN, &adapter->state))
6095 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006096
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006097 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006098
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006099 if (adapter->link_up)
6100 ixgbe_watchdog_link_is_up(adapter);
6101 else
6102 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006103
Greg Rosea985b6c32010-11-18 03:02:52 +00006104 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006105 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006106
6107 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006108}
6109
Alexander Duyck70864002011-04-27 09:13:56 +00006110/**
6111 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6112 * @adapter - the ixgbe adapter structure
6113 **/
6114static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6115{
6116 struct ixgbe_hw *hw = &adapter->hw;
6117 s32 err;
6118
6119 /* not searching for SFP so there is nothing to do here */
6120 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6121 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6122 return;
6123
6124 /* someone else is in init, wait until next service event */
6125 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6126 return;
6127
6128 err = hw->phy.ops.identify_sfp(hw);
6129 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6130 goto sfp_out;
6131
6132 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6133 /* If no cable is present, then we need to reset
6134 * the next time we find a good cable. */
6135 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6136 }
6137
6138 /* exit on error */
6139 if (err)
6140 goto sfp_out;
6141
6142 /* exit if reset not needed */
6143 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6144 goto sfp_out;
6145
6146 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6147
6148 /*
6149 * A module may be identified correctly, but the EEPROM may not have
6150 * support for that module. setup_sfp() will fail in that case, so
6151 * we should not allow that module to load.
6152 */
6153 if (hw->mac.type == ixgbe_mac_82598EB)
6154 err = hw->phy.ops.reset(hw);
6155 else
6156 err = hw->mac.ops.setup_sfp(hw);
6157
6158 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6159 goto sfp_out;
6160
6161 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6162 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6163
6164sfp_out:
6165 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6166
6167 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6168 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6169 e_dev_err("failed to initialize because an unsupported "
6170 "SFP+ module type was detected.\n");
6171 e_dev_err("Reload the driver after installing a "
6172 "supported module.\n");
6173 unregister_netdev(adapter->netdev);
6174 }
6175}
6176
6177/**
6178 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6179 * @adapter - the ixgbe adapter structure
6180 **/
6181static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6182{
6183 struct ixgbe_hw *hw = &adapter->hw;
6184 u32 autoneg;
6185 bool negotiation;
6186
6187 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6188 return;
6189
6190 /* someone else is in init, wait until next service event */
6191 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6192 return;
6193
6194 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6195
6196 autoneg = hw->phy.autoneg_advertised;
6197 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6198 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6199 hw->mac.autotry_restart = false;
6200 if (hw->mac.ops.setup_link)
6201 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6202
6203 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6204 adapter->link_check_timeout = jiffies;
6205 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6206}
6207
6208/**
6209 * ixgbe_service_timer - Timer Call-back
6210 * @data: pointer to adapter cast into an unsigned long
6211 **/
6212static void ixgbe_service_timer(unsigned long data)
6213{
6214 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6215 unsigned long next_event_offset;
6216
6217 /* poll faster when waiting for link */
6218 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6219 next_event_offset = HZ / 10;
6220 else
6221 next_event_offset = HZ * 2;
6222
6223 /* Reset the timer */
6224 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6225
6226 ixgbe_service_event_schedule(adapter);
6227}
6228
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006229static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6230{
6231 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6232 return;
6233
6234 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6235
6236 /* If we're already down or resetting, just bail */
6237 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6238 test_bit(__IXGBE_RESETTING, &adapter->state))
6239 return;
6240
6241 ixgbe_dump(adapter);
6242 netdev_err(adapter->netdev, "Reset adapter\n");
6243 adapter->tx_timeout_count++;
6244
6245 ixgbe_reinit_locked(adapter);
6246}
6247
Alexander Duyck70864002011-04-27 09:13:56 +00006248/**
6249 * ixgbe_service_task - manages and runs subtasks
6250 * @work: pointer to work_struct containing our data
6251 **/
6252static void ixgbe_service_task(struct work_struct *work)
6253{
6254 struct ixgbe_adapter *adapter = container_of(work,
6255 struct ixgbe_adapter,
6256 service_task);
6257
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006258 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006259 ixgbe_sfp_detection_subtask(adapter);
6260 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006261 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006262 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006263 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006264 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006265
6266 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006267}
6268
Alexander Duyck897ab152011-05-27 05:31:47 +00006269void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6270 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006271{
6272 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006273 u16 i = tx_ring->next_to_use;
6274
6275 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6276
6277 i++;
6278 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6279
6280 /* set bits to identify this as an advanced context descriptor */
6281 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6282
6283 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6284 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6285 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6286 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6287}
6288
6289static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6290 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6291{
Auke Kok9a799d72007-09-15 14:07:45 -07006292 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006293 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006294 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006295
Alexander Duyck897ab152011-05-27 05:31:47 +00006296 if (!skb_is_gso(skb))
6297 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006298
Alexander Duyck897ab152011-05-27 05:31:47 +00006299 if (skb_header_cloned(skb)) {
6300 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6301 if (err)
6302 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006303 }
6304
Alexander Duyck897ab152011-05-27 05:31:47 +00006305 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6306 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6307
6308 if (protocol == __constant_htons(ETH_P_IP)) {
6309 struct iphdr *iph = ip_hdr(skb);
6310 iph->tot_len = 0;
6311 iph->check = 0;
6312 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6313 iph->daddr, 0,
6314 IPPROTO_TCP,
6315 0);
6316 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6317 } else if (skb_is_gso_v6(skb)) {
6318 ipv6_hdr(skb)->payload_len = 0;
6319 tcp_hdr(skb)->check =
6320 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6321 &ipv6_hdr(skb)->daddr,
6322 0, IPPROTO_TCP, 0);
6323 }
6324
6325 l4len = tcp_hdrlen(skb);
6326 *hdr_len = skb_transport_offset(skb) + l4len;
6327
6328 /* mss_l4len_id: use 1 as index for TSO */
6329 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6330 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6331 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6332
6333 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6334 vlan_macip_lens = skb_network_header_len(skb);
6335 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6336 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6337
6338 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6339 mss_l4len_idx);
6340
6341 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006342}
6343
Alexander Duyck897ab152011-05-27 05:31:47 +00006344static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006345 struct sk_buff *skb, u32 tx_flags,
6346 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006347{
Alexander Duyck897ab152011-05-27 05:31:47 +00006348 u32 vlan_macip_lens = 0;
6349 u32 mss_l4len_idx = 0;
6350 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006351
Alexander Duyck897ab152011-05-27 05:31:47 +00006352 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6353 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6354 return false;
6355 } else {
6356 u8 l4_hdr = 0;
6357 switch (protocol) {
6358 case __constant_htons(ETH_P_IP):
6359 vlan_macip_lens |= skb_network_header_len(skb);
6360 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6361 l4_hdr = ip_hdr(skb)->protocol;
6362 break;
6363 case __constant_htons(ETH_P_IPV6):
6364 vlan_macip_lens |= skb_network_header_len(skb);
6365 l4_hdr = ipv6_hdr(skb)->nexthdr;
6366 break;
6367 default:
6368 if (unlikely(net_ratelimit())) {
6369 dev_warn(tx_ring->dev,
6370 "partial checksum but proto=%x!\n",
6371 skb->protocol);
6372 }
6373 break;
6374 }
Auke Kok9a799d72007-09-15 14:07:45 -07006375
Alexander Duyck897ab152011-05-27 05:31:47 +00006376 switch (l4_hdr) {
6377 case IPPROTO_TCP:
6378 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6379 mss_l4len_idx = tcp_hdrlen(skb) <<
6380 IXGBE_ADVTXD_L4LEN_SHIFT;
6381 break;
6382 case IPPROTO_SCTP:
6383 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6384 mss_l4len_idx = sizeof(struct sctphdr) <<
6385 IXGBE_ADVTXD_L4LEN_SHIFT;
6386 break;
6387 case IPPROTO_UDP:
6388 mss_l4len_idx = sizeof(struct udphdr) <<
6389 IXGBE_ADVTXD_L4LEN_SHIFT;
6390 break;
6391 default:
6392 if (unlikely(net_ratelimit())) {
6393 dev_warn(tx_ring->dev,
6394 "partial checksum but l4 proto=%x!\n",
6395 skb->protocol);
6396 }
6397 break;
6398 }
Auke Kok9a799d72007-09-15 14:07:45 -07006399 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006400
Alexander Duyck897ab152011-05-27 05:31:47 +00006401 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6402 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6403
6404 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6405 type_tucmd, mss_l4len_idx);
6406
6407 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006408}
6409
6410static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006411 struct ixgbe_ring *tx_ring,
6412 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006413 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006414{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006415 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006416 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006417 unsigned int len;
6418 unsigned int total = skb->len;
Alexander Duyck63544e92011-05-27 05:31:42 +00006419 unsigned int offset = 0, size, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006420 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6421 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006422 unsigned int bytecount = skb->len;
6423 u16 gso_segs = 1;
Alexander Duyck63544e92011-05-27 05:31:42 +00006424 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07006425
6426 i = tx_ring->next_to_use;
6427
Yi Zoueacd73f2009-05-13 13:11:06 +00006428 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6429 /* excluding fcoe_crc_eof for FCoE */
6430 total -= sizeof(struct fcoe_crc_eof);
6431
6432 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006433 while (len) {
6434 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6435 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6436
6437 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006438 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006439 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006440 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006441 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006442 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006443 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006444 tx_buffer_info->time_stamp = jiffies;
6445 tx_buffer_info->next_to_watch = i;
6446
6447 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006448 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006449 offset += size;
6450 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006451
6452 if (len) {
6453 i++;
6454 if (i == tx_ring->count)
6455 i = 0;
6456 }
Auke Kok9a799d72007-09-15 14:07:45 -07006457 }
6458
6459 for (f = 0; f < nr_frags; f++) {
6460 struct skb_frag_struct *frag;
6461
6462 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006463 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006464 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006465
6466 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006467 i++;
6468 if (i == tx_ring->count)
6469 i = 0;
6470
Auke Kok9a799d72007-09-15 14:07:45 -07006471 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6472 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6473
6474 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006475 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006476 frag->page,
6477 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006478 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006479 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006480 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006481 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006482 tx_buffer_info->time_stamp = jiffies;
6483 tx_buffer_info->next_to_watch = i;
6484
6485 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006486 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006487 offset += size;
6488 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006489 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006490 if (total == 0)
6491 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006492 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006493
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006494 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6495 gso_segs = skb_shinfo(skb)->gso_segs;
6496#ifdef IXGBE_FCOE
6497 /* adjust for FCoE Sequence Offload */
6498 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6499 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6500 skb_shinfo(skb)->gso_size);
6501#endif /* IXGBE_FCOE */
6502 bytecount += (gso_segs - 1) * hdr_len;
6503
6504 /* multiply data chunks by size of headers */
6505 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6506 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006507 tx_ring->tx_buffer_info[i].skb = skb;
6508 tx_ring->tx_buffer_info[first].next_to_watch = i;
6509
6510 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006511
6512dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006513 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006514
6515 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6516 tx_buffer_info->dma = 0;
6517 tx_buffer_info->time_stamp = 0;
6518 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006519 if (count)
6520 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006521
6522 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006523 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006524 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006525 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006526 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006527 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006528 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006529 }
6530
Anton Blancharde44d38e2010-02-03 13:12:51 +00006531 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006532}
6533
Alexander Duyck84ea2592010-11-16 19:26:49 -08006534static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006535 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006536{
6537 union ixgbe_adv_tx_desc *tx_desc = NULL;
6538 struct ixgbe_tx_buffer *tx_buffer_info;
6539 u32 olinfo_status = 0, cmd_type_len = 0;
6540 unsigned int i;
6541 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6542
6543 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6544
6545 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6546
6547 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6548 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6549
6550 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6551 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6552
6553 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006554 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006555
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006556 /* use index 1 context for tso */
6557 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006558 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6559 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006560 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006561
6562 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6563 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006564 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006565
Yi Zoueacd73f2009-05-13 13:11:06 +00006566 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6567 olinfo_status |= IXGBE_ADVTXD_CC;
6568 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6569 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6570 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6571 }
6572
Auke Kok9a799d72007-09-15 14:07:45 -07006573 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6574
6575 i = tx_ring->next_to_use;
6576 while (count--) {
6577 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006578 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006579 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6580 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006581 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006582 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006583 i++;
6584 if (i == tx_ring->count)
6585 i = 0;
6586 }
6587
6588 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6589
6590 /*
6591 * Force memory writes to complete before letting h/w
6592 * know there are new descriptors to fetch. (Only
6593 * applicable for weak-ordered memory model archs,
6594 * such as IA-64).
6595 */
6596 wmb();
6597
6598 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006599 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006600}
6601
Alexander Duyck69830522011-01-06 14:29:58 +00006602static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6603 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006604{
Alexander Duyck69830522011-01-06 14:29:58 +00006605 struct ixgbe_q_vector *q_vector = ring->q_vector;
6606 union ixgbe_atr_hash_dword input = { .dword = 0 };
6607 union ixgbe_atr_hash_dword common = { .dword = 0 };
6608 union {
6609 unsigned char *network;
6610 struct iphdr *ipv4;
6611 struct ipv6hdr *ipv6;
6612 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006613 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006614 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006615
Alexander Duyck69830522011-01-06 14:29:58 +00006616 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6617 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006618 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006619
Alexander Duyck69830522011-01-06 14:29:58 +00006620 /* do nothing if sampling is disabled */
6621 if (!ring->atr_sample_rate)
6622 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006623
Alexander Duyck69830522011-01-06 14:29:58 +00006624 ring->atr_count++;
6625
6626 /* snag network header to get L4 type and address */
6627 hdr.network = skb_network_header(skb);
6628
6629 /* Currently only IPv4/IPv6 with TCP is supported */
6630 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6631 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6632 (protocol != __constant_htons(ETH_P_IP) ||
6633 hdr.ipv4->protocol != IPPROTO_TCP))
6634 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006635
6636 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006637
Alexander Duyck69830522011-01-06 14:29:58 +00006638 /* skip this packet since the socket is closing */
6639 if (th->fin)
6640 return;
6641
6642 /* sample on all syn packets or once every atr sample count */
6643 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6644 return;
6645
6646 /* reset sample count */
6647 ring->atr_count = 0;
6648
6649 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6650
6651 /*
6652 * src and dst are inverted, think how the receiver sees them
6653 *
6654 * The input is broken into two sections, a non-compressed section
6655 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6656 * is XORed together and stored in the compressed dword.
6657 */
6658 input.formatted.vlan_id = vlan_id;
6659
6660 /*
6661 * since src port and flex bytes occupy the same word XOR them together
6662 * and write the value to source port portion of compressed dword
6663 */
6664 if (vlan_id)
6665 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6666 else
6667 common.port.src ^= th->dest ^ protocol;
6668 common.port.dst ^= th->source;
6669
6670 if (protocol == __constant_htons(ETH_P_IP)) {
6671 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6672 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6673 } else {
6674 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6675 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6676 hdr.ipv6->saddr.s6_addr32[1] ^
6677 hdr.ipv6->saddr.s6_addr32[2] ^
6678 hdr.ipv6->saddr.s6_addr32[3] ^
6679 hdr.ipv6->daddr.s6_addr32[0] ^
6680 hdr.ipv6->daddr.s6_addr32[1] ^
6681 hdr.ipv6->daddr.s6_addr32[2] ^
6682 hdr.ipv6->daddr.s6_addr32[3];
6683 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006684
6685 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006686 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6687 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006688}
6689
Alexander Duyck63544e92011-05-27 05:31:42 +00006690static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006691{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006692 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006693 /* Herbert's original patch had:
6694 * smp_mb__after_netif_stop_queue();
6695 * but since that doesn't exist yet, just open code it. */
6696 smp_mb();
6697
6698 /* We need to check again in a case another CPU has just
6699 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006700 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006701 return -EBUSY;
6702
6703 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006704 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006705 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006706 return 0;
6707}
6708
Alexander Duyck82d4e462011-06-11 01:44:58 +00006709static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006710{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006711 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006712 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006713 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006714}
6715
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006716static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6717{
6718 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006719 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6720 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006721#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006722 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006723
John Fastabende5b64632011-03-08 03:44:52 +00006724 if (((protocol == htons(ETH_P_FCOE)) ||
6725 (protocol == htons(ETH_P_FIP))) &&
6726 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6727 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6728 txq += adapter->ring_feature[RING_F_FCOE].mask;
6729 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006730 }
6731#endif
6732
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006733 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6734 while (unlikely(txq >= dev->real_num_tx_queues))
6735 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006736 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006737 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006738
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006739 return skb_tx_hash(dev, skb);
6740}
6741
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006742netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006743 struct ixgbe_adapter *adapter,
6744 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006745{
Yi Zou5f715822009-12-03 11:32:44 +00006746 int tso;
Alexander Duycka535c302011-05-27 05:31:52 +00006747 u32 tx_flags = 0;
6748#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6749 unsigned short f;
6750#endif
Alexander Duyck63544e92011-05-27 05:31:42 +00006751 u16 first;
Alexander Duycka535c302011-05-27 05:31:52 +00006752 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Hao Zheng5e09a102010-11-11 13:47:59 +00006753 __be16 protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006754 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006755
Alexander Duycka535c302011-05-27 05:31:52 +00006756 /*
6757 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6758 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6759 * + 2 desc gap to keep tail from touching head,
6760 * + 1 desc for context descriptor,
6761 * otherwise try next time
6762 */
6763#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6764 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6765 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6766#else
6767 count += skb_shinfo(skb)->nr_frags;
6768#endif
6769 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6770 tx_ring->tx_stats.tx_busy++;
6771 return NETDEV_TX_BUSY;
6772 }
6773
Hao Zheng5e09a102010-11-11 13:47:59 +00006774 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006775
Jesse Grosseab6d182010-10-20 13:56:03 +00006776 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006777 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006778 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6779 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006780 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006781 }
6782 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6783 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006784 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6785 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006786 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006787 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6788 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006789 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006790
Yi Zou09ad1cc2009-09-03 14:56:10 +00006791#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006792 /* for FCoE with DCB, we force the priority to what
6793 * was specified by the switch */
6794 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006795 (protocol == htons(ETH_P_FCOE)))
6796 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Alexander Duycka535c302011-05-27 05:31:52 +00006797
Robert Loveca77cd52010-03-24 12:45:00 +00006798#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006799 /* record the location of the first descriptor for this packet */
Auke Kok9a799d72007-09-15 14:07:45 -07006800 first = tx_ring->next_to_use;
Alexander Duycka535c302011-05-27 05:31:52 +00006801
Yi Zoueacd73f2009-05-13 13:11:06 +00006802 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6803#ifdef IXGBE_FCOE
6804 /* setup tx offload for FCoE */
Alexander Duyck897ab152011-05-27 05:31:47 +00006805 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6806 if (tso < 0)
6807 goto out_drop;
6808 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006809 tx_flags |= IXGBE_TX_FLAGS_FSO;
6810#endif /* IXGBE_FCOE */
6811 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006812 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006813 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006814 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6815 if (tso < 0)
6816 goto out_drop;
6817 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006818 tx_flags |= IXGBE_TX_FLAGS_TSO;
Alexander Duyck897ab152011-05-27 05:31:47 +00006819 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
Yi Zoueacd73f2009-05-13 13:11:06 +00006820 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006821 }
6822
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006823 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006824 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006825 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006826 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6827 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006828 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006829 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006830
Alexander Duyck44df32c2009-03-31 21:34:23 +00006831 } else {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006832 tx_ring->tx_buffer_info[first].time_stamp = 0;
6833 tx_ring->next_to_use = first;
Alexander Duyck897ab152011-05-27 05:31:47 +00006834 goto out_drop;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006835 }
Auke Kok9a799d72007-09-15 14:07:45 -07006836
6837 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006838
6839out_drop:
6840 dev_kfree_skb_any(skb);
6841 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006842}
6843
Alexander Duyck84418e32010-08-19 13:40:54 +00006844static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6845{
6846 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6847 struct ixgbe_ring *tx_ring;
6848
6849 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006850 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006851}
6852
Auke Kok9a799d72007-09-15 14:07:45 -07006853/**
Auke Kok9a799d72007-09-15 14:07:45 -07006854 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6855 * @netdev: network interface device structure
6856 * @p: pointer to an address structure
6857 *
6858 * Returns 0 on success, negative on failure
6859 **/
6860static int ixgbe_set_mac(struct net_device *netdev, void *p)
6861{
6862 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006863 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006864 struct sockaddr *addr = p;
6865
6866 if (!is_valid_ether_addr(addr->sa_data))
6867 return -EADDRNOTAVAIL;
6868
6869 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006870 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006871
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006872 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6873 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006874
6875 return 0;
6876}
6877
Ben Hutchings6b73e102009-04-29 08:08:58 +00006878static int
6879ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6880{
6881 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6882 struct ixgbe_hw *hw = &adapter->hw;
6883 u16 value;
6884 int rc;
6885
6886 if (prtad != hw->phy.mdio.prtad)
6887 return -EINVAL;
6888 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6889 if (!rc)
6890 rc = value;
6891 return rc;
6892}
6893
6894static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6895 u16 addr, u16 value)
6896{
6897 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6898 struct ixgbe_hw *hw = &adapter->hw;
6899
6900 if (prtad != hw->phy.mdio.prtad)
6901 return -EINVAL;
6902 return hw->phy.ops.write_reg(hw, addr, devad, value);
6903}
6904
6905static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6906{
6907 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6908
6909 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6910}
6911
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006912/**
6913 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006914 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006915 * @netdev: network interface device structure
6916 *
6917 * Returns non-zero on failure
6918 **/
6919static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6920{
6921 int err = 0;
6922 struct ixgbe_adapter *adapter = netdev_priv(dev);
6923 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6924
6925 if (is_valid_ether_addr(mac->san_addr)) {
6926 rtnl_lock();
6927 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6928 rtnl_unlock();
6929 }
6930 return err;
6931}
6932
6933/**
6934 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006935 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006936 * @netdev: network interface device structure
6937 *
6938 * Returns non-zero on failure
6939 **/
6940static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6941{
6942 int err = 0;
6943 struct ixgbe_adapter *adapter = netdev_priv(dev);
6944 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6945
6946 if (is_valid_ether_addr(mac->san_addr)) {
6947 rtnl_lock();
6948 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6949 rtnl_unlock();
6950 }
6951 return err;
6952}
6953
Auke Kok9a799d72007-09-15 14:07:45 -07006954#ifdef CONFIG_NET_POLL_CONTROLLER
6955/*
6956 * Polling 'interrupt' - used by things like netconsole to send skbs
6957 * without having to re-enable interrupts. It's not called while
6958 * the interrupt routine is executing.
6959 */
6960static void ixgbe_netpoll(struct net_device *netdev)
6961{
6962 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006963 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006964
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006965 /* if interface is down do nothing */
6966 if (test_bit(__IXGBE_DOWN, &adapter->state))
6967 return;
6968
Auke Kok9a799d72007-09-15 14:07:45 -07006969 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006970 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6971 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6972 for (i = 0; i < num_q_vectors; i++) {
6973 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
6974 ixgbe_msix_clean_many(0, q_vector);
6975 }
6976 } else {
6977 ixgbe_intr(adapter->pdev->irq, netdev);
6978 }
Auke Kok9a799d72007-09-15 14:07:45 -07006979 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006980}
6981#endif
6982
Eric Dumazetde1036b2010-10-20 23:00:04 +00006983static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6984 struct rtnl_link_stats64 *stats)
6985{
6986 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6987 int i;
6988
Eric Dumazet1a515022010-11-16 19:26:42 -08006989 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006990 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006991 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006992 u64 bytes, packets;
6993 unsigned int start;
6994
Eric Dumazet1a515022010-11-16 19:26:42 -08006995 if (ring) {
6996 do {
6997 start = u64_stats_fetch_begin_bh(&ring->syncp);
6998 packets = ring->stats.packets;
6999 bytes = ring->stats.bytes;
7000 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7001 stats->rx_packets += packets;
7002 stats->rx_bytes += bytes;
7003 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007004 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007005
7006 for (i = 0; i < adapter->num_tx_queues; i++) {
7007 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7008 u64 bytes, packets;
7009 unsigned int start;
7010
7011 if (ring) {
7012 do {
7013 start = u64_stats_fetch_begin_bh(&ring->syncp);
7014 packets = ring->stats.packets;
7015 bytes = ring->stats.bytes;
7016 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7017 stats->tx_packets += packets;
7018 stats->tx_bytes += bytes;
7019 }
7020 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007021 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007022 /* following stats updated by ixgbe_watchdog_task() */
7023 stats->multicast = netdev->stats.multicast;
7024 stats->rx_errors = netdev->stats.rx_errors;
7025 stats->rx_length_errors = netdev->stats.rx_length_errors;
7026 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7027 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7028 return stats;
7029}
7030
John Fastabend8b1c0b22011-05-03 02:26:48 +00007031/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7032 * #adapter: pointer to ixgbe_adapter
7033 * @tc: number of traffic classes currently enabled
7034 *
7035 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7036 * 802.1Q priority maps to a packet buffer that exists.
7037 */
7038static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7039{
7040 struct ixgbe_hw *hw = &adapter->hw;
7041 u32 reg, rsave;
7042 int i;
7043
7044 /* 82598 have a static priority to TC mapping that can not
7045 * be changed so no validation is needed.
7046 */
7047 if (hw->mac.type == ixgbe_mac_82598EB)
7048 return;
7049
7050 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7051 rsave = reg;
7052
7053 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7054 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7055
7056 /* If up2tc is out of bounds default to zero */
7057 if (up2tc > tc)
7058 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7059 }
7060
7061 if (reg != rsave)
7062 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7063
7064 return;
7065}
7066
7067
7068/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7069 * classes.
7070 *
7071 * @netdev: net device to configure
7072 * @tc: number of traffic classes to enable
7073 */
7074int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7075{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007076 struct ixgbe_adapter *adapter = netdev_priv(dev);
7077 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007078
7079 /* If DCB is anabled do not remove traffic classes, multiple
7080 * traffic classes are required to implement DCB
7081 */
7082 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7083 return 0;
7084
7085 /* Hardware supports up to 8 traffic classes */
7086 if (tc > MAX_TRAFFIC_CLASS ||
7087 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7088 return -EINVAL;
7089
7090 /* Hardware has to reinitialize queues and interrupts to
7091 * match packet buffer alignment. Unfortunantly, the
7092 * hardware is not flexible enough to do this dynamically.
7093 */
7094 if (netif_running(dev))
7095 ixgbe_close(dev);
7096 ixgbe_clear_interrupt_scheme(adapter);
7097
7098 if (tc)
7099 netdev_set_num_tc(dev, tc);
7100 else
7101 netdev_reset_tc(dev);
7102
John Fastabend8b1c0b22011-05-03 02:26:48 +00007103 ixgbe_init_interrupt_scheme(adapter);
7104 ixgbe_validate_rtr(adapter, tc);
7105 if (netif_running(dev))
7106 ixgbe_open(dev);
7107
7108 return 0;
7109}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007110
Don Skidmore082757a2011-07-21 05:55:00 +00007111void ixgbe_do_reset(struct net_device *netdev)
7112{
7113 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7114
7115 if (netif_running(netdev))
7116 ixgbe_reinit_locked(adapter);
7117 else
7118 ixgbe_reset(adapter);
7119}
7120
7121static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7122{
7123 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7124
7125#ifdef CONFIG_DCB
7126 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7127 data &= ~NETIF_F_HW_VLAN_RX;
7128#endif
7129
7130 /* return error if RXHASH is being enabled when RSS is not supported */
7131 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7132 data &= ~NETIF_F_RXHASH;
7133
7134 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7135 if (!(data & NETIF_F_RXCSUM))
7136 data &= ~NETIF_F_LRO;
7137
7138 /* Turn off LRO if not RSC capable or invalid ITR settings */
7139 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7140 data &= ~NETIF_F_LRO;
7141 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7142 (adapter->rx_itr_setting != 1 &&
7143 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7144 data &= ~NETIF_F_LRO;
7145 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7146 }
7147
7148 return data;
7149}
7150
7151static int ixgbe_set_features(struct net_device *netdev, u32 data)
7152{
7153 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7154 bool need_reset = false;
7155
7156 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7157 if (!(data & NETIF_F_RXCSUM))
7158 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7159 else
7160 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7161
7162 /* Make sure RSC matches LRO, reset if change */
7163 if (!!(data & NETIF_F_LRO) !=
7164 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7165 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7166 switch (adapter->hw.mac.type) {
7167 case ixgbe_mac_X540:
7168 case ixgbe_mac_82599EB:
7169 need_reset = true;
7170 break;
7171 default:
7172 break;
7173 }
7174 }
7175
7176 /*
7177 * Check if Flow Director n-tuple support was enabled or disabled. If
7178 * the state changed, we need to reset.
7179 */
7180 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7181 /* turn off ATR, enable perfect filters and reset */
7182 if (data & NETIF_F_NTUPLE) {
7183 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7184 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7185 need_reset = true;
7186 }
7187 } else if (!(data & NETIF_F_NTUPLE)) {
7188 /* turn off Flow Director, set ATR and reset */
7189 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7190 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7191 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7192 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7193 need_reset = true;
7194 }
7195
7196 if (need_reset)
7197 ixgbe_do_reset(netdev);
7198
7199 return 0;
7200
7201}
7202
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007203static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007204 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007205 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007206 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007207 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007208 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007209 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7210 .ndo_validate_addr = eth_validate_addr,
7211 .ndo_set_mac_address = ixgbe_set_mac,
7212 .ndo_change_mtu = ixgbe_change_mtu,
7213 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007214 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7215 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007216 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007217 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7218 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7219 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7220 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007221 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007222 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007223#ifdef CONFIG_NET_POLL_CONTROLLER
7224 .ndo_poll_controller = ixgbe_netpoll,
7225#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007226#ifdef IXGBE_FCOE
7227 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007228 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007229 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007230 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7231 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007232 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007233#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007234 .ndo_set_features = ixgbe_set_features,
7235 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007236};
7237
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007238static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7239 const struct ixgbe_info *ii)
7240{
7241#ifdef CONFIG_PCI_IOV
7242 struct ixgbe_hw *hw = &adapter->hw;
7243 int err;
Greg Rosea1cbb152011-05-13 01:33:48 +00007244 int num_vf_macvlans, i;
7245 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007246
Greg Rose3377eba2010-12-07 08:16:45 +00007247 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007248 return;
7249
7250 /* The 82599 supports up to 64 VFs per physical function
7251 * but this implementation limits allocation to 63 so that
7252 * basic networking resources are still available to the
7253 * physical function
7254 */
7255 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7256 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7257 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7258 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007259 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007260 goto err_novfs;
7261 }
Greg Rosea1cbb152011-05-13 01:33:48 +00007262
7263 num_vf_macvlans = hw->mac.num_rar_entries -
7264 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7265
7266 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7267 sizeof(struct vf_macvlans),
7268 GFP_KERNEL);
7269 if (mv_list) {
7270 /* Initialize list of VF macvlans */
7271 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7272 for (i = 0; i < num_vf_macvlans; i++) {
7273 mv_list->vf = -1;
7274 mv_list->free = true;
7275 mv_list->rar_entry = hw->mac.num_rar_entries -
7276 (i + adapter->num_vfs + 1);
7277 list_add(&mv_list->l, &adapter->vf_mvs.l);
7278 mv_list++;
7279 }
7280 }
7281
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007282 /* If call to enable VFs succeeded then allocate memory
7283 * for per VF control structures.
7284 */
7285 adapter->vfinfo =
7286 kcalloc(adapter->num_vfs,
7287 sizeof(struct vf_data_storage), GFP_KERNEL);
7288 if (adapter->vfinfo) {
7289 /* Now that we're sure SR-IOV is enabled
7290 * and memory allocated set up the mailbox parameters
7291 */
7292 ixgbe_init_mbx_params_pf(hw);
7293 memcpy(&hw->mbx.ops, ii->mbx_ops,
7294 sizeof(hw->mbx.ops));
7295
7296 /* Disable RSC when in SR-IOV mode */
7297 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7298 IXGBE_FLAG2_RSC_ENABLED);
7299 return;
7300 }
7301
7302 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007303 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7304 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007305 pci_disable_sriov(adapter->pdev);
7306
7307err_novfs:
7308 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7309 adapter->num_vfs = 0;
7310#endif /* CONFIG_PCI_IOV */
7311}
7312
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007313/**
Auke Kok9a799d72007-09-15 14:07:45 -07007314 * ixgbe_probe - Device Initialization Routine
7315 * @pdev: PCI device information struct
7316 * @ent: entry in ixgbe_pci_tbl
7317 *
7318 * Returns 0 on success, negative on failure
7319 *
7320 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7321 * The OS initialization, configuring of the adapter private structure,
7322 * and a hardware reset occur.
7323 **/
7324static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007325 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007326{
7327 struct net_device *netdev;
7328 struct ixgbe_adapter *adapter = NULL;
7329 struct ixgbe_hw *hw;
7330 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007331 static int cards_found;
7332 int i, err, pci_using_dac;
Don Skidmore289700d2010-12-03 03:32:58 +00007333 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007334 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007335#ifdef IXGBE_FCOE
7336 u16 device_caps;
7337#endif
Don Skidmore289700d2010-12-03 03:32:58 +00007338 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007339
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007340 /* Catch broken hardware that put the wrong VF device ID in
7341 * the PCIe SR-IOV capability.
7342 */
7343 if (pdev->is_virtfn) {
7344 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7345 pci_name(pdev), pdev->vendor, pdev->device);
7346 return -EINVAL;
7347 }
7348
gouji-new9ce77662009-05-06 10:44:45 +00007349 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007350 if (err)
7351 return err;
7352
Nick Nunley1b507732010-04-27 13:10:27 +00007353 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7354 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007355 pci_using_dac = 1;
7356 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007357 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007358 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007359 err = dma_set_coherent_mask(&pdev->dev,
7360 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007361 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007362 dev_err(&pdev->dev,
7363 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007364 goto err_dma;
7365 }
7366 }
7367 pci_using_dac = 0;
7368 }
7369
gouji-new9ce77662009-05-06 10:44:45 +00007370 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007371 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007372 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007373 dev_err(&pdev->dev,
7374 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007375 goto err_pci_reg;
7376 }
7377
Frans Pop19d5afd2009-10-02 10:04:12 -07007378 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007379
Auke Kok9a799d72007-09-15 14:07:45 -07007380 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007381 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007382
John Fastabende901acd2011-04-26 07:26:08 +00007383#ifdef CONFIG_IXGBE_DCB
7384 indices *= MAX_TRAFFIC_CLASS;
7385#endif
7386
John Fastabendc85a2612010-02-25 23:15:21 +00007387 if (ii->mac == ixgbe_mac_82598EB)
7388 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7389 else
7390 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7391
John Fastabende901acd2011-04-26 07:26:08 +00007392#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007393 indices += min_t(unsigned int, num_possible_cpus(),
7394 IXGBE_MAX_FCOE_INDICES);
7395#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007396 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007397 if (!netdev) {
7398 err = -ENOMEM;
7399 goto err_alloc_etherdev;
7400 }
7401
Auke Kok9a799d72007-09-15 14:07:45 -07007402 SET_NETDEV_DEV(netdev, &pdev->dev);
7403
Auke Kok9a799d72007-09-15 14:07:45 -07007404 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007405 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007406
7407 adapter->netdev = netdev;
7408 adapter->pdev = pdev;
7409 hw = &adapter->hw;
7410 hw->back = adapter;
7411 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7412
Jeff Kirsher05857982008-09-11 19:57:00 -07007413 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007414 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007415 if (!hw->hw_addr) {
7416 err = -EIO;
7417 goto err_ioremap;
7418 }
7419
7420 for (i = 1; i <= 5; i++) {
7421 if (pci_resource_len(pdev, i) == 0)
7422 continue;
7423 }
7424
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007425 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007426 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007427 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007428 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007429
Auke Kok9a799d72007-09-15 14:07:45 -07007430 adapter->bd_number = cards_found;
7431
Auke Kok9a799d72007-09-15 14:07:45 -07007432 /* Setup hw api */
7433 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007434 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007435
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007436 /* EEPROM */
7437 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7438 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7439 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7440 if (!(eec & (1 << 8)))
7441 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7442
7443 /* PHY */
7444 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007445 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007446 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7447 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7448 hw->phy.mdio.mmds = 0;
7449 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7450 hw->phy.mdio.dev = netdev;
7451 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7452 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007453
Don Skidmore8ca783a2009-05-26 20:40:47 -07007454 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007455
7456 /* setup the private structure */
7457 err = ixgbe_sw_init(adapter);
7458 if (err)
7459 goto err_sw_init;
7460
Don Skidmoree86bff02010-02-11 04:14:08 +00007461 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007462 switch (adapter->hw.mac.type) {
7463 case ixgbe_mac_82599EB:
7464 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007465 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007466 break;
7467 default:
7468 break;
7469 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007470
Don Skidmorebf069c92009-05-07 10:39:54 +00007471 /*
7472 * If there is a fan on this device and it has failed log the
7473 * failure.
7474 */
7475 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7476 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7477 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007478 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007479 }
7480
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007481 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007482 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007483 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007484 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007485 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7486 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007487 err = 0;
7488 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007489 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007490 "module type was detected.\n");
7491 e_dev_err("Reload the driver after installing a supported "
7492 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007493 goto err_sw_init;
7494 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007495 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007496 goto err_sw_init;
7497 }
7498
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007499 ixgbe_probe_vf(adapter, ii);
7500
Emil Tantilov396e7992010-07-01 20:05:12 +00007501 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007502 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007503 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007504 NETIF_F_HW_VLAN_TX |
7505 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007506 NETIF_F_HW_VLAN_FILTER |
7507 NETIF_F_TSO |
7508 NETIF_F_TSO6 |
7509 NETIF_F_GRO |
7510 NETIF_F_RXHASH |
7511 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007512
Don Skidmore082757a2011-07-21 05:55:00 +00007513 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007514
Don Skidmore58be7662011-04-12 09:42:11 +00007515 switch (adapter->hw.mac.type) {
7516 case ixgbe_mac_82599EB:
7517 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007518 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007519 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7520 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007521 break;
7522 default:
7523 break;
7524 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007525
Jeff Kirsherad31c402008-06-05 04:05:30 -07007526 netdev->vlan_features |= NETIF_F_TSO;
7527 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007528 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007529 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007530 netdev->vlan_features |= NETIF_F_SG;
7531
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007532 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7533 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7534 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007535
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007536#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007537 netdev->dcbnl_ops = &dcbnl_ops;
7538#endif
7539
Yi Zoueacd73f2009-05-13 13:11:06 +00007540#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007541 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007542 if (hw->mac.ops.get_device_caps) {
7543 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007544 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7545 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007546 }
7547 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007548 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7549 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7550 netdev->vlan_features |= NETIF_F_FSO;
7551 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7552 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007553#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007554 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007555 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007556 netdev->vlan_features |= NETIF_F_HIGHDMA;
7557 }
Auke Kok9a799d72007-09-15 14:07:45 -07007558
Don Skidmore082757a2011-07-21 05:55:00 +00007559 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7560 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007561 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007562 netdev->features |= NETIF_F_LRO;
7563
Auke Kok9a799d72007-09-15 14:07:45 -07007564 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007565 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007566 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007567 err = -EIO;
7568 goto err_eeprom;
7569 }
7570
7571 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7572 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7573
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007574 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007575 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007576 err = -EIO;
7577 goto err_eeprom;
7578 }
7579
Don Skidmorec6ecf392010-12-03 03:31:51 +00007580 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7581 if (hw->mac.ops.disable_tx_laser &&
7582 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007583 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007584 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007585 hw->mac.ops.disable_tx_laser(hw);
7586
Alexander Duyck70864002011-04-27 09:13:56 +00007587 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7588 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007589
Alexander Duyck70864002011-04-27 09:13:56 +00007590 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7591 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007592
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007593 err = ixgbe_init_interrupt_scheme(adapter);
7594 if (err)
7595 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007596
Don Skidmore082757a2011-07-21 05:55:00 +00007597 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7598 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007599 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007600 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007601
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007602 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007603 case IXGBE_DEV_ID_82599_SFP:
7604 /* Only this subdevice supports WOL */
7605 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007606 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007607 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007608 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7609 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007610 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007611 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007612 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007613 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007614 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007615 break;
7616 default:
7617 adapter->wol = 0;
7618 break;
7619 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007620 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7621
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007622 /* pick up the PCI bus settings for reporting later */
7623 hw->mac.ops.get_bus_info(hw);
7624
Auke Kok9a799d72007-09-15 14:07:45 -07007625 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007626 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007627 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7628 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007629 "Unknown"),
7630 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7631 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7632 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7633 "Unknown"),
7634 netdev->dev_addr);
Don Skidmore289700d2010-12-03 03:32:58 +00007635
7636 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7637 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007638 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007639 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700d2010-12-03 03:32:58 +00007640 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007641 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700d2010-12-03 03:32:58 +00007642 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007643 else
Don Skidmore289700d2010-12-03 03:32:58 +00007644 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7645 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007646
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007647 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007648 e_dev_warn("PCI-Express bandwidth available for this card is "
7649 "not sufficient for optimal performance.\n");
7650 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7651 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007652 }
7653
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007654 /* save off EEPROM version number */
7655 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7656
Auke Kok9a799d72007-09-15 14:07:45 -07007657 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007658 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007659
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007660 if (err == IXGBE_ERR_EEPROM_VERSION) {
7661 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007662 e_dev_warn("This device is a pre-production adapter/LOM. "
7663 "Please be aware there may be issues associated "
7664 "with your hardware. If you are experiencing "
7665 "problems please contact your Intel or hardware "
7666 "representative who provided you with this "
7667 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007668 }
Auke Kok9a799d72007-09-15 14:07:45 -07007669 strcpy(netdev->name, "eth%d");
7670 err = register_netdev(netdev);
7671 if (err)
7672 goto err_register;
7673
Jesse Brandeburg54386462009-04-17 20:44:27 +00007674 /* carrier off reporting is important to ethtool even BEFORE open */
7675 netif_carrier_off(netdev);
7676
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007677#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007678 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007679 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007680 ixgbe_setup_dca(adapter);
7681 }
7682#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007683 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007684 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007685 for (i = 0; i < adapter->num_vfs; i++)
7686 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7687 }
7688
Emil Tantilov9612de92011-05-07 07:40:20 +00007689 /* Inform firmware of driver version */
7690 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007691 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7692 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007693
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007694 /* add san mac addr to netdev */
7695 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007696
Emil Tantilov849c4542010-06-03 16:53:41 +00007697 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007698 cards_found++;
7699 return 0;
7700
7701err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007702 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007703 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007704err_sw_init:
7705err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007706 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7707 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007708 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007709 iounmap(hw->hw_addr);
7710err_ioremap:
7711 free_netdev(netdev);
7712err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007713 pci_release_selected_regions(pdev,
7714 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007715err_pci_reg:
7716err_dma:
7717 pci_disable_device(pdev);
7718 return err;
7719}
7720
7721/**
7722 * ixgbe_remove - Device Removal Routine
7723 * @pdev: PCI device information struct
7724 *
7725 * ixgbe_remove is called by the PCI subsystem to alert the driver
7726 * that it should release a PCI device. The could be caused by a
7727 * Hot-Plug event, or because the driver is going to be removed from
7728 * memory.
7729 **/
7730static void __devexit ixgbe_remove(struct pci_dev *pdev)
7731{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007732 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7733 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007734
7735 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007736 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007737
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007738#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007739 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7740 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7741 dca_remove_requester(&pdev->dev);
7742 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7743 }
7744
7745#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007746#ifdef IXGBE_FCOE
7747 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7748 ixgbe_cleanup_fcoe(adapter);
7749
7750#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007751
7752 /* remove the added san mac */
7753 ixgbe_del_sanmac_netdev(netdev);
7754
Donald Skidmorec4900be2008-11-20 21:11:42 -08007755 if (netdev->reg_state == NETREG_REGISTERED)
7756 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007757
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007758 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7759 ixgbe_disable_sriov(adapter);
7760
Alexander Duyck7a921c92009-05-06 10:43:28 +00007761 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007762
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007763 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007764
7765 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007766 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007767 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007768
Emil Tantilov849c4542010-06-03 16:53:41 +00007769 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007770
Auke Kok9a799d72007-09-15 14:07:45 -07007771 free_netdev(netdev);
7772
Frans Pop19d5afd2009-10-02 10:04:12 -07007773 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007774
Auke Kok9a799d72007-09-15 14:07:45 -07007775 pci_disable_device(pdev);
7776}
7777
7778/**
7779 * ixgbe_io_error_detected - called when PCI error is detected
7780 * @pdev: Pointer to PCI device
7781 * @state: The current pci connection state
7782 *
7783 * This function is called after a PCI bus error affecting
7784 * this device has been detected.
7785 */
7786static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007787 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007788{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007789 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7790 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007791
7792 netif_device_detach(netdev);
7793
Breno Leitao3044b8d2009-05-06 10:44:26 +00007794 if (state == pci_channel_io_perm_failure)
7795 return PCI_ERS_RESULT_DISCONNECT;
7796
Auke Kok9a799d72007-09-15 14:07:45 -07007797 if (netif_running(netdev))
7798 ixgbe_down(adapter);
7799 pci_disable_device(pdev);
7800
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007801 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007802 return PCI_ERS_RESULT_NEED_RESET;
7803}
7804
7805/**
7806 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7807 * @pdev: Pointer to PCI device
7808 *
7809 * Restart the card from scratch, as if from a cold-boot.
7810 */
7811static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7812{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007813 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007814 pci_ers_result_t result;
7815 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007816
gouji-new9ce77662009-05-06 10:44:45 +00007817 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007818 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007819 result = PCI_ERS_RESULT_DISCONNECT;
7820 } else {
7821 pci_set_master(pdev);
7822 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007823 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007824
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007825 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007826
7827 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007828 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007829 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007830 }
Auke Kok9a799d72007-09-15 14:07:45 -07007831
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007832 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7833 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007834 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7835 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007836 /* non-fatal, continue */
7837 }
Auke Kok9a799d72007-09-15 14:07:45 -07007838
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007839 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007840}
7841
7842/**
7843 * ixgbe_io_resume - called when traffic can start flowing again.
7844 * @pdev: Pointer to PCI device
7845 *
7846 * This callback is called when the error recovery driver tells us that
7847 * its OK to resume normal operation.
7848 */
7849static void ixgbe_io_resume(struct pci_dev *pdev)
7850{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007851 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7852 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007853
7854 if (netif_running(netdev)) {
7855 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007856 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007857 return;
7858 }
7859 }
7860
7861 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007862}
7863
7864static struct pci_error_handlers ixgbe_err_handler = {
7865 .error_detected = ixgbe_io_error_detected,
7866 .slot_reset = ixgbe_io_slot_reset,
7867 .resume = ixgbe_io_resume,
7868};
7869
7870static struct pci_driver ixgbe_driver = {
7871 .name = ixgbe_driver_name,
7872 .id_table = ixgbe_pci_tbl,
7873 .probe = ixgbe_probe,
7874 .remove = __devexit_p(ixgbe_remove),
7875#ifdef CONFIG_PM
7876 .suspend = ixgbe_suspend,
7877 .resume = ixgbe_resume,
7878#endif
7879 .shutdown = ixgbe_shutdown,
7880 .err_handler = &ixgbe_err_handler
7881};
7882
7883/**
7884 * ixgbe_init_module - Driver Registration Routine
7885 *
7886 * ixgbe_init_module is the first routine called when the driver is
7887 * loaded. All it does is register with the PCI subsystem.
7888 **/
7889static int __init ixgbe_init_module(void)
7890{
7891 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007892 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007893 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007894
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007895#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007896 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007897#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007898
Auke Kok9a799d72007-09-15 14:07:45 -07007899 ret = pci_register_driver(&ixgbe_driver);
7900 return ret;
7901}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007902
Auke Kok9a799d72007-09-15 14:07:45 -07007903module_init(ixgbe_init_module);
7904
7905/**
7906 * ixgbe_exit_module - Driver Exit Cleanup Routine
7907 *
7908 * ixgbe_exit_module is called just before the driver is removed
7909 * from memory.
7910 **/
7911static void __exit ixgbe_exit_module(void)
7912{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007913#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007914 dca_unregister_notify(&dca_notifier);
7915#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007916 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007917 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007918}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007919
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007920#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007921static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007922 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007923{
7924 int ret_val;
7925
7926 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007927 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007928
7929 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7930}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007931
Alexander Duyckb4533682009-03-31 21:32:42 +00007932#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007933
Auke Kok9a799d72007-09-15 14:07:45 -07007934module_exit(ixgbe_exit_module);
7935
7936/* ixgbe_main.c */