blob: faa83cea73318e08d282765e5766e9c393e6c8e4 [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>
Jiri Pirko01789342011-08-16 06:29:00 +000045#include <linux/if.h>
Auke Kok9a799d72007-09-15 14:07:45 -070046#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040047#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000048#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070049
50#include "ixgbe.h"
51#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000052#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000053#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070054
55char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070056static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000057 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000058#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000059#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000060#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000061#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000062 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070063const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000064static const char ixgbe_copyright[] =
65 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070066
67static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070068 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000069 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080070 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070071};
72
73/* ixgbe_pci_tbl - PCI Device ID Table
74 *
75 * Wildcard entries (PCI_ANY_ID) should come last
76 * Last entry must be all 0s
77 *
78 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
79 * Class, Class Mask, private data (not used) }
80 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000081static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080082 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
83 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070084 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070085 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070086 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070087 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070088 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
89 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000090 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
91 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070092 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070093 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070094 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
95 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080096 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
97 board_82598 },
98 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
99 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -0700100 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
101 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800102 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
103 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800104 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
105 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000106 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
107 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000108 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
109 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000110 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
111 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000112 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
113 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000114 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
115 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000116 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
117 board_82599 },
Peter P Waskiewicz Jr8911184f2009-09-14 07:47:49 +0000118 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
119 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000120 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
121 board_82599 },
122 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
123 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700124 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
125 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000126 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
127 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800128 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000129 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000130 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
131 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000132 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
133 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700134
135 /* required last entry */
136 {0, }
137};
138MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
139
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400140#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800141static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000142 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800143static struct notifier_block dca_notifier = {
144 .notifier_call = ixgbe_notify_dca,
145 .next = NULL,
146 .priority = 0
147};
148#endif
149
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000150#ifdef CONFIG_PCI_IOV
151static unsigned int max_vfs;
152module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000153MODULE_PARM_DESC(max_vfs,
154 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000155#endif /* CONFIG_PCI_IOV */
156
Auke Kok9a799d72007-09-15 14:07:45 -0700157MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
158MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
159MODULE_LICENSE("GPL");
160MODULE_VERSION(DRV_VERSION);
161
162#define DEFAULT_DEBUG_LEVEL_SHIFT 3
163
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000164static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
165{
166 struct ixgbe_hw *hw = &adapter->hw;
167 u32 gcr;
168 u32 gpie;
169 u32 vmdctl;
170
171#ifdef CONFIG_PCI_IOV
172 /* disable iov and allow time for transactions to clear */
173 pci_disable_sriov(adapter->pdev);
174#endif
175
176 /* turn off device IOV mode */
177 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
178 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
179 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
180 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
181 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
182 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
183
184 /* set default pool back to 0 */
185 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
186 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
187 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
Jesse Brandeburg945a5152011-07-20 00:56:21 +0000188 IXGBE_WRITE_FLUSH(hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000189
190 /* take a breather then clean up driver data */
191 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000192
193 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000194 adapter->vfinfo = NULL;
195
196 adapter->num_vfs = 0;
197 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
198}
199
Alexander Duyck70864002011-04-27 09:13:56 +0000200static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
201{
202 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
203 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
204 schedule_work(&adapter->service_task);
205}
206
207static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
208{
209 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
210
211 /* flush memory to make sure state is correct before next watchog */
212 smp_mb__before_clear_bit();
213 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
214}
215
Taku Izumidcd79ae2010-04-27 14:39:53 +0000216struct ixgbe_reg_info {
217 u32 ofs;
218 char *name;
219};
220
221static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
222
223 /* General Registers */
224 {IXGBE_CTRL, "CTRL"},
225 {IXGBE_STATUS, "STATUS"},
226 {IXGBE_CTRL_EXT, "CTRL_EXT"},
227
228 /* Interrupt Registers */
229 {IXGBE_EICR, "EICR"},
230
231 /* RX Registers */
232 {IXGBE_SRRCTL(0), "SRRCTL"},
233 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
234 {IXGBE_RDLEN(0), "RDLEN"},
235 {IXGBE_RDH(0), "RDH"},
236 {IXGBE_RDT(0), "RDT"},
237 {IXGBE_RXDCTL(0), "RXDCTL"},
238 {IXGBE_RDBAL(0), "RDBAL"},
239 {IXGBE_RDBAH(0), "RDBAH"},
240
241 /* TX Registers */
242 {IXGBE_TDBAL(0), "TDBAL"},
243 {IXGBE_TDBAH(0), "TDBAH"},
244 {IXGBE_TDLEN(0), "TDLEN"},
245 {IXGBE_TDH(0), "TDH"},
246 {IXGBE_TDT(0), "TDT"},
247 {IXGBE_TXDCTL(0), "TXDCTL"},
248
249 /* List Terminator */
250 {}
251};
252
253
254/*
255 * ixgbe_regdump - register printout routine
256 */
257static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
258{
259 int i = 0, j = 0;
260 char rname[16];
261 u32 regs[64];
262
263 switch (reginfo->ofs) {
264 case IXGBE_SRRCTL(0):
265 for (i = 0; i < 64; i++)
266 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
267 break;
268 case IXGBE_DCA_RXCTRL(0):
269 for (i = 0; i < 64; i++)
270 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
271 break;
272 case IXGBE_RDLEN(0):
273 for (i = 0; i < 64; i++)
274 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
275 break;
276 case IXGBE_RDH(0):
277 for (i = 0; i < 64; i++)
278 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
279 break;
280 case IXGBE_RDT(0):
281 for (i = 0; i < 64; i++)
282 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
283 break;
284 case IXGBE_RXDCTL(0):
285 for (i = 0; i < 64; i++)
286 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
287 break;
288 case IXGBE_RDBAL(0):
289 for (i = 0; i < 64; i++)
290 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
291 break;
292 case IXGBE_RDBAH(0):
293 for (i = 0; i < 64; i++)
294 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
295 break;
296 case IXGBE_TDBAL(0):
297 for (i = 0; i < 64; i++)
298 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
299 break;
300 case IXGBE_TDBAH(0):
301 for (i = 0; i < 64; i++)
302 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
303 break;
304 case IXGBE_TDLEN(0):
305 for (i = 0; i < 64; i++)
306 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
307 break;
308 case IXGBE_TDH(0):
309 for (i = 0; i < 64; i++)
310 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
311 break;
312 case IXGBE_TDT(0):
313 for (i = 0; i < 64; i++)
314 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
315 break;
316 case IXGBE_TXDCTL(0):
317 for (i = 0; i < 64; i++)
318 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
319 break;
320 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000321 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000322 IXGBE_READ_REG(hw, reginfo->ofs));
323 return;
324 }
325
326 for (i = 0; i < 8; i++) {
327 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000328 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000329 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000330 pr_cont(" %08x", regs[i*8+j]);
331 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000332 }
333
334}
335
336/*
337 * ixgbe_dump - Print registers, tx-rings and rx-rings
338 */
339static void ixgbe_dump(struct ixgbe_adapter *adapter)
340{
341 struct net_device *netdev = adapter->netdev;
342 struct ixgbe_hw *hw = &adapter->hw;
343 struct ixgbe_reg_info *reginfo;
344 int n = 0;
345 struct ixgbe_ring *tx_ring;
346 struct ixgbe_tx_buffer *tx_buffer_info;
347 union ixgbe_adv_tx_desc *tx_desc;
348 struct my_u0 { u64 a; u64 b; } *u0;
349 struct ixgbe_ring *rx_ring;
350 union ixgbe_adv_rx_desc *rx_desc;
351 struct ixgbe_rx_buffer *rx_buffer_info;
352 u32 staterr;
353 int i = 0;
354
355 if (!netif_msg_hw(adapter))
356 return;
357
358 /* Print netdevice Info */
359 if (netdev) {
360 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000363 pr_info("%-15s %016lX %016lX %016lX\n",
364 netdev->name,
365 netdev->state,
366 netdev->trans_start,
367 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000368 }
369
370 /* Print Registers */
371 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000372 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000373 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
374 reginfo->name; reginfo++) {
375 ixgbe_regdump(hw, reginfo);
376 }
377
378 /* Print TX Ring Summary */
379 if (!netdev || !netif_running(netdev))
380 goto exit;
381
382 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000383 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000384 for (n = 0; n < adapter->num_tx_queues; n++) {
385 tx_ring = adapter->tx_ring[n];
386 tx_buffer_info =
387 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000388 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000389 n, tx_ring->next_to_use, tx_ring->next_to_clean,
390 (u64)tx_buffer_info->dma,
391 tx_buffer_info->length,
392 tx_buffer_info->next_to_watch,
393 (u64)tx_buffer_info->time_stamp);
394 }
395
396 /* Print TX Rings */
397 if (!netif_msg_tx_done(adapter))
398 goto rx_ring_summary;
399
400 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
401
402 /* Transmit Descriptor Formats
403 *
404 * Advanced Transmit Descriptor
405 * +--------------------------------------------------------------+
406 * 0 | Buffer Address [63:0] |
407 * +--------------------------------------------------------------+
408 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
409 * +--------------------------------------------------------------+
410 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
411 */
412
413 for (n = 0; n < adapter->num_tx_queues; n++) {
414 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000415 pr_info("------------------------------------\n");
416 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
417 pr_info("------------------------------------\n");
418 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000419 "[PlPOIdStDDt Ln] [bi->dma ] "
420 "leng ntw timestamp bi->skb\n");
421
422 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000423 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000424 tx_buffer_info = &tx_ring->tx_buffer_info[i];
425 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000426 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000427 " %04X %3X %016llX %p", i,
428 le64_to_cpu(u0->a),
429 le64_to_cpu(u0->b),
430 (u64)tx_buffer_info->dma,
431 tx_buffer_info->length,
432 tx_buffer_info->next_to_watch,
433 (u64)tx_buffer_info->time_stamp,
434 tx_buffer_info->skb);
435 if (i == tx_ring->next_to_use &&
436 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000437 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000438 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000439 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000440 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000441 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442 else
Joe Perchesc7689572010-09-07 21:35:17 +0000443 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000444
445 if (netif_msg_pktdata(adapter) &&
446 tx_buffer_info->dma != 0)
447 print_hex_dump(KERN_INFO, "",
448 DUMP_PREFIX_ADDRESS, 16, 1,
449 phys_to_virt(tx_buffer_info->dma),
450 tx_buffer_info->length, true);
451 }
452 }
453
454 /* Print RX Rings Summary */
455rx_ring_summary:
456 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000457 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000458 for (n = 0; n < adapter->num_rx_queues; n++) {
459 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000460 pr_info("%5d %5X %5X\n",
461 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000462 }
463
464 /* Print RX Rings */
465 if (!netif_msg_rx_status(adapter))
466 goto exit;
467
468 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
469
470 /* Advanced Receive Descriptor (Read) Format
471 * 63 1 0
472 * +-----------------------------------------------------+
473 * 0 | Packet Buffer Address [63:1] |A0/NSE|
474 * +----------------------------------------------+------+
475 * 8 | Header Buffer Address [63:1] | DD |
476 * +-----------------------------------------------------+
477 *
478 *
479 * Advanced Receive Descriptor (Write-Back) Format
480 *
481 * 63 48 47 32 31 30 21 20 16 15 4 3 0
482 * +------------------------------------------------------+
483 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
484 * | Checksum Ident | | | | Type | Type |
485 * +------------------------------------------------------+
486 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
487 * +------------------------------------------------------+
488 * 63 48 47 32 31 20 19 0
489 */
490 for (n = 0; n < adapter->num_rx_queues; n++) {
491 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000492 pr_info("------------------------------------\n");
493 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
494 pr_info("------------------------------------\n");
495 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000496 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
497 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000498 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000499 "[vl er S cks ln] ---------------- [bi->skb] "
500 "<-- Adv Rx Write-Back format\n");
501
502 for (i = 0; i < rx_ring->count; i++) {
503 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000504 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000505 u0 = (struct my_u0 *)rx_desc;
506 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
507 if (staterr & IXGBE_RXD_STAT_DD) {
508 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000509 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000510 "%016llX ---------------- %p", i,
511 le64_to_cpu(u0->a),
512 le64_to_cpu(u0->b),
513 rx_buffer_info->skb);
514 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000515 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000516 "%016llX %016llX %p", i,
517 le64_to_cpu(u0->a),
518 le64_to_cpu(u0->b),
519 (u64)rx_buffer_info->dma,
520 rx_buffer_info->skb);
521
522 if (netif_msg_pktdata(adapter)) {
523 print_hex_dump(KERN_INFO, "",
524 DUMP_PREFIX_ADDRESS, 16, 1,
525 phys_to_virt(rx_buffer_info->dma),
526 rx_ring->rx_buf_len, true);
527
528 if (rx_ring->rx_buf_len
529 < IXGBE_RXBUFFER_2048)
530 print_hex_dump(KERN_INFO, "",
531 DUMP_PREFIX_ADDRESS, 16, 1,
532 phys_to_virt(
533 rx_buffer_info->page_dma +
534 rx_buffer_info->page_offset
535 ),
536 PAGE_SIZE/2, true);
537 }
538 }
539
540 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000543 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000544 else
Joe Perchesc7689572010-09-07 21:35:17 +0000545 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000546
547 }
548 }
549
550exit:
551 return;
552}
553
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800554static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
555{
556 u32 ctrl_ext;
557
558 /* Let firmware take over control of h/w */
559 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
560 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800562}
563
564static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
565{
566 u32 ctrl_ext;
567
568 /* Let firmware know the driver has taken over */
569 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
570 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000571 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800572}
Auke Kok9a799d72007-09-15 14:07:45 -0700573
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000574/*
575 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
576 * @adapter: pointer to adapter struct
577 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
578 * @queue: queue to map the corresponding interrupt to
579 * @msix_vector: the vector to map to the corresponding queue
580 *
581 */
582static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000583 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700584{
585 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000586 struct ixgbe_hw *hw = &adapter->hw;
587 switch (hw->mac.type) {
588 case ixgbe_mac_82598EB:
589 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
590 if (direction == -1)
591 direction = 0;
592 index = (((direction * 64) + queue) >> 2) & 0x1F;
593 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
594 ivar &= ~(0xFF << (8 * (queue & 0x3)));
595 ivar |= (msix_vector << (8 * (queue & 0x3)));
596 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
597 break;
598 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800599 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000600 if (direction == -1) {
601 /* other causes */
602 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
603 index = ((queue & 1) * 8);
604 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
605 ivar &= ~(0xFF << index);
606 ivar |= (msix_vector << index);
607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
608 break;
609 } else {
610 /* tx or rx causes */
611 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
612 index = ((16 * (queue & 1)) + (8 * direction));
613 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
614 ivar &= ~(0xFF << index);
615 ivar |= (msix_vector << index);
616 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
617 break;
618 }
619 default:
620 break;
621 }
Auke Kok9a799d72007-09-15 14:07:45 -0700622}
623
Alexander Duyckfe49f042009-06-04 16:00:09 +0000624static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000625 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000626{
627 u32 mask;
628
Alexander Duyckbd508172010-11-16 19:27:03 -0800629 switch (adapter->hw.mac.type) {
630 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000631 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
632 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800633 break;
634 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800635 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000636 mask = (qmask & 0xFFFFFFFF);
637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
638 mask = (qmask >> 32);
639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800640 break;
641 default:
642 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000643 }
644}
645
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800646void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
647 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700648{
Alexander Duycke5a43542009-12-02 16:46:56 +0000649 if (tx_buffer_info->dma) {
650 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800651 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000652 tx_buffer_info->dma,
653 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000654 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000655 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800656 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000657 tx_buffer_info->dma,
658 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000659 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000660 tx_buffer_info->dma = 0;
661 }
Auke Kok9a799d72007-09-15 14:07:45 -0700662 if (tx_buffer_info->skb) {
663 dev_kfree_skb_any(tx_buffer_info->skb);
664 tx_buffer_info->skb = NULL;
665 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000666 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700667 /* tx_buffer_info must be completely set up in the transmit path */
668}
669
John Fastabendc84d3242010-11-16 19:27:12 -0800670static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700671{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700672 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800673 struct ixgbe_hw_stats *hwstats = &adapter->stats;
674 u32 data = 0;
675 u32 xoff[8] = {0};
676 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700677
John Fastabendc84d3242010-11-16 19:27:12 -0800678 if ((hw->fc.current_mode == ixgbe_fc_full) ||
679 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
680 switch (hw->mac.type) {
681 case ixgbe_mac_82598EB:
682 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
683 break;
684 default:
685 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
686 }
687 hwstats->lxoffrxc += data;
688
689 /* refill credits (no tx hang) if we received xoff */
690 if (!data)
691 return;
692
693 for (i = 0; i < adapter->num_tx_queues; i++)
694 clear_bit(__IXGBE_HANG_CHECK_ARMED,
695 &adapter->tx_ring[i]->state);
696 return;
697 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
698 return;
699
700 /* update stats for each tc, only valid with PFC enabled */
701 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
702 switch (hw->mac.type) {
703 case ixgbe_mac_82598EB:
704 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
705 break;
706 default:
707 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
708 }
709 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700710 }
711
John Fastabendc84d3242010-11-16 19:27:12 -0800712 /* disarm tx queues that have received xoff frames */
713 for (i = 0; i < adapter->num_tx_queues; i++) {
714 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000715 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800716
717 if (xoff[tc])
718 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
719 }
720}
721
722static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
723{
724 return ring->tx_stats.completed;
725}
726
727static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
728{
729 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
730 struct ixgbe_hw *hw = &adapter->hw;
731
732 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
733 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
734
735 if (head != tail)
736 return (head < tail) ?
737 tail - head : (tail + ring->count - head);
738
739 return 0;
740}
741
742static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
743{
744 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
745 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
746 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
747 bool ret = false;
748
749 clear_check_for_tx_hang(tx_ring);
750
751 /*
752 * Check for a hung queue, but be thorough. This verifies
753 * that a transmit has been completed since the previous
754 * check AND there is at least one packet pending. The
755 * ARMED bit is set to indicate a potential hang. The
756 * bit is cleared if a pause frame is received to remove
757 * false hang detection due to PFC or 802.3x frames. By
758 * requiring this to fail twice we avoid races with
759 * pfc clearing the ARMED bit and conditions where we
760 * run the check_tx_hang logic with a transmit completion
761 * pending but without time to complete it yet.
762 */
763 if ((tx_done_old == tx_done) && tx_pending) {
764 /* make sure it is true for two checks in a row */
765 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
766 &tx_ring->state);
767 } else {
768 /* update completed stats and continue */
769 tx_ring->tx_stats.tx_done_old = tx_done;
770 /* reset the countdown */
771 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
772 }
773
774 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700775}
776
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000777/**
778 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
779 * @adapter: driver private struct
780 **/
781static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
782{
783
784 /* Do the reset outside of interrupt context */
785 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
786 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
787 ixgbe_service_event_schedule(adapter);
788 }
789}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700790
Auke Kok9a799d72007-09-15 14:07:45 -0700791/**
792 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000793 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700794 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700795 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000796static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000797 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700798{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000799 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800800 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
801 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700802 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800803 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700804
805 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800806 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000807 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800808
809 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Alexander Duyckbd198052011-06-11 01:45:08 +0000810 (count < q_vector->tx.work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800811 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000812 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800813 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000814 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700815 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700816
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800817 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800818 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800819
Auke Kok9a799d72007-09-15 14:07:45 -0700820 i++;
821 if (i == tx_ring->count)
822 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800823
824 if (cleaned && tx_buffer_info->skb) {
825 total_bytes += tx_buffer_info->bytecount;
826 total_packets += tx_buffer_info->gso_segs;
827 }
828
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800829 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800830 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700831 }
832
John Fastabendc84d3242010-11-16 19:27:12 -0800833 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800834 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000835 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800836 }
837
Auke Kok9a799d72007-09-15 14:07:45 -0700838 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800839 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000840 tx_ring->stats.packets += total_packets;
841 u64_stats_update_begin(&tx_ring->syncp);
842 q_vector->tx.total_bytes += total_bytes;
843 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800844 u64_stats_update_end(&tx_ring->syncp);
845
John Fastabendc84d3242010-11-16 19:27:12 -0800846 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800847 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800848 struct ixgbe_hw *hw = &adapter->hw;
849 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
850 e_err(drv, "Detected Tx Unit Hang\n"
851 " Tx Queue <%d>\n"
852 " TDH, TDT <%x>, <%x>\n"
853 " next_to_use <%x>\n"
854 " next_to_clean <%x>\n"
855 "tx_buffer_info[next_to_clean]\n"
856 " time_stamp <%lx>\n"
857 " jiffies <%lx>\n",
858 tx_ring->queue_index,
859 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
860 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
861 tx_ring->next_to_use, eop,
862 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
863
864 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
865
866 e_info(probe,
867 "tx hang %d detected on queue %d, resetting adapter\n",
868 adapter->tx_timeout_count + 1, tx_ring->queue_index);
869
870 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000871 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800872
873 /* the adapter is about to reset, no point in enabling stuff */
874 return true;
875 }
Auke Kok9a799d72007-09-15 14:07:45 -0700876
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800877#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800878 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000879 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800880 /* Make sure that anybody stopping the queue after this
881 * sees the new next_to_clean.
882 */
883 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800884 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800885 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800886 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800887 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800888 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800889 }
Auke Kok9a799d72007-09-15 14:07:45 -0700890
Alexander Duyckbd198052011-06-11 01:45:08 +0000891 return count < q_vector->tx.work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700892}
893
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400894#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800895static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800896 struct ixgbe_ring *rx_ring,
897 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800898{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800899 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800900 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800901 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800902
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800903 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
904 switch (hw->mac.type) {
905 case ixgbe_mac_82598EB:
906 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
907 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
908 break;
909 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800910 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800911 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
912 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
913 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
914 break;
915 default:
916 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800917 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800918 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
919 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
920 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800921 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800922}
923
924static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925 struct ixgbe_ring *tx_ring,
926 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800927{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000928 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800929 u32 txctrl;
930 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800931
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932 switch (hw->mac.type) {
933 case ixgbe_mac_82598EB:
934 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
935 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
936 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
937 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800938 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
939 break;
940 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800941 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800942 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
943 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
944 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
945 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
946 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800947 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
948 break;
949 default:
950 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800951 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800952}
953
954static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
955{
956 struct ixgbe_adapter *adapter = q_vector->adapter;
957 int cpu = get_cpu();
958 long r_idx;
959 int i;
960
961 if (q_vector->cpu == cpu)
962 goto out_no_update;
963
Alexander Duyck08c88332011-06-11 01:45:03 +0000964 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
965 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800966 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000967 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 r_idx + 1);
969 }
970
Alexander Duyck08c88332011-06-11 01:45:03 +0000971 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
972 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800973 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000974 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800975 r_idx + 1);
976 }
977
978 q_vector->cpu = cpu;
979out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800980 put_cpu();
981}
982
983static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
984{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800985 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800986 int i;
987
988 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
989 return;
990
Alexander Duycke35ec122009-05-21 13:07:12 +0000991 /* always use CB2 mode, difference is masked in the CB driver */
992 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
993
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800994 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
995 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
996 else
997 num_q_vectors = 1;
998
999 for (i = 0; i < num_q_vectors; i++) {
1000 adapter->q_vector[i]->cpu = -1;
1001 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001002 }
1003}
1004
1005static int __ixgbe_notify_dca(struct device *dev, void *data)
1006{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001007 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001008 unsigned long event = *(unsigned long *)data;
1009
Don Skidmore2a72c312011-07-20 02:27:05 +00001010 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001011 return 0;
1012
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001013 switch (event) {
1014 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001015 /* if we're already enabled, don't do it again */
1016 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1017 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001018 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001019 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001020 ixgbe_setup_dca(adapter);
1021 break;
1022 }
1023 /* Fall Through since DCA is disabled. */
1024 case DCA_PROVIDER_REMOVE:
1025 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1026 dca_remove_requester(dev);
1027 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1028 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1029 }
1030 break;
1031 }
1032
Denis V. Lunev652f0932008-03-27 14:39:17 +03001033 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001034}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001035#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001036
1037static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1038 struct sk_buff *skb)
1039{
1040 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1041}
1042
Auke Kok9a799d72007-09-15 14:07:45 -07001043/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001044 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1045 * @adapter: address of board private structure
1046 * @rx_desc: advanced rx descriptor
1047 *
1048 * Returns : true if it is FCoE pkt
1049 */
1050static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1051 union ixgbe_adv_rx_desc *rx_desc)
1052{
1053 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1054
1055 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1056 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1057 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1058 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1059}
1060
1061/**
Auke Kok9a799d72007-09-15 14:07:45 -07001062 * ixgbe_receive_skb - Send a completed packet up the stack
1063 * @adapter: board private structure
1064 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001065 * @status: hardware indication of status of receive
1066 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1067 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001068 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001069static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001070 struct sk_buff *skb, u8 status,
1071 struct ixgbe_ring *ring,
1072 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001073{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001074 struct ixgbe_adapter *adapter = q_vector->adapter;
1075 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001076 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1077 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001078
Jesse Grossf62bbb52010-10-20 13:56:10 +00001079 if (is_vlan && (tag & VLAN_VID_MASK))
1080 __vlan_hwaccel_put_tag(skb, tag);
1081
1082 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1083 napi_gro_receive(napi, skb);
1084 else
1085 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001086}
1087
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001088/**
1089 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1090 * @adapter: address of board private structure
1091 * @status_err: hardware indication of status of receive
1092 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001093 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001094 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001095static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001096 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001097 struct sk_buff *skb,
1098 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001099{
Alexander Duyckff886df2011-06-11 01:45:13 +00001100 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001101
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001102 /* Rx csum disabled */
1103 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001104 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001105
1106 /* if IP and error */
1107 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1108 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001109 adapter->hw_csum_rx_error++;
1110 return;
1111 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001112
1113 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1114 return;
1115
1116 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001117 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1118
1119 /*
1120 * 82599 errata, UDP frames with a 0 checksum can be marked as
1121 * checksum errors.
1122 */
1123 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1124 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1125 return;
1126
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001127 adapter->hw_csum_rx_error++;
1128 return;
1129 }
1130
Auke Kok9a799d72007-09-15 14:07:45 -07001131 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001132 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001133}
1134
Alexander Duyck84ea2592010-11-16 19:26:49 -08001135static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001136{
1137 /*
1138 * Force memory writes to complete before letting h/w
1139 * know there are new descriptors to fetch. (Only
1140 * applicable for weak-ordered memory model archs,
1141 * such as IA-64).
1142 */
1143 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001144 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001145}
1146
Auke Kok9a799d72007-09-15 14:07:45 -07001147/**
1148 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001149 * @rx_ring: ring to place buffers on
1150 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001151 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001152void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001153{
Auke Kok9a799d72007-09-15 14:07:45 -07001154 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001155 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001156 struct sk_buff *skb;
1157 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001158
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001159 /* do nothing if no valid netdev defined */
1160 if (!rx_ring->netdev)
1161 return;
1162
Auke Kok9a799d72007-09-15 14:07:45 -07001163 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001164 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001165 bi = &rx_ring->rx_buffer_info[i];
1166 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001167
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001168 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001169 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001170 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001171 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001172 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001173 goto no_buffers;
1174 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001175 /* initialize queue mapping */
1176 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001177 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001178 }
Auke Kok9a799d72007-09-15 14:07:45 -07001179
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001180 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001181 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001182 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001183 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001184 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001185 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001186 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001187 bi->dma = 0;
1188 goto no_buffers;
1189 }
Auke Kok9a799d72007-09-15 14:07:45 -07001190 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001191
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001192 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001193 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001194 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001195 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001196 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001197 goto no_buffers;
1198 }
1199 }
1200
1201 if (!bi->page_dma) {
1202 /* use a half page if we're re-using */
1203 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001204 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001205 bi->page,
1206 bi->page_offset,
1207 PAGE_SIZE / 2,
1208 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001209 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001210 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001211 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001212 bi->page_dma = 0;
1213 goto no_buffers;
1214 }
1215 }
1216
1217 /* Refresh the desc even if buffer_addrs didn't change
1218 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001219 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1220 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001221 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001222 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001223 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001224 }
1225
1226 i++;
1227 if (i == rx_ring->count)
1228 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001229 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001230
Auke Kok9a799d72007-09-15 14:07:45 -07001231no_buffers:
1232 if (rx_ring->next_to_use != i) {
1233 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001234 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001235 }
1236}
1237
Alexander Duyckc267fc12010-11-16 19:27:00 -08001238static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001239{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001240 /* HW will not DMA in data larger than the given buffer, even if it
1241 * parses the (NFS, of course) header to be larger. In that case, it
1242 * fills the header buffer and spills the rest into the page.
1243 */
1244 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1245 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1246 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1247 if (hlen > IXGBE_RX_HDR_SIZE)
1248 hlen = IXGBE_RX_HDR_SIZE;
1249 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001250}
1251
Alexander Duyckf8212f92009-04-27 22:42:37 +00001252/**
1253 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1254 * @skb: pointer to the last skb in the rsc queue
1255 *
1256 * This function changes a queue full of hw rsc buffers into a completed
1257 * packet. It uses the ->prev pointers to find the first packet and then
1258 * turns it into the frag list owner.
1259 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001260static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001261{
1262 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001263 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001264
1265 while (skb->prev) {
1266 struct sk_buff *prev = skb->prev;
1267 frag_list_size += skb->len;
1268 skb->prev = NULL;
1269 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001270 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001271 }
1272
1273 skb_shinfo(skb)->frag_list = skb->next;
1274 skb->next = NULL;
1275 skb->len += frag_list_size;
1276 skb->data_len += frag_list_size;
1277 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001278 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1279
Alexander Duyckf8212f92009-04-27 22:42:37 +00001280 return skb;
1281}
1282
Alexander Duyckaa801752010-11-16 19:27:02 -08001283static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1284{
1285 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1286 IXGBE_RXDADV_RSCCNT_MASK);
1287}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001288
Alexander Duyckc267fc12010-11-16 19:27:00 -08001289static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001290 struct ixgbe_ring *rx_ring,
1291 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001292{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001293 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001294 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1295 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1296 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001297 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001298 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001299#ifdef IXGBE_FCOE
1300 int ddp_bytes = 0;
1301#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001302 u32 staterr;
1303 u16 i;
1304 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001305 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001306
1307 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001308 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001309 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001310
1311 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001312 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001313
Milton Miller3c945e52010-02-19 17:44:42 +00001314 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001315
Alexander Duyckc267fc12010-11-16 19:27:00 -08001316 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1317
Auke Kok9a799d72007-09-15 14:07:45 -07001318 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001319 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001320 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001321
Alexander Duyckc267fc12010-11-16 19:27:00 -08001322 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001323 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001324
1325 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001326 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001327 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001328 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001329 !(staterr & IXGBE_RXD_STAT_EOP) &&
1330 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001331 /*
1332 * When HWRSC is enabled, delay unmapping
1333 * of the first packet. It carries the
1334 * header information, HW may still
1335 * access the header after the writeback.
1336 * Only unmap it when EOP is reached
1337 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001338 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001339 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001340 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001341 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001342 rx_buffer_info->dma,
1343 rx_ring->rx_buf_len,
1344 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001345 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001346 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001347
1348 if (ring_is_ps_enabled(rx_ring)) {
1349 hlen = ixgbe_get_hlen(rx_desc);
1350 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1351 } else {
1352 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1353 }
1354
1355 skb_put(skb, hlen);
1356 } else {
1357 /* assume packet split since header is unmapped */
1358 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001359 }
1360
1361 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001362 dma_unmap_page(rx_ring->dev,
1363 rx_buffer_info->page_dma,
1364 PAGE_SIZE / 2,
1365 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001366 rx_buffer_info->page_dma = 0;
1367 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001368 rx_buffer_info->page,
1369 rx_buffer_info->page_offset,
1370 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001371
Alexander Duyckc267fc12010-11-16 19:27:00 -08001372 if ((page_count(rx_buffer_info->page) == 1) &&
1373 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001374 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001375 else
1376 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001377
1378 skb->len += upper_len;
1379 skb->data_len += upper_len;
1380 skb->truesize += upper_len;
1381 }
1382
1383 i++;
1384 if (i == rx_ring->count)
1385 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001386
Alexander Duyck31f05a22010-08-19 13:40:31 +00001387 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001388 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001389 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001390
Alexander Duyckaa801752010-11-16 19:27:02 -08001391 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001392 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1393 IXGBE_RXDADV_NEXTP_SHIFT;
1394 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001395 } else {
1396 next_buffer = &rx_ring->rx_buffer_info[i];
1397 }
1398
Alexander Duyckc267fc12010-11-16 19:27:00 -08001399 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001400 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001401 rx_buffer_info->skb = next_buffer->skb;
1402 rx_buffer_info->dma = next_buffer->dma;
1403 next_buffer->skb = skb;
1404 next_buffer->dma = 0;
1405 } else {
1406 skb->next = next_buffer->skb;
1407 skb->next->prev = skb;
1408 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001409 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001410 goto next_desc;
1411 }
1412
Alexander Duyckaa801752010-11-16 19:27:02 -08001413 if (skb->prev) {
1414 skb = ixgbe_transform_rsc_queue(skb);
1415 /* if we got here without RSC the packet is invalid */
1416 if (!pkt_is_rsc) {
1417 __pskb_trim(skb, 0);
1418 rx_buffer_info->skb = skb;
1419 goto next_desc;
1420 }
1421 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001422
1423 if (ring_is_rsc_enabled(rx_ring)) {
1424 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1425 dma_unmap_single(rx_ring->dev,
1426 IXGBE_RSC_CB(skb)->dma,
1427 rx_ring->rx_buf_len,
1428 DMA_FROM_DEVICE);
1429 IXGBE_RSC_CB(skb)->dma = 0;
1430 IXGBE_RSC_CB(skb)->delay_unmap = false;
1431 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001432 }
1433 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001434 if (ring_is_ps_enabled(rx_ring))
1435 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001436 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001437 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001438 rx_ring->rx_stats.rsc_count +=
1439 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001440 rx_ring->rx_stats.rsc_flush++;
1441 }
1442
1443 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001444 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1445 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001446 goto next_desc;
1447 }
1448
Alexander Duyckff886df2011-06-11 01:45:13 +00001449 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001450 if (adapter->netdev->features & NETIF_F_RXHASH)
1451 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001452
1453 /* probably a little skewed due to removing CRC */
1454 total_rx_bytes += skb->len;
1455 total_rx_packets++;
1456
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001457 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001458#ifdef IXGBE_FCOE
1459 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001460 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1461 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1462 staterr);
Yi Zou3d8fd382009-06-08 14:38:44 +00001463 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001464 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001465 }
Yi Zou332d4a72009-05-13 13:11:53 +00001466#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001467 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001468
1469next_desc:
1470 rx_desc->wb.upper.status_error = 0;
1471
Alexander Duyckc267fc12010-11-16 19:27:00 -08001472 (*work_done)++;
1473 if (*work_done >= work_to_do)
1474 break;
1475
Auke Kok9a799d72007-09-15 14:07:45 -07001476 /* return some buffers to hardware, one at a time is too slow */
1477 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001478 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001479 cleaned_count = 0;
1480 }
1481
1482 /* use prefetched values */
1483 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001484 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001485 }
1486
Auke Kok9a799d72007-09-15 14:07:45 -07001487 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001488 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001489
1490 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001491 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001492
Yi Zou3d8fd382009-06-08 14:38:44 +00001493#ifdef IXGBE_FCOE
1494 /* include DDPed FCoE data */
1495 if (ddp_bytes > 0) {
1496 unsigned int mss;
1497
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001498 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001499 sizeof(struct fc_frame_header) -
1500 sizeof(struct fcoe_crc_eof);
1501 if (mss > 512)
1502 mss &= ~511;
1503 total_rx_bytes += ddp_bytes;
1504 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1505 }
1506#endif /* IXGBE_FCOE */
1507
Alexander Duyckc267fc12010-11-16 19:27:00 -08001508 u64_stats_update_begin(&rx_ring->syncp);
1509 rx_ring->stats.packets += total_rx_packets;
1510 rx_ring->stats.bytes += total_rx_bytes;
1511 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001512 q_vector->rx.total_packets += total_rx_packets;
1513 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001514}
1515
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001516static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001517/**
1518 * ixgbe_configure_msix - Configure MSI-X hardware
1519 * @adapter: board private structure
1520 *
1521 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1522 * interrupts.
1523 **/
1524static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1525{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001526 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001527 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001528 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001529
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001530 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1531
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001532 /*
1533 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001534 * corresponding register.
1535 */
1536 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001537 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001538 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001539 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001540 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001541
Alexander Duyck08c88332011-06-11 01:45:03 +00001542 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001543 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1544 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001545 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001546 adapter->num_rx_queues,
1547 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001549 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001550 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001551
Alexander Duyck08c88332011-06-11 01:45:03 +00001552 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001553 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1554 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001555 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001556 adapter->num_tx_queues,
1557 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001558 }
1559
Alexander Duyck08c88332011-06-11 01:45:03 +00001560 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001561 /* tx only */
1562 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001563 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001564 /* rx or mixed */
1565 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001566
Alexander Duyckfe49f042009-06-04 16:00:09 +00001567 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001568 /* If ATR is enabled, set interrupt affinity */
1569 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001570 /*
1571 * Allocate the affinity_hint cpumask, assign the mask
1572 * for this vector, and set our affinity_hint for
1573 * this irq.
1574 */
1575 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1576 GFP_KERNEL))
1577 return;
1578 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1579 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1580 q_vector->affinity_mask);
1581 }
Auke Kok9a799d72007-09-15 14:07:45 -07001582 }
1583
Alexander Duyckbd508172010-11-16 19:27:03 -08001584 switch (adapter->hw.mac.type) {
1585 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001586 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001587 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001588 break;
1589 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001590 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001591 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001592 break;
1593
1594 default:
1595 break;
1596 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001597 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001598
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001599 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001600 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001601 if (adapter->num_vfs)
1602 mask &= ~(IXGBE_EIMS_OTHER |
1603 IXGBE_EIMS_MAILBOX |
1604 IXGBE_EIMS_LSC);
1605 else
1606 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001607 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001608}
1609
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001610enum latency_range {
1611 lowest_latency = 0,
1612 low_latency = 1,
1613 bulk_latency = 2,
1614 latency_invalid = 255
1615};
1616
1617/**
1618 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001619 * @q_vector: structure containing interrupt and ring information
1620 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001621 *
1622 * Stores a new ITR value based on packets and byte
1623 * counts during the last interrupt. The advantage of per interrupt
1624 * computation is faster updates and more accurate ITR for the current
1625 * traffic pattern. Constants in this function were computed
1626 * based on theoretical maximum wire speed and thresholds were set based
1627 * on testing data as well as attempting to minimize response time
1628 * while increasing bulk throughput.
1629 * this functionality is controlled by the InterruptThrottleRate module
1630 * parameter (see ixgbe_param.c)
1631 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001632static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1633 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001634{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001635 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001636 struct ixgbe_adapter *adapter = q_vector->adapter;
1637 int bytes = ring_container->total_bytes;
1638 int packets = ring_container->total_packets;
1639 u32 timepassed_us;
1640 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001641
1642 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001643 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001644
1645 /* simple throttlerate management
1646 * 0-20MB/s lowest (100000 ints/s)
1647 * 20-100MB/s low (20000 ints/s)
1648 * 100-1249MB/s bulk (8000 ints/s)
1649 */
1650 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001651 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001652 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1653
1654 switch (itr_setting) {
1655 case lowest_latency:
1656 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001657 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001658 break;
1659 case low_latency:
1660 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001661 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001662 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001663 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001664 break;
1665 case bulk_latency:
1666 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001667 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001668 break;
1669 }
1670
Alexander Duyckbd198052011-06-11 01:45:08 +00001671 /* clear work counters since we have the values we need */
1672 ring_container->total_bytes = 0;
1673 ring_container->total_packets = 0;
1674
1675 /* write updated itr to ring container */
1676 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001677}
1678
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001679/**
1680 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001681 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001682 *
1683 * This function is made to be called by ethtool and by the driver
1684 * when it needs to update EITR registers at runtime. Hardware
1685 * specific quirks/differences are taken care of here.
1686 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001687void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001688{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001689 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001690 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001691 int v_idx = q_vector->v_idx;
1692 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1693
Alexander Duyckbd508172010-11-16 19:27:03 -08001694 switch (adapter->hw.mac.type) {
1695 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001696 /* must write high and low 16 bits to reset counter */
1697 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001698 break;
1699 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001700 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001701 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001702 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001703 * max interrupt rate, but there is an errata where it can
1704 * not be zero with RSC
1705 */
1706 if (itr_reg == 8 &&
1707 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1708 itr_reg = 0;
1709
1710 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001711 * set the WDIS bit to not clear the timer bits and cause an
1712 * immediate assertion of the interrupt
1713 */
1714 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001715 break;
1716 default:
1717 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001718 }
1719 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1720}
1721
Alexander Duyckbd198052011-06-11 01:45:08 +00001722static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001723{
Alexander Duyckbd198052011-06-11 01:45:08 +00001724 u32 new_itr = q_vector->eitr;
1725 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001726
Alexander Duyckbd198052011-06-11 01:45:08 +00001727 ixgbe_update_itr(q_vector, &q_vector->tx);
1728 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001729
Alexander Duyck08c88332011-06-11 01:45:03 +00001730 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001731
1732 switch (current_itr) {
1733 /* counts and packets in update_itr are dependent on these numbers */
1734 case lowest_latency:
1735 new_itr = 100000;
1736 break;
1737 case low_latency:
1738 new_itr = 20000; /* aka hwitr = ~200 */
1739 break;
1740 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001741 new_itr = 8000;
1742 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001743 default:
1744 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001745 }
1746
1747 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001748 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001749 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001750
Alexander Duyckbd198052011-06-11 01:45:08 +00001751 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001752 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001753
1754 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001755 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001756}
1757
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001758/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001759 * ixgbe_check_overtemp_subtask - check for over tempurature
1760 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001761 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001762static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001763{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001764 struct ixgbe_hw *hw = &adapter->hw;
1765 u32 eicr = adapter->interrupt_event;
1766
Alexander Duyckf0f97782011-04-22 04:08:09 +00001767 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001768 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001769
Alexander Duyckf0f97782011-04-22 04:08:09 +00001770 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1771 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1772 return;
1773
1774 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1775
Joe Perches7ca647b2010-09-07 21:35:40 +00001776 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001777 case IXGBE_DEV_ID_82599_T3_LOM:
1778 /*
1779 * Since the warning interrupt is for both ports
1780 * we don't have to check if:
1781 * - This interrupt wasn't for our port.
1782 * - We may have missed the interrupt so always have to
1783 * check if we got a LSC
1784 */
1785 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1786 !(eicr & IXGBE_EICR_LSC))
1787 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001788
Alexander Duyckf0f97782011-04-22 04:08:09 +00001789 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1790 u32 autoneg;
1791 bool link_up = false;
1792
Joe Perches7ca647b2010-09-07 21:35:40 +00001793 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1794
Alexander Duyckf0f97782011-04-22 04:08:09 +00001795 if (link_up)
1796 return;
1797 }
1798
1799 /* Check if this is not due to overtemp */
1800 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1801 return;
1802
1803 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001804 default:
1805 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1806 return;
1807 break;
1808 }
1809 e_crit(drv,
1810 "Network adapter has been stopped because it has over heated. "
1811 "Restart the computer. If the problem persists, "
1812 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001813
1814 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001815}
1816
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001817static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1818{
1819 struct ixgbe_hw *hw = &adapter->hw;
1820
1821 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1822 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001823 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001824 /* write to clear the interrupt */
1825 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1826 }
1827}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001828
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001829static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1830{
1831 struct ixgbe_hw *hw = &adapter->hw;
1832
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001833 if (eicr & IXGBE_EICR_GPI_SDP2) {
1834 /* Clear the interrupt */
1835 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001836 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1837 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1838 ixgbe_service_event_schedule(adapter);
1839 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001840 }
1841
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001842 if (eicr & IXGBE_EICR_GPI_SDP1) {
1843 /* Clear the interrupt */
1844 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001845 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1846 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1847 ixgbe_service_event_schedule(adapter);
1848 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001849 }
1850}
1851
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001852static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1853{
1854 struct ixgbe_hw *hw = &adapter->hw;
1855
1856 adapter->lsc_int++;
1857 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1858 adapter->link_check_timeout = jiffies;
1859 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1860 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001861 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001862 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001863 }
1864}
1865
Auke Kok9a799d72007-09-15 14:07:45 -07001866static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1867{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001868 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001869 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001870 u32 eicr;
1871
1872 /*
1873 * Workaround for Silicon errata. Use clear-by-write instead
1874 * of clear-by-read. Reading with EICS will return the
1875 * interrupt causes without clearing, which later be done
1876 * with the write to EICR.
1877 */
1878 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1879 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001880
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001881 if (eicr & IXGBE_EICR_LSC)
1882 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001883
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001884 if (eicr & IXGBE_EICR_MAILBOX)
1885 ixgbe_msg_task(adapter);
1886
Alexander Duyckbd508172010-11-16 19:27:03 -08001887 switch (hw->mac.type) {
1888 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001889 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001890 /* Handle Flow Director Full threshold interrupt */
1891 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001892 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001893 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001894 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001895 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001896 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001897 &ring->state))
1898 reinit_count++;
1899 }
1900 if (reinit_count) {
1901 /* no more flow director interrupts until after init */
1902 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1903 eicr &= ~IXGBE_EICR_FLOW_DIR;
1904 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1905 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001906 }
1907 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001908 ixgbe_check_sfp_event(adapter, eicr);
1909 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1910 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1911 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1912 adapter->interrupt_event = eicr;
1913 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1914 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001915 }
1916 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001917 break;
1918 default:
1919 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001920 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001921
1922 ixgbe_check_fan_failure(adapter, eicr);
1923
Alexander Duyck70864002011-04-27 09:13:56 +00001924 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001925 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001926 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1927 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001928
1929 return IRQ_HANDLED;
1930}
1931
Alexander Duyckfe49f042009-06-04 16:00:09 +00001932static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1933 u64 qmask)
1934{
1935 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001936 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001937
Alexander Duyckbd508172010-11-16 19:27:03 -08001938 switch (hw->mac.type) {
1939 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001940 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001941 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1942 break;
1943 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001944 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001945 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001946 if (mask)
1947 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001948 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001949 if (mask)
1950 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1951 break;
1952 default:
1953 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001954 }
1955 /* skip the flush */
1956}
1957
1958static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001959 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001960{
1961 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001962 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001963
Alexander Duyckbd508172010-11-16 19:27:03 -08001964 switch (hw->mac.type) {
1965 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001966 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001967 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1968 break;
1969 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001970 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001971 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001972 if (mask)
1973 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001974 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001975 if (mask)
1976 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1977 break;
1978 default:
1979 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001980 }
1981 /* skip the flush */
1982}
1983
Auke Kok9a799d72007-09-15 14:07:45 -07001984static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1985{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001986 struct ixgbe_q_vector *q_vector = data;
1987 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001988 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001989 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001990
Alexander Duyck08c88332011-06-11 01:45:03 +00001991 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001992 return IRQ_HANDLED;
1993
Alexander Duyck08c88332011-06-11 01:45:03 +00001994 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
1995 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00001996 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00001997 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001998 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001999 }
2000
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002001 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002002 napi_schedule(&q_vector->napi);
2003
Auke Kok9a799d72007-09-15 14:07:45 -07002004 return IRQ_HANDLED;
2005}
2006
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002007/**
2008 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2009 * @irq: unused
2010 * @data: pointer to our q_vector struct for this interrupt vector
2011 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002012static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2013{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002014 struct ixgbe_q_vector *q_vector = data;
2015 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002016 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002017 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002018 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002019
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002020#ifdef CONFIG_IXGBE_DCA
2021 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2022 ixgbe_update_dca(q_vector);
2023#endif
2024
Alexander Duyck08c88332011-06-11 01:45:03 +00002025 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2026 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002027 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002028 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002029 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002030 }
2031
Alexander Duyck08c88332011-06-11 01:45:03 +00002032 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002033 return IRQ_HANDLED;
2034
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002035 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002036 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002037
Auke Kok9a799d72007-09-15 14:07:45 -07002038 return IRQ_HANDLED;
2039}
2040
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002041static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2042{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002043 struct ixgbe_q_vector *q_vector = data;
2044 struct ixgbe_adapter *adapter = q_vector->adapter;
2045 struct ixgbe_ring *ring;
2046 int r_idx;
2047 int i;
2048
Alexander Duyck08c88332011-06-11 01:45:03 +00002049 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002050 return IRQ_HANDLED;
2051
Alexander Duyck08c88332011-06-11 01:45:03 +00002052 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2053 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002054 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002055 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002056 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002057 }
2058
Alexander Duyck08c88332011-06-11 01:45:03 +00002059 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2060 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002061 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002062 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002063 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002064 }
2065
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002066 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002067 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002068
2069 return IRQ_HANDLED;
2070}
2071
2072/**
2073 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2074 * @napi: napi struct with our devices info in it
2075 * @budget: amount of work driver is allowed to do this pass, in packets
2076 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002077 * This function is optimized for cleaning one queue only on a single
2078 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002079 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002080static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2081{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002082 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002083 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002084 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002085 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002086 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002087 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002088
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002089#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002090 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002091 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002092#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002093
Alexander Duyck08c88332011-06-11 01:45:03 +00002094 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002095 rx_ring = adapter->rx_ring[r_idx];
2096
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002097 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002098
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002099 /* If all Rx work done, exit the polling mode */
2100 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002101 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002102 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002103 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002104 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002105 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002106 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002107 }
2108
2109 return work_done;
2110}
2111
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002112/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002113 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002114 * @napi: napi struct with our devices info in it
2115 * @budget: amount of work driver is allowed to do this pass, in packets
2116 *
2117 * This function will clean more than one rx queue associated with a
2118 * q_vector.
2119 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002120static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002121{
2122 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002123 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002124 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002125 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002126 int work_done = 0, i;
2127 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002128 bool tx_clean_complete = true;
2129
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002130#ifdef CONFIG_IXGBE_DCA
2131 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2132 ixgbe_update_dca(q_vector);
2133#endif
2134
Alexander Duyck08c88332011-06-11 01:45:03 +00002135 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2136 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002137 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002138 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002139 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002140 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002141 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002142
2143 /* attempt to distribute budget to each queue fairly, but don't allow
2144 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002145 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002146 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002147 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2148 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002149 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002150 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002151 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002152 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002153 }
2154
Alexander Duyck08c88332011-06-11 01:45:03 +00002155 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002156 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002157 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002158 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002159 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002160 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002161 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002162 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002163 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002164 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002165 return 0;
2166 }
2167
2168 return work_done;
2169}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002170
2171/**
2172 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2173 * @napi: napi struct with our devices info in it
2174 * @budget: amount of work driver is allowed to do this pass, in packets
2175 *
2176 * This function is optimized for cleaning one queue only on a single
2177 * q_vector!!!
2178 **/
2179static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2180{
2181 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002182 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002183 struct ixgbe_adapter *adapter = q_vector->adapter;
2184 struct ixgbe_ring *tx_ring = NULL;
2185 int work_done = 0;
2186 long r_idx;
2187
Alexander Duyck91281fd2009-06-04 16:00:27 +00002188#ifdef CONFIG_IXGBE_DCA
2189 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002190 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002191#endif
2192
Alexander Duyck08c88332011-06-11 01:45:03 +00002193 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002194 tx_ring = adapter->tx_ring[r_idx];
2195
Alexander Duyck91281fd2009-06-04 16:00:27 +00002196 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2197 work_done = budget;
2198
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002199 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002200 if (work_done < budget) {
2201 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002202 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002203 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002204 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002205 ixgbe_irq_enable_queues(adapter,
2206 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002207 }
2208
2209 return work_done;
2210}
2211
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002212static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002213 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002214{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002215 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002216 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002217
Alexander Duyck08c88332011-06-11 01:45:03 +00002218 set_bit(r_idx, q_vector->rx.idx);
2219 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002220 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002221}
Auke Kok9a799d72007-09-15 14:07:45 -07002222
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002223static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002224 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002225{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002226 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002227 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002228
Alexander Duyck08c88332011-06-11 01:45:03 +00002229 set_bit(t_idx, q_vector->tx.idx);
2230 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002231 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002232 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002233}
Auke Kok9a799d72007-09-15 14:07:45 -07002234
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002235/**
2236 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2237 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002238 *
2239 * This function maps descriptor rings to the queue-specific vectors
2240 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2241 * one vector per ring/queue, but on a constrained vector budget, we
2242 * group the rings as "efficiently" as possible. You would add new
2243 * mapping configurations in here.
2244 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002245static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002247 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002248 int v_start = 0;
2249 int rxr_idx = 0, txr_idx = 0;
2250 int rxr_remaining = adapter->num_rx_queues;
2251 int txr_remaining = adapter->num_tx_queues;
2252 int i, j;
2253 int rqpv, tqpv;
2254 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002255
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256 /* No mapping required if MSI-X is disabled. */
2257 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002258 goto out;
2259
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002260 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2261
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002262 /*
2263 * The ideal configuration...
2264 * We have enough vectors to map one per queue.
2265 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002266 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2268 map_vector_to_rxq(adapter, v_start, rxr_idx);
2269
2270 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2271 map_vector_to_txq(adapter, v_start, txr_idx);
2272
2273 goto out;
2274 }
2275
2276 /*
2277 * If we don't have enough vectors for a 1-to-1
2278 * mapping, we'll have to group them so there are
2279 * multiple queues per vector.
2280 */
2281 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002282 for (i = v_start; i < q_vectors; i++) {
2283 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 for (j = 0; j < rqpv; j++) {
2285 map_vector_to_rxq(adapter, i, rxr_idx);
2286 rxr_idx++;
2287 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002288 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002289 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002290 for (j = 0; j < tqpv; j++) {
2291 map_vector_to_txq(adapter, i, txr_idx);
2292 txr_idx++;
2293 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002294 }
Auke Kok9a799d72007-09-15 14:07:45 -07002295 }
Auke Kok9a799d72007-09-15 14:07:45 -07002296out:
Auke Kok9a799d72007-09-15 14:07:45 -07002297 return err;
2298}
2299
2300/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2302 * @adapter: board private structure
2303 *
2304 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2305 * interrupts from the kernel.
2306 **/
2307static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2308{
2309 struct net_device *netdev = adapter->netdev;
2310 irqreturn_t (*handler)(int, void *);
2311 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002312 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002313
2314 /* Decrement for Other and TCP Timer vectors */
2315 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2316
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002317 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002318 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002319 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002320
Alexander Duyck08c88332011-06-11 01:45:03 +00002321#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002322 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002323 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2324 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002325 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002326 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002327 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2328 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002329
Joe Perchese8e9f692010-09-07 21:34:53 +00002330 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002331 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2332 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002333 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002334 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2335 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002336 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002337 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2338 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002339 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002340 } else {
2341 /* skip this unused q_vector */
2342 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002343 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002345 handler, 0, q_vector->name,
2346 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002347 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002348 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002349 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002350 goto free_queue_irqs;
2351 }
2352 }
2353
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002354 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002355 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002356 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002357 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002358 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002359 goto free_queue_irqs;
2360 }
2361
2362 return 0;
2363
2364free_queue_irqs:
2365 for (i = vector - 1; i >= 0; i--)
2366 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002367 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002368 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2369 pci_disable_msix(adapter->pdev);
2370 kfree(adapter->msix_entries);
2371 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372 return err;
2373}
2374
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002375/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002376 * ixgbe_irq_enable - Enable default interrupt generation settings
2377 * @adapter: board private structure
2378 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002379static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2380 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002381{
2382 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002383
2384 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002385 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2386 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002387 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2388 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002389 switch (adapter->hw.mac.type) {
2390 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002391 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002392 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002393 mask |= IXGBE_EIMS_GPI_SDP1;
2394 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002395 if (adapter->num_vfs)
2396 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002397 break;
2398 default:
2399 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002400 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002401 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002402 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002403
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002404 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002405 if (queues)
2406 ixgbe_irq_enable_queues(adapter, ~0);
2407 if (flush)
2408 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002409
2410 if (adapter->num_vfs > 32) {
2411 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2412 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2413 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002414}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002415
2416/**
2417 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002418 * @irq: interrupt number
2419 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002420 **/
2421static irqreturn_t ixgbe_intr(int irq, void *data)
2422{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002423 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002424 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002425 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002426 u32 eicr;
2427
Don Skidmore54037502009-02-21 15:42:56 -08002428 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002429 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002430 * before the read of EICR.
2431 */
2432 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2433
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002434 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2435 * therefore no explict interrupt disable is necessary */
2436 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002437 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002438 /*
2439 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002440 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002441 * have disabled interrupts due to EIAM
2442 * finish the workaround of silicon errata on 82598. Unmask
2443 * the interrupt that we masked before the EICR read.
2444 */
2445 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2446 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002447 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002448 }
Auke Kok9a799d72007-09-15 14:07:45 -07002449
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002450 if (eicr & IXGBE_EICR_LSC)
2451 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002452
Alexander Duyckbd508172010-11-16 19:27:03 -08002453 switch (hw->mac.type) {
2454 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002455 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002456 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2457 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002458 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2459 adapter->interrupt_event = eicr;
2460 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2461 ixgbe_service_event_schedule(adapter);
2462 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002463 }
2464 break;
2465 default:
2466 break;
2467 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002468
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002469 ixgbe_check_fan_failure(adapter, eicr);
2470
Alexander Duyck7a921c92009-05-06 10:43:28 +00002471 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002472 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002473 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002474 }
2475
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002476 /*
2477 * re-enable link(maybe) and non-queue interrupts, no flush.
2478 * ixgbe_poll will re-enable the queue interrupts
2479 */
2480
2481 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2482 ixgbe_irq_enable(adapter, false, false);
2483
Auke Kok9a799d72007-09-15 14:07:45 -07002484 return IRQ_HANDLED;
2485}
2486
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002487static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2488{
2489 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2490
2491 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002492 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002493 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2494 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2495 q_vector->rx.count = 0;
2496 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002497 }
2498}
2499
Auke Kok9a799d72007-09-15 14:07:45 -07002500/**
2501 * ixgbe_request_irq - initialize interrupts
2502 * @adapter: board private structure
2503 *
2504 * Attempts to configure interrupts using the best available
2505 * capabilities of the hardware and kernel.
2506 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002508{
2509 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002510 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002511
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002512 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2513 err = ixgbe_request_msix_irqs(adapter);
2514 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002515 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002516 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002518 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002519 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002520 }
2521
Auke Kok9a799d72007-09-15 14:07:45 -07002522 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002523 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002524
Auke Kok9a799d72007-09-15 14:07:45 -07002525 return err;
2526}
2527
2528static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2529{
Auke Kok9a799d72007-09-15 14:07:45 -07002530 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002531 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002532
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002533 q_vectors = adapter->num_msix_vectors;
2534
2535 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002536 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002537
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002538 i--;
2539 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002540 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002541 if (!adapter->q_vector[i]->rx.count &&
2542 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002543 continue;
2544
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002545 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002546 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002547 }
2548
2549 ixgbe_reset_q_vectors(adapter);
2550 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002551 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002552 }
2553}
2554
2555/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002556 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2557 * @adapter: board private structure
2558 **/
2559static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2560{
Alexander Duyckbd508172010-11-16 19:27:03 -08002561 switch (adapter->hw.mac.type) {
2562 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002563 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002564 break;
2565 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002566 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002569 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002570 if (adapter->num_vfs > 32)
2571 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002572 break;
2573 default:
2574 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002575 }
2576 IXGBE_WRITE_FLUSH(&adapter->hw);
2577 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2578 int i;
2579 for (i = 0; i < adapter->num_msix_vectors; i++)
2580 synchronize_irq(adapter->msix_entries[i].vector);
2581 } else {
2582 synchronize_irq(adapter->pdev->irq);
2583 }
2584}
2585
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002586/**
Auke Kok9a799d72007-09-15 14:07:45 -07002587 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2588 *
2589 **/
2590static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2591{
Auke Kok9a799d72007-09-15 14:07:45 -07002592 struct ixgbe_hw *hw = &adapter->hw;
2593
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002594 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002595 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002596
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002597 ixgbe_set_ivar(adapter, 0, 0, 0);
2598 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002599
2600 map_vector_to_rxq(adapter, 0, 0);
2601 map_vector_to_txq(adapter, 0, 0);
2602
Emil Tantilov396e7992010-07-01 20:05:12 +00002603 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002604}
2605
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002606/**
2607 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2608 * @adapter: board private structure
2609 * @ring: structure containing ring specific data
2610 *
2611 * Configure the Tx descriptor ring after a reset.
2612 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002613void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2614 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002615{
2616 struct ixgbe_hw *hw = &adapter->hw;
2617 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002618 int wait_loop = 10;
2619 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002620 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002621
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002622 /* disable queue to avoid issues while updating state */
2623 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2624 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2625 txdctl & ~IXGBE_TXDCTL_ENABLE);
2626 IXGBE_WRITE_FLUSH(hw);
2627
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002628 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002629 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002630 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2631 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2632 ring->count * sizeof(union ixgbe_adv_tx_desc));
2633 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2634 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002635 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002636
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002637 /* configure fetching thresholds */
2638 if (adapter->rx_itr_setting == 0) {
2639 /* cannot set wthresh when itr==0 */
2640 txdctl &= ~0x007F0000;
2641 } else {
2642 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2643 txdctl |= (8 << 16);
2644 }
2645 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2646 /* PThresh workaround for Tx hang with DFP enabled. */
2647 txdctl |= 32;
2648 }
2649
2650 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002651 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2652 adapter->atr_sample_rate) {
2653 ring->atr_sample_rate = adapter->atr_sample_rate;
2654 ring->atr_count = 0;
2655 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2656 } else {
2657 ring->atr_sample_rate = 0;
2658 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002659
John Fastabendc84d3242010-11-16 19:27:12 -08002660 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2661
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002662 /* enable queue */
2663 txdctl |= IXGBE_TXDCTL_ENABLE;
2664 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2665
2666 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2667 if (hw->mac.type == ixgbe_mac_82598EB &&
2668 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2669 return;
2670
2671 /* poll to verify queue is enabled */
2672 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002673 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002674 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2675 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2676 if (!wait_loop)
2677 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002678}
2679
Alexander Duyck120ff942010-08-19 13:34:50 +00002680static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2681{
2682 struct ixgbe_hw *hw = &adapter->hw;
2683 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002684 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002685 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002686
2687 if (hw->mac.type == ixgbe_mac_82598EB)
2688 return;
2689
2690 /* disable the arbiter while setting MTQC */
2691 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2692 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2693 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2694
2695 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002696 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002697 case (IXGBE_FLAG_SRIOV_ENABLED):
2698 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2699 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2700 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002701 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002702 if (!tcs)
2703 reg = IXGBE_MTQC_64Q_1PB;
2704 else if (tcs <= 4)
2705 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2706 else
2707 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2708
2709 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2710
2711 /* Enable Security TX Buffer IFG for multiple pb */
2712 if (tcs) {
2713 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2714 reg |= IXGBE_SECTX_DCB;
2715 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2716 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002717 break;
2718 }
2719
2720 /* re-enable the arbiter */
2721 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2722 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2723}
2724
Auke Kok9a799d72007-09-15 14:07:45 -07002725/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002726 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002727 * @adapter: board private structure
2728 *
2729 * Configure the Tx unit of the MAC after a reset.
2730 **/
2731static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2732{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002733 struct ixgbe_hw *hw = &adapter->hw;
2734 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002735 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002736
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002737 ixgbe_setup_mtqc(adapter);
2738
2739 if (hw->mac.type != ixgbe_mac_82598EB) {
2740 /* DMATXCTL.EN must be before Tx queues are enabled */
2741 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2742 dmatxctl |= IXGBE_DMATXCTL_TE;
2743 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2744 }
2745
Auke Kok9a799d72007-09-15 14:07:45 -07002746 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002747 for (i = 0; i < adapter->num_tx_queues; i++)
2748 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002749}
2750
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002751#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002752
Yi Zoua6616b42009-08-06 13:05:23 +00002753static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002754 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002755{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002756 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002757 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002758
Alexander Duyckbd508172010-11-16 19:27:03 -08002759 switch (adapter->hw.mac.type) {
2760 case ixgbe_mac_82598EB: {
2761 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2762 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002763 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002764 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002765 break;
2766 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002767 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002768 default:
2769 break;
2770 }
2771
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002772 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002773
2774 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2775 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002776 if (adapter->num_vfs)
2777 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002778
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002779 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2780 IXGBE_SRRCTL_BSIZEHDR_MASK;
2781
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002782 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002783#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2784 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2785#else
2786 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2787#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002788 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002789 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002790 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2791 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002792 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002793 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002794
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002795 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002796}
2797
Alexander Duyck05abb122010-08-19 13:35:41 +00002798static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002799{
Alexander Duyck05abb122010-08-19 13:35:41 +00002800 struct ixgbe_hw *hw = &adapter->hw;
2801 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002802 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2803 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002804 u32 mrqc = 0, reta = 0;
2805 u32 rxcsum;
2806 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002807 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002808 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2809
2810 if (tcs)
2811 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002812
Alexander Duyck05abb122010-08-19 13:35:41 +00002813 /* Fill out hash function seeds */
2814 for (i = 0; i < 10; i++)
2815 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002816
Alexander Duyck05abb122010-08-19 13:35:41 +00002817 /* Fill out redirection table */
2818 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002819 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002820 j = 0;
2821 /* reta = 4-byte sliding window of
2822 * 0x00..(indices-1)(indices-1)00..etc. */
2823 reta = (reta << 8) | (j * 0x11);
2824 if ((i & 3) == 3)
2825 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2826 }
2827
2828 /* Disable indicating checksum in descriptor, enables RSS hash */
2829 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2830 rxcsum |= IXGBE_RXCSUM_PCSD;
2831 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2832
John Fastabend8b1c0b22011-05-03 02:26:48 +00002833 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2834 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002835 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002836 } else {
2837 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2838 | IXGBE_FLAG_SRIOV_ENABLED);
2839
2840 switch (mask) {
2841 case (IXGBE_FLAG_RSS_ENABLED):
2842 if (!tcs)
2843 mrqc = IXGBE_MRQC_RSSEN;
2844 else if (tcs <= 4)
2845 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2846 else
2847 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2848 break;
2849 case (IXGBE_FLAG_SRIOV_ENABLED):
2850 mrqc = IXGBE_MRQC_VMDQEN;
2851 break;
2852 default:
2853 break;
2854 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002855 }
2856
Alexander Duyck05abb122010-08-19 13:35:41 +00002857 /* Perform hash on these packet types */
2858 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2859 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2860 | IXGBE_MRQC_RSS_FIELD_IPV6
2861 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2862
2863 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002864}
2865
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002866/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002867 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2868 * @adapter: address of board private structure
2869 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002870 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002871static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002872 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002873{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002874 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002875 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002876 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002877 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002878
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002879 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002880 return;
2881
2882 rx_buf_len = ring->rx_buf_len;
2883 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002884 rscctrl |= IXGBE_RSCCTL_RSCEN;
2885 /*
2886 * we must limit the number of descriptors so that the
2887 * total size of max desc * buf_len is not greater
2888 * than 65535
2889 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002890 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002891#if (MAX_SKB_FRAGS > 16)
2892 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2893#elif (MAX_SKB_FRAGS > 8)
2894 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2895#elif (MAX_SKB_FRAGS > 4)
2896 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2897#else
2898 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2899#endif
2900 } else {
2901 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2902 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2903 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2904 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2905 else
2906 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2907 }
Alexander Duyck73670962010-08-19 13:38:34 +00002908 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002909}
2910
Alexander Duyck9e10e042010-08-19 13:40:06 +00002911/**
2912 * ixgbe_set_uta - Set unicast filter table address
2913 * @adapter: board private structure
2914 *
2915 * The unicast table address is a register array of 32-bit registers.
2916 * The table is meant to be used in a way similar to how the MTA is used
2917 * however due to certain limitations in the hardware it is necessary to
2918 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2919 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2920 **/
2921static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2922{
2923 struct ixgbe_hw *hw = &adapter->hw;
2924 int i;
2925
2926 /* The UTA table only exists on 82599 hardware and newer */
2927 if (hw->mac.type < ixgbe_mac_82599EB)
2928 return;
2929
2930 /* we only need to do this if VMDq is enabled */
2931 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2932 return;
2933
2934 for (i = 0; i < 128; i++)
2935 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2936}
2937
2938#define IXGBE_MAX_RX_DESC_POLL 10
2939static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2940 struct ixgbe_ring *ring)
2941{
2942 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002943 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2944 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002945 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002946
2947 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2948 if (hw->mac.type == ixgbe_mac_82598EB &&
2949 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2950 return;
2951
2952 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002953 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002954 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2955 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2956
2957 if (!wait_loop) {
2958 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2959 "the polling period\n", reg_idx);
2960 }
2961}
2962
Yi Zou2d39d572011-01-06 14:29:56 +00002963void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2964 struct ixgbe_ring *ring)
2965{
2966 struct ixgbe_hw *hw = &adapter->hw;
2967 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2968 u32 rxdctl;
2969 u8 reg_idx = ring->reg_idx;
2970
2971 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2972 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2973
2974 /* write value back with RXDCTL.ENABLE bit cleared */
2975 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2976
2977 if (hw->mac.type == ixgbe_mac_82598EB &&
2978 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2979 return;
2980
2981 /* the hardware may take up to 100us to really disable the rx queue */
2982 do {
2983 udelay(10);
2984 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2985 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
2986
2987 if (!wait_loop) {
2988 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
2989 "the polling period\n", reg_idx);
2990 }
2991}
2992
Alexander Duyck84418e32010-08-19 13:40:54 +00002993void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
2994 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00002995{
2996 struct ixgbe_hw *hw = &adapter->hw;
2997 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002998 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002999 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003000
Alexander Duyck9e10e042010-08-19 13:40:06 +00003001 /* disable queue to avoid issues while updating state */
3002 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003003 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003004
Alexander Duyckacd37172010-08-19 13:36:05 +00003005 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3006 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3007 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3008 ring->count * sizeof(union ixgbe_adv_rx_desc));
3009 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3010 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003011 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003012
3013 ixgbe_configure_srrctl(adapter, ring);
3014 ixgbe_configure_rscctl(adapter, ring);
3015
Greg Rosee9f98072011-01-26 01:06:07 +00003016 /* If operating in IOV mode set RLPML for X540 */
3017 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3018 hw->mac.type == ixgbe_mac_X540) {
3019 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3020 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3021 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3022 }
3023
Alexander Duyck9e10e042010-08-19 13:40:06 +00003024 if (hw->mac.type == ixgbe_mac_82598EB) {
3025 /*
3026 * enable cache line friendly hardware writes:
3027 * PTHRESH=32 descriptors (half the internal cache),
3028 * this also removes ugly rx_no_buffer_count increment
3029 * HTHRESH=4 descriptors (to minimize latency on fetch)
3030 * WTHRESH=8 burst writeback up to two cache lines
3031 */
3032 rxdctl &= ~0x3FFFFF;
3033 rxdctl |= 0x080420;
3034 }
3035
3036 /* enable receive descriptor ring */
3037 rxdctl |= IXGBE_RXDCTL_ENABLE;
3038 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3039
3040 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003041 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003042}
3043
Alexander Duyck48654522010-08-19 13:36:27 +00003044static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3045{
3046 struct ixgbe_hw *hw = &adapter->hw;
3047 int p;
3048
3049 /* PSRTYPE must be initialized in non 82598 adapters */
3050 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003051 IXGBE_PSRTYPE_UDPHDR |
3052 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003053 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003054 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003055
3056 if (hw->mac.type == ixgbe_mac_82598EB)
3057 return;
3058
3059 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3060 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3061
3062 for (p = 0; p < adapter->num_rx_pools; p++)
3063 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3064 psrtype);
3065}
3066
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003067static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3068{
3069 struct ixgbe_hw *hw = &adapter->hw;
3070 u32 gcr_ext;
3071 u32 vt_reg_bits;
3072 u32 reg_offset, vf_shift;
3073 u32 vmdctl;
3074
3075 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3076 return;
3077
3078 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3079 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3080 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3081 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3082
3083 vf_shift = adapter->num_vfs % 32;
3084 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3085
3086 /* Enable only the PF's pool for Tx/Rx */
3087 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3088 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3089 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3090 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3091 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3092
3093 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3094 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3095
3096 /*
3097 * Set up VF register offsets for selected VT Mode,
3098 * i.e. 32 or 64 VFs for SR-IOV
3099 */
3100 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3101 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3102 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3103 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3104
3105 /* enable Tx loopback for VF/PF communication */
3106 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003107 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003108 hw->mac.ops.set_mac_anti_spoofing(hw,
3109 (adapter->antispoofing_enabled =
3110 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003111 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003112}
3113
Alexander Duyck477de6e2010-08-19 13:38:11 +00003114static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003115{
Auke Kok9a799d72007-09-15 14:07:45 -07003116 struct ixgbe_hw *hw = &adapter->hw;
3117 struct net_device *netdev = adapter->netdev;
3118 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003119 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003120 struct ixgbe_ring *rx_ring;
3121 int i;
3122 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003123
Auke Kok9a799d72007-09-15 14:07:45 -07003124 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003125 /* On by default */
3126 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3127
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003128 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003129 if (adapter->num_vfs)
3130 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3131
3132 /* Disable packet split due to 82599 erratum #45 */
3133 if (hw->mac.type == ixgbe_mac_82599EB)
3134 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003135
3136 /* Set the RX buffer length according to the mode */
3137 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003138 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003139 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003140 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003141 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003142 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003143 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003144 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3145 }
3146
3147#ifdef IXGBE_FCOE
3148 /* adjust max frame to be able to do baby jumbo for FCoE */
3149 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3150 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3151 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3152
3153#endif /* IXGBE_FCOE */
3154 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3155 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3156 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3157 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3158
3159 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003160 }
3161
Auke Kok9a799d72007-09-15 14:07:45 -07003162 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003163 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3164 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003165 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3166
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003167 /*
3168 * Setup the HW Rx Head and Tail Descriptor Pointers and
3169 * the Base and Length of the Rx Descriptor Ring
3170 */
Auke Kok9a799d72007-09-15 14:07:45 -07003171 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003172 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003173 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003174
Yi Zou6e455b892009-08-06 13:05:44 +00003175 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003176 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003177 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003178 clear_ring_ps_enabled(rx_ring);
3179
3180 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3181 set_ring_rsc_enabled(rx_ring);
3182 else
3183 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003184
Yi Zou63f39bd2009-05-17 12:34:35 +00003185#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003186 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003187 struct ixgbe_ring_feature *f;
3188 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003189 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003190 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003191 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3192 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003193 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003194 } else if (!ring_is_rsc_enabled(rx_ring) &&
3195 !ring_is_ps_enabled(rx_ring)) {
3196 rx_ring->rx_buf_len =
3197 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003198 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003199 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003200#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003201 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003202}
3203
Alexander Duyck73670962010-08-19 13:38:34 +00003204static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3205{
3206 struct ixgbe_hw *hw = &adapter->hw;
3207 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3208
3209 switch (hw->mac.type) {
3210 case ixgbe_mac_82598EB:
3211 /*
3212 * For VMDq support of different descriptor types or
3213 * buffer sizes through the use of multiple SRRCTL
3214 * registers, RDRXCTL.MVMEN must be set to 1
3215 *
3216 * also, the manual doesn't mention it clearly but DCA hints
3217 * will only use queue 0's tags unless this bit is set. Side
3218 * effects of setting this bit are only that SRRCTL must be
3219 * fully programmed [0..15]
3220 */
3221 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3222 break;
3223 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003224 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003225 /* Disable RSC for ACK packets */
3226 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3227 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3228 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3229 /* hardware requires some bits to be set by default */
3230 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3231 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3232 break;
3233 default:
3234 /* We should do nothing since we don't know this hardware */
3235 return;
3236 }
3237
3238 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3239}
3240
Alexander Duyck477de6e2010-08-19 13:38:11 +00003241/**
3242 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3243 * @adapter: board private structure
3244 *
3245 * Configure the Rx unit of the MAC after a reset.
3246 **/
3247static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3248{
3249 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003250 int i;
3251 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003252
3253 /* disable receives while setting up the descriptors */
3254 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3255 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3256
3257 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003258 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003259
Alexander Duyck9e10e042010-08-19 13:40:06 +00003260 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003261 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003262
Alexander Duyck9e10e042010-08-19 13:40:06 +00003263 ixgbe_set_uta(adapter);
3264
Alexander Duyck477de6e2010-08-19 13:38:11 +00003265 /* set_rx_buffer_len must be called before ring initialization */
3266 ixgbe_set_rx_buffer_len(adapter);
3267
3268 /*
3269 * Setup the HW Rx Head and Tail Descriptor Pointers and
3270 * the Base and Length of the Rx Descriptor Ring
3271 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003272 for (i = 0; i < adapter->num_rx_queues; i++)
3273 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003274
Alexander Duyck9e10e042010-08-19 13:40:06 +00003275 /* disable drop enable for 82598 parts */
3276 if (hw->mac.type == ixgbe_mac_82598EB)
3277 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3278
3279 /* enable all receives */
3280 rxctrl |= IXGBE_RXCTRL_RXEN;
3281 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003282}
3283
Auke Kok9a799d72007-09-15 14:07:45 -07003284static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3285{
3286 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003287 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003288 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003289
3290 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003291 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003292 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003293}
3294
3295static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3296{
3297 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003298 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003299 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003300
Auke Kok9a799d72007-09-15 14:07:45 -07003301 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003302 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003303 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003304}
3305
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003306/**
3307 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3308 * @adapter: driver data
3309 */
3310static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3311{
3312 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003313 u32 vlnctrl;
3314
3315 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3316 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3317 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3318}
3319
3320/**
3321 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3322 * @adapter: driver data
3323 */
3324static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3325{
3326 struct ixgbe_hw *hw = &adapter->hw;
3327 u32 vlnctrl;
3328
3329 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3330 vlnctrl |= IXGBE_VLNCTRL_VFE;
3331 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3332 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3333}
3334
3335/**
3336 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3337 * @adapter: driver data
3338 */
3339static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3340{
3341 struct ixgbe_hw *hw = &adapter->hw;
3342 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003343 int i, j;
3344
3345 switch (hw->mac.type) {
3346 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003347 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3348 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003349 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3350 break;
3351 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003352 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003353 for (i = 0; i < adapter->num_rx_queues; i++) {
3354 j = adapter->rx_ring[i]->reg_idx;
3355 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3356 vlnctrl &= ~IXGBE_RXDCTL_VME;
3357 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3358 }
3359 break;
3360 default:
3361 break;
3362 }
3363}
3364
3365/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003366 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003367 * @adapter: driver data
3368 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003369static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003370{
3371 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003372 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003373 int i, j;
3374
3375 switch (hw->mac.type) {
3376 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003377 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3378 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003379 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3380 break;
3381 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003382 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003383 for (i = 0; i < adapter->num_rx_queues; i++) {
3384 j = adapter->rx_ring[i]->reg_idx;
3385 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3386 vlnctrl |= IXGBE_RXDCTL_VME;
3387 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3388 }
3389 break;
3390 default:
3391 break;
3392 }
3393}
3394
Auke Kok9a799d72007-09-15 14:07:45 -07003395static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3396{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003397 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003398
Jesse Grossf62bbb52010-10-20 13:56:10 +00003399 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3400
3401 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3402 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003403}
3404
3405/**
Alexander Duyck28500622010-06-15 09:25:48 +00003406 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3407 * @netdev: network interface device structure
3408 *
3409 * Writes unicast address list to the RAR table.
3410 * Returns: -ENOMEM on failure/insufficient address space
3411 * 0 on no addresses written
3412 * X on writing X addresses to the RAR table
3413 **/
3414static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3415{
3416 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3417 struct ixgbe_hw *hw = &adapter->hw;
3418 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003419 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003420 int count = 0;
3421
3422 /* return ENOMEM indicating insufficient memory for addresses */
3423 if (netdev_uc_count(netdev) > rar_entries)
3424 return -ENOMEM;
3425
3426 if (!netdev_uc_empty(netdev) && rar_entries) {
3427 struct netdev_hw_addr *ha;
3428 /* return error if we do not support writing to RAR table */
3429 if (!hw->mac.ops.set_rar)
3430 return -ENOMEM;
3431
3432 netdev_for_each_uc_addr(ha, netdev) {
3433 if (!rar_entries)
3434 break;
3435 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3436 vfn, IXGBE_RAH_AV);
3437 count++;
3438 }
3439 }
3440 /* write the addresses in reverse order to avoid write combining */
3441 for (; rar_entries > 0 ; rar_entries--)
3442 hw->mac.ops.clear_rar(hw, rar_entries);
3443
3444 return count;
3445}
3446
3447/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003448 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003449 * @netdev: network interface device structure
3450 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003451 * The set_rx_method entry point is called whenever the unicast/multicast
3452 * address list or the network interface flags are updated. This routine is
3453 * responsible for configuring the hardware for proper unicast, multicast and
3454 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003455 **/
Greg Rose7f870472010-01-09 02:25:29 +00003456void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003457{
3458 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3459 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003460 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3461 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003462
3463 /* Check for Promiscuous and All Multicast modes */
3464
3465 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3466
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003467 /* set all bits that we expect to always be set */
3468 fctrl |= IXGBE_FCTRL_BAM;
3469 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3470 fctrl |= IXGBE_FCTRL_PMCF;
3471
Alexander Duyck28500622010-06-15 09:25:48 +00003472 /* clear the bits we are changing the status of */
3473 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3474
Auke Kok9a799d72007-09-15 14:07:45 -07003475 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003476 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003477 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003478 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003479 /* don't hardware filter vlans in promisc mode */
3480 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003481 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003482 if (netdev->flags & IFF_ALLMULTI) {
3483 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003484 vmolr |= IXGBE_VMOLR_MPE;
3485 } else {
3486 /*
3487 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003488 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003489 * that we can at least receive multicast traffic
3490 */
3491 hw->mac.ops.update_mc_addr_list(hw, netdev);
3492 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003493 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003494 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003495 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003496 /*
3497 * Write addresses to available RAR registers, if there is not
3498 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003499 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003500 */
3501 count = ixgbe_write_uc_addr_list(netdev);
3502 if (count < 0) {
3503 fctrl |= IXGBE_FCTRL_UPE;
3504 vmolr |= IXGBE_VMOLR_ROPE;
3505 }
3506 }
3507
3508 if (adapter->num_vfs) {
3509 ixgbe_restore_vf_multicasts(adapter);
3510 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3511 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3512 IXGBE_VMOLR_ROPE);
3513 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003514 }
3515
3516 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003517
3518 if (netdev->features & NETIF_F_HW_VLAN_RX)
3519 ixgbe_vlan_strip_enable(adapter);
3520 else
3521 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003522}
3523
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003524static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3525{
3526 int q_idx;
3527 struct ixgbe_q_vector *q_vector;
3528 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3529
3530 /* legacy and MSI only use one vector */
3531 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3532 q_vectors = 1;
3533
3534 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003535 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003536 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003537 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003538 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003539 if (!q_vector->rx.count || !q_vector->tx.count) {
3540 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003541 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003542 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003543 napi->poll = &ixgbe_clean_rxonly;
3544 }
3545 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003546
3547 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003548 }
3549}
3550
3551static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3552{
3553 int q_idx;
3554 struct ixgbe_q_vector *q_vector;
3555 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3556
3557 /* legacy and MSI only use one vector */
3558 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3559 q_vectors = 1;
3560
3561 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003562 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003563 napi_disable(&q_vector->napi);
3564 }
3565}
3566
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003567#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003568/*
3569 * ixgbe_configure_dcb - Configure DCB hardware
3570 * @adapter: ixgbe adapter struct
3571 *
3572 * This is called by the driver on open to configure the DCB hardware.
3573 * This is also called by the gennetlink interface when reconfiguring
3574 * the DCB state.
3575 */
3576static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3577{
3578 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003579 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003580
Alexander Duyck67ebd792010-08-19 13:34:04 +00003581 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3582 if (hw->mac.type == ixgbe_mac_82598EB)
3583 netif_set_gso_max_size(adapter->netdev, 65536);
3584 return;
3585 }
3586
3587 if (hw->mac.type == ixgbe_mac_82598EB)
3588 netif_set_gso_max_size(adapter->netdev, 32768);
3589
Alexander Duyck2f90b862008-11-20 20:52:10 -08003590
Alexander Duyck2f90b862008-11-20 20:52:10 -08003591 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003592 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003593
Alexander Duyck2f90b862008-11-20 20:52:10 -08003594 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003595
3596 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003597 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003598#ifdef CONFIG_FCOE
3599 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3600 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3601#endif
3602 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3603 DCB_TX_CONFIG);
3604 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3605 DCB_RX_CONFIG);
3606 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3607 } else {
3608 struct net_device *dev = adapter->netdev;
3609
3610 if (adapter->ixgbe_ieee_ets)
3611 dev->dcbnl_ops->ieee_setets(dev,
3612 adapter->ixgbe_ieee_ets);
3613 if (adapter->ixgbe_ieee_pfc)
3614 dev->dcbnl_ops->ieee_setpfc(dev,
3615 adapter->ixgbe_ieee_pfc);
3616 }
John Fastabend8187cd42011-02-23 05:58:08 +00003617
3618 /* Enable RSS Hash per TC */
3619 if (hw->mac.type != ixgbe_mac_82598EB) {
3620 int i;
3621 u32 reg = 0;
3622
3623 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3624 u8 msb = 0;
3625 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3626
3627 while (cnt >>= 1)
3628 msb++;
3629
3630 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3631 }
3632 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3633 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003634}
3635
3636#endif
John Fastabend80605c652011-05-02 12:34:10 +00003637
3638static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3639{
3640 int hdrm = 0;
3641 int num_tc = netdev_get_num_tc(adapter->netdev);
3642 struct ixgbe_hw *hw = &adapter->hw;
3643
3644 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3645 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3646 hdrm = 64 << adapter->fdir_pballoc;
3647
3648 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3649}
3650
Alexander Duycke4911d52011-05-11 07:18:52 +00003651static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3652{
3653 struct ixgbe_hw *hw = &adapter->hw;
3654 struct hlist_node *node, *node2;
3655 struct ixgbe_fdir_filter *filter;
3656
3657 spin_lock(&adapter->fdir_perfect_lock);
3658
3659 if (!hlist_empty(&adapter->fdir_filter_list))
3660 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3661
3662 hlist_for_each_entry_safe(filter, node, node2,
3663 &adapter->fdir_filter_list, fdir_node) {
3664 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003665 &filter->filter,
3666 filter->sw_idx,
3667 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3668 IXGBE_FDIR_DROP_QUEUE :
3669 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003670 }
3671
3672 spin_unlock(&adapter->fdir_perfect_lock);
3673}
3674
Auke Kok9a799d72007-09-15 14:07:45 -07003675static void ixgbe_configure(struct ixgbe_adapter *adapter)
3676{
3677 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003678 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003679 int i;
3680
John Fastabend80605c652011-05-02 12:34:10 +00003681 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003682#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003683 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003684#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003685
Jesse Grossf62bbb52010-10-20 13:56:10 +00003686 ixgbe_set_rx_mode(netdev);
3687 ixgbe_restore_vlan(adapter);
3688
Yi Zoueacd73f2009-05-13 13:11:06 +00003689#ifdef IXGBE_FCOE
3690 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3691 ixgbe_configure_fcoe(adapter);
3692
3693#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003694 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3695 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003696 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003697 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003698 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003699 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3700 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3701 adapter->fdir_pballoc);
3702 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003703 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003704 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003705
Auke Kok9a799d72007-09-15 14:07:45 -07003706 ixgbe_configure_tx(adapter);
3707 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003708}
3709
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003710static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3711{
3712 switch (hw->phy.type) {
3713 case ixgbe_phy_sfp_avago:
3714 case ixgbe_phy_sfp_ftl:
3715 case ixgbe_phy_sfp_intel:
3716 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003717 case ixgbe_phy_sfp_passive_tyco:
3718 case ixgbe_phy_sfp_passive_unknown:
3719 case ixgbe_phy_sfp_active_unknown:
3720 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003721 return true;
3722 default:
3723 return false;
3724 }
3725}
3726
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003727/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003728 * ixgbe_sfp_link_config - set up SFP+ link
3729 * @adapter: pointer to private adapter struct
3730 **/
3731static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3732{
Alexander Duyck70864002011-04-27 09:13:56 +00003733 /*
3734 * We are assuming the worst case scenerio here, and that
3735 * is that an SFP was inserted/removed after the reset
3736 * but before SFP detection was enabled. As such the best
3737 * solution is to just start searching as soon as we start
3738 */
3739 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3740 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003741
Alexander Duyck70864002011-04-27 09:13:56 +00003742 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003743}
3744
3745/**
3746 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003747 * @hw: pointer to private hardware struct
3748 *
3749 * Returns 0 on success, negative on failure
3750 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003751static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003752{
3753 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003754 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003755 u32 ret = IXGBE_ERR_LINK_SETUP;
3756
3757 if (hw->mac.ops.check_link)
3758 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3759
3760 if (ret)
3761 goto link_cfg_out;
3762
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003763 autoneg = hw->phy.autoneg_advertised;
3764 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003765 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3766 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003767 if (ret)
3768 goto link_cfg_out;
3769
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003770 if (hw->mac.ops.setup_link)
3771 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003772link_cfg_out:
3773 return ret;
3774}
3775
Alexander Duycka34bcff2010-08-19 13:39:20 +00003776static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003777{
Auke Kok9a799d72007-09-15 14:07:45 -07003778 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003779 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003780
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003781 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003782 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3783 IXGBE_GPIE_OCD;
3784 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003785 /*
3786 * use EIAM to auto-mask when MSI-X interrupt is asserted
3787 * this saves a register write for every interrupt
3788 */
3789 switch (hw->mac.type) {
3790 case ixgbe_mac_82598EB:
3791 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3792 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003793 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003794 case ixgbe_mac_X540:
3795 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003796 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3797 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3798 break;
3799 }
3800 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003801 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3802 * specifically only auto mask tx and rx interrupts */
3803 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003804 }
3805
Alexander Duycka34bcff2010-08-19 13:39:20 +00003806 /* XXX: to interrupt immediately for EICS writes, enable this */
3807 /* gpie |= IXGBE_GPIE_EIMEN; */
3808
3809 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3810 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3811 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003812 }
3813
Alexander Duycka34bcff2010-08-19 13:39:20 +00003814 /* Enable fan failure interrupt */
3815 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003816 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003817
Don Skidmore2698b202011-04-13 07:01:52 +00003818 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003819 gpie |= IXGBE_SDP1_GPIEN;
3820 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003821 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003822
3823 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3824}
3825
3826static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3827{
3828 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003829 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003830 u32 ctrl_ext;
3831
3832 ixgbe_get_hw_control(adapter);
3833 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003834
Auke Kok9a799d72007-09-15 14:07:45 -07003835 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3836 ixgbe_configure_msix(adapter);
3837 else
3838 ixgbe_configure_msi_and_legacy(adapter);
3839
Don Skidmorec6ecf392010-12-03 03:31:51 +00003840 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3841 if (hw->mac.ops.enable_tx_laser &&
3842 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003843 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003844 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003845 hw->mac.ops.enable_tx_laser(hw);
3846
Auke Kok9a799d72007-09-15 14:07:45 -07003847 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003848 ixgbe_napi_enable_all(adapter);
3849
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003850 if (ixgbe_is_sfp(hw)) {
3851 ixgbe_sfp_link_config(adapter);
3852 } else {
3853 err = ixgbe_non_sfp_link_config(hw);
3854 if (err)
3855 e_err(probe, "link_config FAILED %d\n", err);
3856 }
3857
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003858 /* clear any pending interrupts, may auto mask */
3859 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003860 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003861
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003862 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003863 * If this adapter has a fan, check to see if we had a failure
3864 * before we enabled the interrupt.
3865 */
3866 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3867 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3868 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003869 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003870 }
3871
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003872 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003873 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003874
Auke Kok9a799d72007-09-15 14:07:45 -07003875 /* bring the link up in the watchdog, this could race with our first
3876 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003877 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3878 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003879 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003880
3881 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3882 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3883 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3884 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3885
Auke Kok9a799d72007-09-15 14:07:45 -07003886 return 0;
3887}
3888
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003889void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3890{
3891 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003892 /* put off any impending NetWatchDogTimeout */
3893 adapter->netdev->trans_start = jiffies;
3894
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003895 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003896 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003897 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003898 /*
3899 * If SR-IOV enabled then wait a bit before bringing the adapter
3900 * back up to give the VFs time to respond to the reset. The
3901 * two second wait is based upon the watchdog timer cycle in
3902 * the VF driver.
3903 */
3904 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3905 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003906 ixgbe_up(adapter);
3907 clear_bit(__IXGBE_RESETTING, &adapter->state);
3908}
3909
Auke Kok9a799d72007-09-15 14:07:45 -07003910int ixgbe_up(struct ixgbe_adapter *adapter)
3911{
3912 /* hardware has been reset, we need to reload some things */
3913 ixgbe_configure(adapter);
3914
3915 return ixgbe_up_complete(adapter);
3916}
3917
3918void ixgbe_reset(struct ixgbe_adapter *adapter)
3919{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003920 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003921 int err;
3922
Alexander Duyck70864002011-04-27 09:13:56 +00003923 /* lock SFP init bit to prevent race conditions with the watchdog */
3924 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3925 usleep_range(1000, 2000);
3926
3927 /* clear all SFP and link config related flags while holding SFP_INIT */
3928 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3929 IXGBE_FLAG2_SFP_NEEDS_RESET);
3930 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3931
Don Skidmore8ca783a2009-05-26 20:40:47 -07003932 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003933 switch (err) {
3934 case 0:
3935 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003936 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003937 break;
3938 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003939 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003940 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003941 case IXGBE_ERR_EEPROM_VERSION:
3942 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003943 e_dev_warn("This device is a pre-production adapter/LOM. "
3944 "Please be aware there may be issuesassociated with "
3945 "your hardware. If you are experiencing problems "
3946 "please contact your Intel or hardware "
3947 "representative who provided you with this "
3948 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003949 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003950 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003951 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003952 }
Auke Kok9a799d72007-09-15 14:07:45 -07003953
Alexander Duyck70864002011-04-27 09:13:56 +00003954 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3955
Auke Kok9a799d72007-09-15 14:07:45 -07003956 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003957 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3958 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003959}
3960
Auke Kok9a799d72007-09-15 14:07:45 -07003961/**
3962 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003963 * @rx_ring: ring to free buffers from
3964 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003965static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003966{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003967 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003968 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003969 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003970
Alexander Duyck84418e32010-08-19 13:40:54 +00003971 /* ring already cleared, nothing to do */
3972 if (!rx_ring->rx_buffer_info)
3973 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003974
Alexander Duyck84418e32010-08-19 13:40:54 +00003975 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003976 for (i = 0; i < rx_ring->count; i++) {
3977 struct ixgbe_rx_buffer *rx_buffer_info;
3978
3979 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3980 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003981 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003982 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003983 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003984 rx_buffer_info->dma = 0;
3985 }
3986 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00003987 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07003988 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00003989 do {
3990 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003991 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003992 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00003993 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003994 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003995 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003996 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00003997 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00003998 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00003999 skb = skb->prev;
4000 dev_kfree_skb(this);
4001 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004002 }
4003 if (!rx_buffer_info->page)
4004 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004005 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004006 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004007 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004008 rx_buffer_info->page_dma = 0;
4009 }
Auke Kok9a799d72007-09-15 14:07:45 -07004010 put_page(rx_buffer_info->page);
4011 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004012 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004013 }
4014
4015 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4016 memset(rx_ring->rx_buffer_info, 0, size);
4017
4018 /* Zero out the descriptor ring */
4019 memset(rx_ring->desc, 0, rx_ring->size);
4020
4021 rx_ring->next_to_clean = 0;
4022 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004023}
4024
4025/**
4026 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004027 * @tx_ring: ring to be cleaned
4028 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004029static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004030{
4031 struct ixgbe_tx_buffer *tx_buffer_info;
4032 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004033 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004034
Alexander Duyck84418e32010-08-19 13:40:54 +00004035 /* ring already cleared, nothing to do */
4036 if (!tx_ring->tx_buffer_info)
4037 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004038
Alexander Duyck84418e32010-08-19 13:40:54 +00004039 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004040 for (i = 0; i < tx_ring->count; i++) {
4041 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004042 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004043 }
4044
4045 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4046 memset(tx_ring->tx_buffer_info, 0, size);
4047
4048 /* Zero out the descriptor ring */
4049 memset(tx_ring->desc, 0, tx_ring->size);
4050
4051 tx_ring->next_to_use = 0;
4052 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004053}
4054
4055/**
Auke Kok9a799d72007-09-15 14:07:45 -07004056 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4057 * @adapter: board private structure
4058 **/
4059static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4060{
4061 int i;
4062
4063 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004064 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004065}
4066
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004067/**
4068 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4069 * @adapter: board private structure
4070 **/
4071static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4072{
4073 int i;
4074
4075 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004076 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004077}
4078
Alexander Duycke4911d52011-05-11 07:18:52 +00004079static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4080{
4081 struct hlist_node *node, *node2;
4082 struct ixgbe_fdir_filter *filter;
4083
4084 spin_lock(&adapter->fdir_perfect_lock);
4085
4086 hlist_for_each_entry_safe(filter, node, node2,
4087 &adapter->fdir_filter_list, fdir_node) {
4088 hlist_del(&filter->fdir_node);
4089 kfree(filter);
4090 }
4091 adapter->fdir_filter_count = 0;
4092
4093 spin_unlock(&adapter->fdir_perfect_lock);
4094}
4095
Auke Kok9a799d72007-09-15 14:07:45 -07004096void ixgbe_down(struct ixgbe_adapter *adapter)
4097{
4098 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004099 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004100 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004101 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004102 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004103
4104 /* signal that we are down to the interrupt handler */
4105 set_bit(__IXGBE_DOWN, &adapter->state);
4106
4107 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004108 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4109 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004110
Yi Zou2d39d572011-01-06 14:29:56 +00004111 /* disable all enabled rx queues */
4112 for (i = 0; i < adapter->num_rx_queues; i++)
4113 /* this call also flushes the previous write */
4114 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4115
Don Skidmore032b4322011-03-18 09:32:53 +00004116 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004117
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004118 netif_tx_stop_all_queues(netdev);
4119
Alexander Duyck70864002011-04-27 09:13:56 +00004120 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004121 netif_carrier_off(netdev);
4122 netif_tx_disable(netdev);
4123
4124 ixgbe_irq_disable(adapter);
4125
4126 ixgbe_napi_disable_all(adapter);
4127
Alexander Duyckd034acf2011-04-27 09:25:34 +00004128 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4129 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004130 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4131
4132 del_timer_sync(&adapter->service_timer);
4133
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004134 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004135 if (adapter->num_vfs) {
4136 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004137 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004138
Auke Kok9a799d72007-09-15 14:07:45 -07004139 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004140 ixgbe_disable_tx_rx(adapter);
4141
4142 /* Mark all the VFs as inactive */
4143 for (i = 0 ; i < adapter->num_vfs; i++)
4144 adapter->vfinfo[i].clear_to_send = 0;
4145 }
4146
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004147 /* Cleanup the affinity_hint CPU mask memory and callback */
4148 for (i = 0; i < num_q_vectors; i++) {
4149 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4150 /* clear the affinity_mask in the IRQ descriptor */
4151 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4152 /* release the CPU mask memory */
4153 free_cpumask_var(q_vector->affinity_mask);
4154 }
4155
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004156 /* disable transmits in the hardware now that interrupts are off */
4157 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004158 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004159 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004160 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004161
4162 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004163 switch (hw->mac.type) {
4164 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004165 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004166 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004167 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4168 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004169 break;
4170 default:
4171 break;
4172 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004173
Paul Larson6f4a0e42008-06-24 17:00:56 -07004174 if (!pci_channel_offline(adapter->pdev))
4175 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004176
4177 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4178 if (hw->mac.ops.disable_tx_laser &&
4179 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004180 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004181 (hw->mac.type == ixgbe_mac_82599EB))))
4182 hw->mac.ops.disable_tx_laser(hw);
4183
Auke Kok9a799d72007-09-15 14:07:45 -07004184 ixgbe_clean_all_tx_rings(adapter);
4185 ixgbe_clean_all_rx_rings(adapter);
4186
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004187#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004188 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004189 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004190#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004191}
4192
Auke Kok9a799d72007-09-15 14:07:45 -07004193/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004194 * ixgbe_poll - NAPI Rx polling callback
4195 * @napi: structure for representing this polling device
4196 * @budget: how many packets driver is allowed to clean
4197 *
4198 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004199 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004200static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004201{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004202 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004203 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004204 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004205 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004206
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004207#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004208 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4209 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004210#endif
4211
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004212 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4213 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004214
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004215 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004216 work_done = budget;
4217
David S. Miller53e52c72008-01-07 21:06:12 -08004218 /* If budget not fully consumed, exit the polling mode */
4219 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004220 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004221 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004222 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004223 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004224 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004225 }
Auke Kok9a799d72007-09-15 14:07:45 -07004226 return work_done;
4227}
4228
4229/**
4230 * ixgbe_tx_timeout - Respond to a Tx Hang
4231 * @netdev: network interface device structure
4232 **/
4233static void ixgbe_tx_timeout(struct net_device *netdev)
4234{
4235 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4236
4237 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004238 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004239}
4240
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004241/**
4242 * ixgbe_set_rss_queues: Allocate queues for RSS
4243 * @adapter: board private structure to initialize
4244 *
4245 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4246 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4247 *
4248 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004249static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4250{
4251 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004252 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004253
4254 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004255 f->mask = 0xF;
4256 adapter->num_rx_queues = f->indices;
4257 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004258 ret = true;
4259 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004260 ret = false;
4261 }
4262
4263 return ret;
4264}
4265
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004266/**
4267 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4268 * @adapter: board private structure to initialize
4269 *
4270 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4271 * to the original CPU that initiated the Tx session. This runs in addition
4272 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4273 * Rx load across CPUs using RSS.
4274 *
4275 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004276static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004277{
4278 bool ret = false;
4279 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4280
4281 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4282 f_fdir->mask = 0;
4283
4284 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004285 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4286 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004287 adapter->num_tx_queues = f_fdir->indices;
4288 adapter->num_rx_queues = f_fdir->indices;
4289 ret = true;
4290 } else {
4291 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004292 }
4293 return ret;
4294}
4295
Yi Zou0331a832009-05-17 12:33:52 +00004296#ifdef IXGBE_FCOE
4297/**
4298 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4299 * @adapter: board private structure to initialize
4300 *
4301 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4302 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4303 * rx queues out of the max number of rx queues, instead, it is used as the
4304 * index of the first rx queue used by FCoE.
4305 *
4306 **/
4307static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4308{
Yi Zou0331a832009-05-17 12:33:52 +00004309 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4310
John Fastabende5b64632011-03-08 03:44:52 +00004311 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4312 return false;
4313
John Fastabende901acd2011-04-26 07:26:08 +00004314 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004315
John Fastabende901acd2011-04-26 07:26:08 +00004316 adapter->num_rx_queues = 1;
4317 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004318
John Fastabende901acd2011-04-26 07:26:08 +00004319 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4320 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004321 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004322 ixgbe_set_fdir_queues(adapter);
4323 else
4324 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004325 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004326
John Fastabende901acd2011-04-26 07:26:08 +00004327 /* adding FCoE rx rings to the end */
4328 f->mask = adapter->num_rx_queues;
4329 adapter->num_rx_queues += f->indices;
4330 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004331
John Fastabende5b64632011-03-08 03:44:52 +00004332 return true;
4333}
4334#endif /* IXGBE_FCOE */
4335
John Fastabende901acd2011-04-26 07:26:08 +00004336/* Artificial max queue cap per traffic class in DCB mode */
4337#define DCB_QUEUE_CAP 8
4338
John Fastabende5b64632011-03-08 03:44:52 +00004339#ifdef CONFIG_IXGBE_DCB
4340static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4341{
John Fastabende901acd2011-04-26 07:26:08 +00004342 int per_tc_q, q, i, offset = 0;
4343 struct net_device *dev = adapter->netdev;
4344 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004345
John Fastabende901acd2011-04-26 07:26:08 +00004346 if (!tcs)
4347 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004348
John Fastabende901acd2011-04-26 07:26:08 +00004349 /* Map queue offset and counts onto allocated tx queues */
4350 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4351 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004352
John Fastabend8b1c0b22011-05-03 02:26:48 +00004353 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004354 netdev_set_prio_tc_map(dev, i, i);
4355 netdev_set_tc_queue(dev, i, q, offset);
4356 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004357 }
4358
John Fastabende901acd2011-04-26 07:26:08 +00004359 adapter->num_tx_queues = q * tcs;
4360 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004361
4362#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004363 /* FCoE enabled queues require special configuration indexed
4364 * by feature specific indices and mask. Here we map FCoE
4365 * indices onto the DCB queue pairs allowing FCoE to own
4366 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004367 */
John Fastabende901acd2011-04-26 07:26:08 +00004368 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4369 int tc;
4370 struct ixgbe_ring_feature *f =
4371 &adapter->ring_feature[RING_F_FCOE];
4372
4373 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4374 f->indices = dev->tc_to_txq[tc].count;
4375 f->mask = dev->tc_to_txq[tc].offset;
4376 }
John Fastabende5b64632011-03-08 03:44:52 +00004377#endif
4378
John Fastabende901acd2011-04-26 07:26:08 +00004379 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004380}
John Fastabende5b64632011-03-08 03:44:52 +00004381#endif
Yi Zou0331a832009-05-17 12:33:52 +00004382
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004383/**
4384 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4385 * @adapter: board private structure to initialize
4386 *
4387 * IOV doesn't actually use anything, so just NAK the
4388 * request for now and let the other queue routines
4389 * figure out what to do.
4390 */
4391static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4392{
4393 return false;
4394}
4395
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004396/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004397 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004398 * @adapter: board private structure to initialize
4399 *
4400 * This is the top level queue allocation routine. The order here is very
4401 * important, starting with the "most" number of features turned on at once,
4402 * and ending with the smallest set of features. This way large combinations
4403 * can be allocated if they're turned on, and smaller combinations are the
4404 * fallthrough conditions.
4405 *
4406 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004407static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004408{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004409 /* Start with base case */
4410 adapter->num_rx_queues = 1;
4411 adapter->num_tx_queues = 1;
4412 adapter->num_rx_pools = adapter->num_rx_queues;
4413 adapter->num_rx_queues_per_pool = 1;
4414
4415 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004416 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004417
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004418#ifdef CONFIG_IXGBE_DCB
4419 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004420 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004421
4422#endif
John Fastabende5b64632011-03-08 03:44:52 +00004423#ifdef IXGBE_FCOE
4424 if (ixgbe_set_fcoe_queues(adapter))
4425 goto done;
4426
4427#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004428 if (ixgbe_set_fdir_queues(adapter))
4429 goto done;
4430
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004431 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004432 goto done;
4433
4434 /* fallback to base case */
4435 adapter->num_rx_queues = 1;
4436 adapter->num_tx_queues = 1;
4437
4438done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004439 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004440 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004441 return netif_set_real_num_rx_queues(adapter->netdev,
4442 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004443}
4444
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004445static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004446 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004447{
4448 int err, vector_threshold;
4449
4450 /* We'll want at least 3 (vector_threshold):
4451 * 1) TxQ[0] Cleanup
4452 * 2) RxQ[0] Cleanup
4453 * 3) Other (Link Status Change, etc.)
4454 * 4) TCP Timer (optional)
4455 */
4456 vector_threshold = MIN_MSIX_COUNT;
4457
4458 /* The more we get, the more we will assign to Tx/Rx Cleanup
4459 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4460 * Right now, we simply care about how many we'll get; we'll
4461 * set them up later while requesting irq's.
4462 */
4463 while (vectors >= vector_threshold) {
4464 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004465 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004466 if (!err) /* Success in acquiring all requested vectors. */
4467 break;
4468 else if (err < 0)
4469 vectors = 0; /* Nasty failure, quit now */
4470 else /* err == number of vectors we should try again with */
4471 vectors = err;
4472 }
4473
4474 if (vectors < vector_threshold) {
4475 /* Can't allocate enough MSI-X interrupts? Oh well.
4476 * This just means we'll go with either a single MSI
4477 * vector or fall back to legacy interrupts.
4478 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004479 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4480 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004481 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4482 kfree(adapter->msix_entries);
4483 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004484 } else {
4485 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004486 /*
4487 * Adjust for only the vectors we'll use, which is minimum
4488 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4489 * vectors we were allocated.
4490 */
4491 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004492 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004493 }
4494}
4495
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004496/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004497 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004498 * @adapter: board private structure to initialize
4499 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004500 * Cache the descriptor ring offsets for RSS to the assigned rings.
4501 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004502 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004503static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004504{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004505 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004506
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004507 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4508 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004509
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004510 for (i = 0; i < adapter->num_rx_queues; i++)
4511 adapter->rx_ring[i]->reg_idx = i;
4512 for (i = 0; i < adapter->num_tx_queues; i++)
4513 adapter->tx_ring[i]->reg_idx = i;
4514
4515 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004516}
4517
4518#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004519
4520/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004521static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4522 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004523{
4524 struct net_device *dev = adapter->netdev;
4525 struct ixgbe_hw *hw = &adapter->hw;
4526 u8 num_tcs = netdev_get_num_tc(dev);
4527
4528 *tx = 0;
4529 *rx = 0;
4530
4531 switch (hw->mac.type) {
4532 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004533 *tx = tc << 2;
4534 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004535 break;
4536 case ixgbe_mac_82599EB:
4537 case ixgbe_mac_X540:
4538 if (num_tcs == 8) {
4539 if (tc < 3) {
4540 *tx = tc << 5;
4541 *rx = tc << 4;
4542 } else if (tc < 5) {
4543 *tx = ((tc + 2) << 4);
4544 *rx = tc << 4;
4545 } else if (tc < num_tcs) {
4546 *tx = ((tc + 8) << 3);
4547 *rx = tc << 4;
4548 }
4549 } else if (num_tcs == 4) {
4550 *rx = tc << 5;
4551 switch (tc) {
4552 case 0:
4553 *tx = 0;
4554 break;
4555 case 1:
4556 *tx = 64;
4557 break;
4558 case 2:
4559 *tx = 96;
4560 break;
4561 case 3:
4562 *tx = 112;
4563 break;
4564 default:
4565 break;
4566 }
4567 }
4568 break;
4569 default:
4570 break;
4571 }
4572}
4573
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004574/**
4575 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4576 * @adapter: board private structure to initialize
4577 *
4578 * Cache the descriptor ring offsets for DCB to the assigned rings.
4579 *
4580 **/
4581static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4582{
John Fastabende5b64632011-03-08 03:44:52 +00004583 struct net_device *dev = adapter->netdev;
4584 int i, j, k;
4585 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004586
John Fastabend8b1c0b22011-05-03 02:26:48 +00004587 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004588 return false;
4589
John Fastabende5b64632011-03-08 03:44:52 +00004590 for (i = 0, k = 0; i < num_tcs; i++) {
4591 unsigned int tx_s, rx_s;
4592 u16 count = dev->tc_to_txq[i].count;
4593
4594 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4595 for (j = 0; j < count; j++, k++) {
4596 adapter->tx_ring[k]->reg_idx = tx_s + j;
4597 adapter->rx_ring[k]->reg_idx = rx_s + j;
4598 adapter->tx_ring[k]->dcb_tc = i;
4599 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004600 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004601 }
John Fastabende5b64632011-03-08 03:44:52 +00004602
4603 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004604}
4605#endif
4606
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004607/**
4608 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4609 * @adapter: board private structure to initialize
4610 *
4611 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4612 *
4613 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004614static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004615{
4616 int i;
4617 bool ret = false;
4618
Alexander Duyck03ecf912011-05-20 07:36:17 +00004619 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4620 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004621 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004622 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004623 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004624 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004625 ret = true;
4626 }
4627
4628 return ret;
4629}
4630
Yi Zou0331a832009-05-17 12:33:52 +00004631#ifdef IXGBE_FCOE
4632/**
4633 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4634 * @adapter: board private structure to initialize
4635 *
4636 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4637 *
4638 */
4639static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4640{
Yi Zou0331a832009-05-17 12:33:52 +00004641 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004642 int i;
4643 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004644
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004645 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4646 return false;
4647
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004648 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004649 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004650 ixgbe_cache_ring_fdir(adapter);
4651 else
4652 ixgbe_cache_ring_rss(adapter);
4653
4654 fcoe_rx_i = f->mask;
4655 fcoe_tx_i = f->mask;
4656 }
4657 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4658 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4659 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4660 }
4661 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004662}
4663
4664#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004665/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004666 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4667 * @adapter: board private structure to initialize
4668 *
4669 * SR-IOV doesn't use any descriptor rings but changes the default if
4670 * no other mapping is used.
4671 *
4672 */
4673static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4674{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004675 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4676 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004677 if (adapter->num_vfs)
4678 return true;
4679 else
4680 return false;
4681}
4682
4683/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004684 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4685 * @adapter: board private structure to initialize
4686 *
4687 * Once we know the feature-set enabled for the device, we'll cache
4688 * the register offset the descriptor ring is assigned to.
4689 *
4690 * Note, the order the various feature calls is important. It must start with
4691 * the "most" features enabled at the same time, then trickle down to the
4692 * least amount of features turned on at once.
4693 **/
4694static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4695{
4696 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004697 adapter->rx_ring[0]->reg_idx = 0;
4698 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004699
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004700 if (ixgbe_cache_ring_sriov(adapter))
4701 return;
4702
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004703#ifdef CONFIG_IXGBE_DCB
4704 if (ixgbe_cache_ring_dcb(adapter))
4705 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004706#endif
John Fastabende5b64632011-03-08 03:44:52 +00004707
4708#ifdef IXGBE_FCOE
4709 if (ixgbe_cache_ring_fcoe(adapter))
4710 return;
4711#endif /* IXGBE_FCOE */
4712
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004713 if (ixgbe_cache_ring_fdir(adapter))
4714 return;
4715
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004716 if (ixgbe_cache_ring_rss(adapter))
4717 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004718}
4719
Auke Kok9a799d72007-09-15 14:07:45 -07004720/**
4721 * ixgbe_alloc_queues - Allocate memory for all rings
4722 * @adapter: board private structure to initialize
4723 *
4724 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004725 * number of queues at compile-time. The polling_netdev array is
4726 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004727 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004728static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004729{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004730 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004731
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004732 if (nid < 0 || !node_online(nid))
4733 nid = first_online_node;
4734
4735 for (; tx < adapter->num_tx_queues; tx++) {
4736 struct ixgbe_ring *ring;
4737
4738 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004739 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004740 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004741 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004742 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004743 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004744 ring->queue_index = tx;
4745 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004746 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004747 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004748
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004749 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004750 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004751
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004752 for (; rx < adapter->num_rx_queues; rx++) {
4753 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004754
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004755 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004756 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004757 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004758 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004759 goto err_allocation;
4760 ring->count = adapter->rx_ring_count;
4761 ring->queue_index = rx;
4762 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004763 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004764 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004765
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004766 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004767 }
4768
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004769 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004770
4771 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004772
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004773err_allocation:
4774 while (tx)
4775 kfree(adapter->tx_ring[--tx]);
4776
4777 while (rx)
4778 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004779 return -ENOMEM;
4780}
4781
4782/**
4783 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4784 * @adapter: board private structure to initialize
4785 *
4786 * Attempt to configure the interrupts using the best available
4787 * capabilities of the hardware and the kernel.
4788 **/
Al Virofeea6a52008-11-27 15:34:07 -08004789static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004790{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004791 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004792 int err = 0;
4793 int vector, v_budget;
4794
4795 /*
4796 * It's easy to be greedy for MSI-X vectors, but it really
4797 * doesn't do us much good if we have a lot more vectors
4798 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004799 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004800 */
4801 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004802 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004803
4804 /*
4805 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004806 * hw.mac->max_msix_vectors vectors. With features
4807 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4808 * descriptor queues supported by our device. Thus, we cap it off in
4809 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004810 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004811 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004812
4813 /* A failure in MSI-X entry allocation isn't fatal, but it does
4814 * mean we disable MSI-X capabilities of the adapter. */
4815 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004816 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004817 if (adapter->msix_entries) {
4818 for (vector = 0; vector < v_budget; vector++)
4819 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004820
Alexander Duyck7a921c92009-05-06 10:43:28 +00004821 ixgbe_acquire_msix_vectors(adapter, v_budget);
4822
4823 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4824 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004825 }
David S. Miller26d27842010-05-03 15:18:22 -07004826
Alexander Duyck7a921c92009-05-06 10:43:28 +00004827 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4828 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004829 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004830 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004831 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004832 "queues are disabled. Disabling Flow Director\n");
4833 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004834 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004835 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004836 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4837 ixgbe_disable_sriov(adapter);
4838
Ben Hutchings847f53f2010-09-27 08:28:56 +00004839 err = ixgbe_set_num_queues(adapter);
4840 if (err)
4841 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004843 err = pci_enable_msi(adapter->pdev);
4844 if (!err) {
4845 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4846 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004847 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4848 "Unable to allocate MSI interrupt, "
4849 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004850 /* reset err */
4851 err = 0;
4852 }
4853
4854out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004855 return err;
4856}
4857
Alexander Duyck7a921c92009-05-06 10:43:28 +00004858/**
4859 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4860 * @adapter: board private structure to initialize
4861 *
4862 * We allocate one q_vector per queue interrupt. If allocation fails we
4863 * return -ENOMEM.
4864 **/
4865static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4866{
4867 int q_idx, num_q_vectors;
4868 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004869 int (*poll)(struct napi_struct *, int);
4870
4871 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4872 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004873 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004874 } else {
4875 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004876 poll = &ixgbe_poll;
4877 }
4878
4879 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004880 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004881 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004882 if (!q_vector)
4883 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004884 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004885 if (!q_vector)
4886 goto err_out;
4887 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004888 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004889 q_vector->eitr = adapter->tx_eitr_param;
4890 else
4891 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004892 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004893 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004894 adapter->q_vector[q_idx] = q_vector;
4895 }
4896
4897 return 0;
4898
4899err_out:
4900 while (q_idx) {
4901 q_idx--;
4902 q_vector = adapter->q_vector[q_idx];
4903 netif_napi_del(&q_vector->napi);
4904 kfree(q_vector);
4905 adapter->q_vector[q_idx] = NULL;
4906 }
4907 return -ENOMEM;
4908}
4909
4910/**
4911 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4912 * @adapter: board private structure to initialize
4913 *
4914 * This function frees the memory allocated to the q_vectors. In addition if
4915 * NAPI is enabled it will delete any references to the NAPI struct prior
4916 * to freeing the q_vector.
4917 **/
4918static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4919{
4920 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004921
Alexander Duyck91281fd2009-06-04 16:00:27 +00004922 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004923 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004924 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004925 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004926
4927 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4928 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004929 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004930 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004931 kfree(q_vector);
4932 }
4933}
4934
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004935static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004936{
4937 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4938 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4939 pci_disable_msix(adapter->pdev);
4940 kfree(adapter->msix_entries);
4941 adapter->msix_entries = NULL;
4942 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4943 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4944 pci_disable_msi(adapter->pdev);
4945 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004946}
4947
4948/**
4949 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4950 * @adapter: board private structure to initialize
4951 *
4952 * We determine which interrupt scheme to use based on...
4953 * - Kernel support (MSI, MSI-X)
4954 * - which can be user-defined (via MODULE_PARAM)
4955 * - Hardware queue count (num_*_queues)
4956 * - defined by miscellaneous hardware support/features (RSS, etc.)
4957 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004958int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004959{
4960 int err;
4961
4962 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004963 err = ixgbe_set_num_queues(adapter);
4964 if (err)
4965 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004966
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004967 err = ixgbe_set_interrupt_capability(adapter);
4968 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004969 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004970 goto err_set_interrupt;
4971 }
4972
Alexander Duyck7a921c92009-05-06 10:43:28 +00004973 err = ixgbe_alloc_q_vectors(adapter);
4974 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004975 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004976 goto err_alloc_q_vectors;
4977 }
4978
4979 err = ixgbe_alloc_queues(adapter);
4980 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004981 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004982 goto err_alloc_queues;
4983 }
4984
Emil Tantilov849c4542010-06-03 16:53:41 +00004985 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00004986 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
4987 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004988
4989 set_bit(__IXGBE_DOWN, &adapter->state);
4990
4991 return 0;
4992
Alexander Duyck7a921c92009-05-06 10:43:28 +00004993err_alloc_queues:
4994 ixgbe_free_q_vectors(adapter);
4995err_alloc_q_vectors:
4996 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004997err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00004998 return err;
4999}
5000
5001/**
5002 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5003 * @adapter: board private structure to clear interrupt scheme on
5004 *
5005 * We go through and clear interrupt specific resources and reset the structure
5006 * to pre-load conditions
5007 **/
5008void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5009{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005010 int i;
5011
5012 for (i = 0; i < adapter->num_tx_queues; i++) {
5013 kfree(adapter->tx_ring[i]);
5014 adapter->tx_ring[i] = NULL;
5015 }
5016 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005017 struct ixgbe_ring *ring = adapter->rx_ring[i];
5018
5019 /* ixgbe_get_stats64() might access this ring, we must wait
5020 * a grace period before freeing it.
5021 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005022 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005023 adapter->rx_ring[i] = NULL;
5024 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005025
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005026 adapter->num_tx_queues = 0;
5027 adapter->num_rx_queues = 0;
5028
Alexander Duyck7a921c92009-05-06 10:43:28 +00005029 ixgbe_free_q_vectors(adapter);
5030 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005031}
5032
5033/**
5034 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5035 * @adapter: board private structure to initialize
5036 *
5037 * ixgbe_sw_init initializes the Adapter private data structure.
5038 * Fields are initialized based on PCI device information and
5039 * OS network device settings (MTU size).
5040 **/
5041static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5042{
5043 struct ixgbe_hw *hw = &adapter->hw;
5044 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005045 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005046 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005047#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005048 int j;
5049 struct tc_configuration *tc;
5050#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005051 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005052
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005053 /* PCI config space info */
5054
5055 hw->vendor_id = pdev->vendor;
5056 hw->device_id = pdev->device;
5057 hw->revision_id = pdev->revision;
5058 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5059 hw->subsystem_device_id = pdev->subsystem_device;
5060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005061 /* Set capability flags */
5062 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5063 adapter->ring_feature[RING_F_RSS].indices = rss;
5064 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005065 switch (hw->mac.type) {
5066 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005067 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5068 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005069 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005070 break;
5071 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005072 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005073 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005074 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5075 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005076 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5077 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005078 /* Flow Director hash filters enabled */
5079 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5080 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005081 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005082 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005083 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005084#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005085 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5086 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5087 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005088#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005089 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005090 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005091#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005092#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005093 break;
5094 default:
5095 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005096 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005097
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005098 /* n-tuple support exists, always init our spinlock */
5099 spin_lock_init(&adapter->fdir_perfect_lock);
5100
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005101#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005102 /* Configure DCB traffic classes */
5103 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5104 tc = &adapter->dcb_cfg.tc_config[j];
5105 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5106 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5107 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5108 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5109 tc->dcb_pfc = pfc_disabled;
5110 }
5111 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5112 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005113 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005114 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005115 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005116 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005117 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005118
5119#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005120
5121 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005122 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005123 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005124#ifdef CONFIG_DCB
5125 adapter->last_lfc_mode = hw->fc.current_mode;
5126#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005127 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5128 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005129 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5130 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005131 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005132
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005133 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005134 adapter->rx_itr_setting = 1;
5135 adapter->rx_eitr_param = 20000;
5136 adapter->tx_itr_setting = 1;
5137 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005138
5139 /* set defaults for eitr in MegaBytes */
5140 adapter->eitr_low = 10;
5141 adapter->eitr_high = 20;
5142
5143 /* set default ring sizes */
5144 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5145 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5146
Alexander Duyckbd198052011-06-11 01:45:08 +00005147 /* set default work limits */
5148 adapter->tx_work_limit = adapter->tx_ring_count;
5149
Auke Kok9a799d72007-09-15 14:07:45 -07005150 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005151 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005152 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005153 return -EIO;
5154 }
5155
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005156 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005157 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5158
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005159 /* get assigned NUMA node */
5160 adapter->node = dev_to_node(&pdev->dev);
5161
Auke Kok9a799d72007-09-15 14:07:45 -07005162 set_bit(__IXGBE_DOWN, &adapter->state);
5163
5164 return 0;
5165}
5166
5167/**
5168 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005169 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005170 *
5171 * Return 0 on success, negative on failure
5172 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005173int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005174{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005175 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005176 int size;
5177
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005178 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005179 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005180 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005181 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005182 if (!tx_ring->tx_buffer_info)
5183 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005184
5185 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005186 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005187 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005188
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005189 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005190 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005191 if (!tx_ring->desc)
5192 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005193
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005194 tx_ring->next_to_use = 0;
5195 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005196 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005197
5198err:
5199 vfree(tx_ring->tx_buffer_info);
5200 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005201 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005202 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005203}
5204
5205/**
Alexander Duyck69888672008-09-11 20:05:39 -07005206 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5207 * @adapter: board private structure
5208 *
5209 * If this function returns with an error, then it's possible one or
5210 * more of the rings is populated (while the rest are not). It is the
5211 * callers duty to clean those orphaned rings.
5212 *
5213 * Return 0 on success, negative on failure
5214 **/
5215static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5216{
5217 int i, err = 0;
5218
5219 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005220 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005221 if (!err)
5222 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005223 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005224 break;
5225 }
5226
5227 return err;
5228}
5229
5230/**
Auke Kok9a799d72007-09-15 14:07:45 -07005231 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005232 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005233 *
5234 * Returns 0 on success, negative on failure
5235 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005236int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005237{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005238 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005239 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005240
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005241 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005242 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005243 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005244 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005245 if (!rx_ring->rx_buffer_info)
5246 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005247
Auke Kok9a799d72007-09-15 14:07:45 -07005248 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005249 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5250 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005251
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005252 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005253 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005254
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005255 if (!rx_ring->desc)
5256 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005257
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005258 rx_ring->next_to_clean = 0;
5259 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005260
5261 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005262err:
5263 vfree(rx_ring->rx_buffer_info);
5264 rx_ring->rx_buffer_info = NULL;
5265 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005266 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005267}
5268
5269/**
Alexander Duyck69888672008-09-11 20:05:39 -07005270 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5271 * @adapter: board private structure
5272 *
5273 * If this function returns with an error, then it's possible one or
5274 * more of the rings is populated (while the rest are not). It is the
5275 * callers duty to clean those orphaned rings.
5276 *
5277 * Return 0 on success, negative on failure
5278 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005279static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5280{
5281 int i, err = 0;
5282
5283 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005284 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005285 if (!err)
5286 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005287 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005288 break;
5289 }
5290
5291 return err;
5292}
5293
5294/**
Auke Kok9a799d72007-09-15 14:07:45 -07005295 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005296 * @tx_ring: Tx descriptor ring for a specific queue
5297 *
5298 * Free all transmit software resources
5299 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005300void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005301{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005302 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005303
5304 vfree(tx_ring->tx_buffer_info);
5305 tx_ring->tx_buffer_info = NULL;
5306
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005307 /* if not set, then don't free */
5308 if (!tx_ring->desc)
5309 return;
5310
5311 dma_free_coherent(tx_ring->dev, tx_ring->size,
5312 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005313
5314 tx_ring->desc = NULL;
5315}
5316
5317/**
5318 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5319 * @adapter: board private structure
5320 *
5321 * Free all transmit software resources
5322 **/
5323static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5324{
5325 int i;
5326
5327 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005328 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005329 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005330}
5331
5332/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005333 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005334 * @rx_ring: ring to clean the resources from
5335 *
5336 * Free all receive software resources
5337 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005338void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005339{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005340 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005341
5342 vfree(rx_ring->rx_buffer_info);
5343 rx_ring->rx_buffer_info = NULL;
5344
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005345 /* if not set, then don't free */
5346 if (!rx_ring->desc)
5347 return;
5348
5349 dma_free_coherent(rx_ring->dev, rx_ring->size,
5350 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005351
5352 rx_ring->desc = NULL;
5353}
5354
5355/**
5356 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5357 * @adapter: board private structure
5358 *
5359 * Free all receive software resources
5360 **/
5361static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5362{
5363 int i;
5364
5365 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005366 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005367 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005368}
5369
5370/**
Auke Kok9a799d72007-09-15 14:07:45 -07005371 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5372 * @netdev: network interface device structure
5373 * @new_mtu: new value for maximum frame size
5374 *
5375 * Returns 0 on success, negative on failure
5376 **/
5377static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5378{
5379 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005380 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005381 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5382
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005383 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005384 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5385 hw->mac.type != ixgbe_mac_X540) {
5386 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5387 return -EINVAL;
5388 } else {
5389 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5390 return -EINVAL;
5391 }
Auke Kok9a799d72007-09-15 14:07:45 -07005392
Emil Tantilov396e7992010-07-01 20:05:12 +00005393 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005394 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005395 netdev->mtu = new_mtu;
5396
John Fastabend16b61be2010-11-16 19:26:44 -08005397 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5398 hw->fc.low_water = FC_LOW_WATER(max_frame);
5399
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005400 if (netif_running(netdev))
5401 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005402
5403 return 0;
5404}
5405
5406/**
5407 * ixgbe_open - Called when a network interface is made active
5408 * @netdev: network interface device structure
5409 *
5410 * Returns 0 on success, negative value on failure
5411 *
5412 * The open entry point is called when a network interface is made
5413 * active by the system (IFF_UP). At this point all resources needed
5414 * for transmit and receive operations are allocated, the interrupt
5415 * handler is registered with the OS, the watchdog timer is started,
5416 * and the stack is notified that the interface is ready.
5417 **/
5418static int ixgbe_open(struct net_device *netdev)
5419{
5420 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5421 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005422
Auke Kok4bebfaa2008-02-11 09:26:01 -08005423 /* disallow open during test */
5424 if (test_bit(__IXGBE_TESTING, &adapter->state))
5425 return -EBUSY;
5426
Jesse Brandeburg54386462009-04-17 20:44:27 +00005427 netif_carrier_off(netdev);
5428
Auke Kok9a799d72007-09-15 14:07:45 -07005429 /* allocate transmit descriptors */
5430 err = ixgbe_setup_all_tx_resources(adapter);
5431 if (err)
5432 goto err_setup_tx;
5433
Auke Kok9a799d72007-09-15 14:07:45 -07005434 /* allocate receive descriptors */
5435 err = ixgbe_setup_all_rx_resources(adapter);
5436 if (err)
5437 goto err_setup_rx;
5438
5439 ixgbe_configure(adapter);
5440
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005441 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005442 if (err)
5443 goto err_req_irq;
5444
Auke Kok9a799d72007-09-15 14:07:45 -07005445 err = ixgbe_up_complete(adapter);
5446 if (err)
5447 goto err_up;
5448
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005449 netif_tx_start_all_queues(netdev);
5450
Auke Kok9a799d72007-09-15 14:07:45 -07005451 return 0;
5452
5453err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005454 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005455 ixgbe_free_irq(adapter);
5456err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005457err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005458 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005459err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005460 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005461 ixgbe_reset(adapter);
5462
5463 return err;
5464}
5465
5466/**
5467 * ixgbe_close - Disables a network interface
5468 * @netdev: network interface device structure
5469 *
5470 * Returns 0, this is not allowed to fail
5471 *
5472 * The close entry point is called when an interface is de-activated
5473 * by the OS. The hardware is still under the drivers control, but
5474 * needs to be disabled. A global MAC reset is issued to stop the
5475 * hardware, and all transmit and receive resources are freed.
5476 **/
5477static int ixgbe_close(struct net_device *netdev)
5478{
5479 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005480
5481 ixgbe_down(adapter);
5482 ixgbe_free_irq(adapter);
5483
Alexander Duycke4911d52011-05-11 07:18:52 +00005484 ixgbe_fdir_filter_exit(adapter);
5485
Auke Kok9a799d72007-09-15 14:07:45 -07005486 ixgbe_free_all_tx_resources(adapter);
5487 ixgbe_free_all_rx_resources(adapter);
5488
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005489 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005490
5491 return 0;
5492}
5493
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005494#ifdef CONFIG_PM
5495static int ixgbe_resume(struct pci_dev *pdev)
5496{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005497 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5498 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005499 u32 err;
5500
5501 pci_set_power_state(pdev, PCI_D0);
5502 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005503 /*
5504 * pci_restore_state clears dev->state_saved so call
5505 * pci_save_state to restore it.
5506 */
5507 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005508
5509 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005510 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005511 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005512 return err;
5513 }
5514 pci_set_master(pdev);
5515
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005516 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005517
5518 err = ixgbe_init_interrupt_scheme(adapter);
5519 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005520 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005521 return err;
5522 }
5523
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005524 ixgbe_reset(adapter);
5525
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005526 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5527
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005528 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005529 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005530 if (err)
5531 return err;
5532 }
5533
5534 netif_device_attach(netdev);
5535
5536 return 0;
5537}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005538#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005539
5540static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005541{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005542 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5543 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005544 struct ixgbe_hw *hw = &adapter->hw;
5545 u32 ctrl, fctrl;
5546 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005547#ifdef CONFIG_PM
5548 int retval = 0;
5549#endif
5550
5551 netif_device_detach(netdev);
5552
5553 if (netif_running(netdev)) {
5554 ixgbe_down(adapter);
5555 ixgbe_free_irq(adapter);
5556 ixgbe_free_all_tx_resources(adapter);
5557 ixgbe_free_all_rx_resources(adapter);
5558 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005559
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005560 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005561#ifdef CONFIG_DCB
5562 kfree(adapter->ixgbe_ieee_pfc);
5563 kfree(adapter->ixgbe_ieee_ets);
5564#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005565
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005566#ifdef CONFIG_PM
5567 retval = pci_save_state(pdev);
5568 if (retval)
5569 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005570
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005571#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005572 if (wufc) {
5573 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005574
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005575 /* turn on all-multi mode if wake on multicast is enabled */
5576 if (wufc & IXGBE_WUFC_MC) {
5577 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5578 fctrl |= IXGBE_FCTRL_MPE;
5579 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5580 }
5581
5582 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5583 ctrl |= IXGBE_CTRL_GIO_DIS;
5584 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5585
5586 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5587 } else {
5588 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5589 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5590 }
5591
Alexander Duyckbd508172010-11-16 19:27:03 -08005592 switch (hw->mac.type) {
5593 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005594 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005595 break;
5596 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005597 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005598 pci_wake_from_d3(pdev, !!wufc);
5599 break;
5600 default:
5601 break;
5602 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005603
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005604 *enable_wake = !!wufc;
5605
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005606 ixgbe_release_hw_control(adapter);
5607
5608 pci_disable_device(pdev);
5609
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005610 return 0;
5611}
5612
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005613#ifdef CONFIG_PM
5614static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5615{
5616 int retval;
5617 bool wake;
5618
5619 retval = __ixgbe_shutdown(pdev, &wake);
5620 if (retval)
5621 return retval;
5622
5623 if (wake) {
5624 pci_prepare_to_sleep(pdev);
5625 } else {
5626 pci_wake_from_d3(pdev, false);
5627 pci_set_power_state(pdev, PCI_D3hot);
5628 }
5629
5630 return 0;
5631}
5632#endif /* CONFIG_PM */
5633
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005634static void ixgbe_shutdown(struct pci_dev *pdev)
5635{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005636 bool wake;
5637
5638 __ixgbe_shutdown(pdev, &wake);
5639
5640 if (system_state == SYSTEM_POWER_OFF) {
5641 pci_wake_from_d3(pdev, wake);
5642 pci_set_power_state(pdev, PCI_D3hot);
5643 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005644}
5645
5646/**
Auke Kok9a799d72007-09-15 14:07:45 -07005647 * ixgbe_update_stats - Update the board statistics counters.
5648 * @adapter: board private structure
5649 **/
5650void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5651{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005652 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005653 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005654 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005655 u64 total_mpc = 0;
5656 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005657 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5658 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5659 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005660
Don Skidmored08935c2010-06-11 13:20:29 +00005661 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5662 test_bit(__IXGBE_RESETTING, &adapter->state))
5663 return;
5664
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005665 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005666 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005667 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005668 for (i = 0; i < 16; i++)
5669 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005670 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005671 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005672 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5673 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005674 }
5675 adapter->rsc_total_count = rsc_count;
5676 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005677 }
5678
Alexander Duyck5b7da512010-11-16 19:26:50 -08005679 for (i = 0; i < adapter->num_rx_queues; i++) {
5680 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5681 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5682 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5683 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5684 bytes += rx_ring->stats.bytes;
5685 packets += rx_ring->stats.packets;
5686 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005687 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005688 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5689 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5690 netdev->stats.rx_bytes = bytes;
5691 netdev->stats.rx_packets = packets;
5692
5693 bytes = 0;
5694 packets = 0;
5695 /* gather some stats to the adapter struct that are per queue */
5696 for (i = 0; i < adapter->num_tx_queues; i++) {
5697 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5698 restart_queue += tx_ring->tx_stats.restart_queue;
5699 tx_busy += tx_ring->tx_stats.tx_busy;
5700 bytes += tx_ring->stats.bytes;
5701 packets += tx_ring->stats.packets;
5702 }
5703 adapter->restart_queue = restart_queue;
5704 adapter->tx_busy = tx_busy;
5705 netdev->stats.tx_bytes = bytes;
5706 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005707
Joe Perches7ca647b2010-09-07 21:35:40 +00005708 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005709 for (i = 0; i < 8; i++) {
5710 /* for packet buffers not used, the register should read 0 */
5711 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5712 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005713 hwstats->mpc[i] += mpc;
5714 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005715 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005716 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5717 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5718 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5719 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5720 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005721 switch (hw->mac.type) {
5722 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005723 hwstats->pxonrxc[i] +=
5724 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005725 break;
5726 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005727 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005728 hwstats->pxonrxc[i] +=
5729 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005730 break;
5731 default:
5732 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005733 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005734 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5735 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005736 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005737 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005738 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005739 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005740
John Fastabendc84d3242010-11-16 19:27:12 -08005741 ixgbe_update_xoff_received(adapter);
5742
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005743 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005744 switch (hw->mac.type) {
5745 case ixgbe_mac_82598EB:
5746 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005747 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5748 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5749 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5750 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005751 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005752 /* OS2BMC stats are X540 only*/
5753 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5754 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5755 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5756 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5757 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005758 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005759 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005760 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005761 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005762 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005763 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005764 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005765 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5766 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005767#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005768 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5769 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5770 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5771 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5772 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5773 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005774#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005775 break;
5776 default:
5777 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005778 }
Auke Kok9a799d72007-09-15 14:07:45 -07005779 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005780 hwstats->bprc += bprc;
5781 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005782 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005783 hwstats->mprc -= bprc;
5784 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5785 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5786 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5787 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5788 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5789 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5790 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5791 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005792 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005793 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005794 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005795 hwstats->lxofftxc += lxoff;
5796 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5797 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5798 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005799 /*
5800 * 82598 errata - tx of flow control packets is included in tx counters
5801 */
5802 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005803 hwstats->gptc -= xon_off_tot;
5804 hwstats->mptc -= xon_off_tot;
5805 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5806 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5807 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5808 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5809 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5810 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5811 hwstats->ptc64 -= xon_off_tot;
5812 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5813 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5814 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5815 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5816 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5817 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005818
5819 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005820 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005821
5822 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005823 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005824 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005825 netdev->stats.rx_length_errors = hwstats->rlec;
5826 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005827 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005828}
5829
5830/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005831 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5832 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005833 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005834static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005835{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005836 struct ixgbe_hw *hw = &adapter->hw;
5837 int i;
5838
Alexander Duyckd034acf2011-04-27 09:25:34 +00005839 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5840 return;
5841
5842 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5843
5844 /* if interface is down do nothing */
5845 if (test_bit(__IXGBE_DOWN, &adapter->state))
5846 return;
5847
5848 /* do nothing if we are not using signature filters */
5849 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5850 return;
5851
5852 adapter->fdir_overflow++;
5853
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005854 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5855 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005856 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005857 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005858 /* re-enable flow director interrupts */
5859 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005860 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005861 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005862 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005863 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005864}
5865
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005866/**
5867 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5868 * @adapter - pointer to the device adapter structure
5869 *
5870 * This function serves two purposes. First it strobes the interrupt lines
5871 * in order to make certain interrupts are occuring. Secondly it sets the
5872 * bits needed to check for TX hangs. As a result we should immediately
5873 * determine if a hang has occured.
5874 */
5875static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5876{
Auke Kok9a799d72007-09-15 14:07:45 -07005877 struct ixgbe_hw *hw = &adapter->hw;
5878 u64 eics = 0;
5879 int i;
5880
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005881 /* If we're down or resetting, just bail */
5882 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5883 test_bit(__IXGBE_RESETTING, &adapter->state))
5884 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005885
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005886 /* Force detection of hung controller */
5887 if (netif_carrier_ok(adapter->netdev)) {
5888 for (i = 0; i < adapter->num_tx_queues; i++)
5889 set_check_for_tx_hang(adapter->tx_ring[i]);
5890 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005891
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005892 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005893 /*
5894 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005895 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005896 * would set *both* EIMS and EICS for any bit in EIAM
5897 */
5898 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5899 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005900 } else {
5901 /* get one bit for every active tx/rx interrupt vector */
5902 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5903 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005904 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005905 eics |= ((u64)1 << i);
5906 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005907 }
5908
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005909 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005910 ixgbe_irq_rearm_queues(adapter, eics);
5911
Alexander Duyckfe49f042009-06-04 16:00:09 +00005912}
5913
5914/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005915 * ixgbe_watchdog_update_link - update the link status
5916 * @adapter - pointer to the device adapter structure
5917 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005918 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005919static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005920{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005921 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005922 u32 link_speed = adapter->link_speed;
5923 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005924 int i;
5925
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005926 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5927 return;
5928
5929 if (hw->mac.ops.check_link) {
5930 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005931 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005932 /* always assume link is up, if no check link function */
5933 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5934 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005935 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005936 if (link_up) {
5937 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5938 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5939 hw->mac.ops.fc_enable(hw, i);
5940 } else {
5941 hw->mac.ops.fc_enable(hw, 0);
5942 }
5943 }
5944
5945 if (link_up ||
5946 time_after(jiffies, (adapter->link_check_timeout +
5947 IXGBE_TRY_LINK_TIMEOUT))) {
5948 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5949 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5950 IXGBE_WRITE_FLUSH(hw);
5951 }
5952
5953 adapter->link_up = link_up;
5954 adapter->link_speed = link_speed;
5955}
5956
5957/**
5958 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5959 * print link up message
5960 * @adapter - pointer to the device adapter structure
5961 **/
5962static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5963{
5964 struct net_device *netdev = adapter->netdev;
5965 struct ixgbe_hw *hw = &adapter->hw;
5966 u32 link_speed = adapter->link_speed;
5967 bool flow_rx, flow_tx;
5968
5969 /* only continue if link was previously down */
5970 if (netif_carrier_ok(netdev))
5971 return;
5972
5973 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5974
5975 switch (hw->mac.type) {
5976 case ixgbe_mac_82598EB: {
5977 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5978 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5979 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5980 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5981 }
5982 break;
5983 case ixgbe_mac_X540:
5984 case ixgbe_mac_82599EB: {
5985 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
5986 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
5987 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
5988 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
5989 }
5990 break;
5991 default:
5992 flow_tx = false;
5993 flow_rx = false;
5994 break;
5995 }
5996 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
5997 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
5998 "10 Gbps" :
5999 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6000 "1 Gbps" :
6001 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6002 "100 Mbps" :
6003 "unknown speed"))),
6004 ((flow_rx && flow_tx) ? "RX/TX" :
6005 (flow_rx ? "RX" :
6006 (flow_tx ? "TX" : "None"))));
6007
6008 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006009 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006010}
6011
6012/**
6013 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6014 * print link down message
6015 * @adapter - pointer to the adapter structure
6016 **/
6017static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6018{
6019 struct net_device *netdev = adapter->netdev;
6020 struct ixgbe_hw *hw = &adapter->hw;
6021
6022 adapter->link_up = false;
6023 adapter->link_speed = 0;
6024
6025 /* only continue if link was up previously */
6026 if (!netif_carrier_ok(netdev))
6027 return;
6028
6029 /* poll for SFP+ cable when link is down */
6030 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6031 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6032
6033 e_info(drv, "NIC Link is Down\n");
6034 netif_carrier_off(netdev);
6035}
6036
6037/**
6038 * ixgbe_watchdog_flush_tx - flush queues on link down
6039 * @adapter - pointer to the device adapter structure
6040 **/
6041static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6042{
6043 int i;
6044 int some_tx_pending = 0;
6045
6046 if (!netif_carrier_ok(adapter->netdev)) {
6047 for (i = 0; i < adapter->num_tx_queues; i++) {
6048 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6049 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6050 some_tx_pending = 1;
6051 break;
6052 }
6053 }
6054
6055 if (some_tx_pending) {
6056 /* We've lost link, so the controller stops DMA,
6057 * but we've got queued Tx work that's never going
6058 * to get done, so reset controller to flush Tx.
6059 * (Do the reset outside of interrupt context).
6060 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006061 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006062 }
6063 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006064}
6065
Greg Rosea985b6c32010-11-18 03:02:52 +00006066static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6067{
6068 u32 ssvpc;
6069
6070 /* Do not perform spoof check for 82598 */
6071 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6072 return;
6073
6074 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6075
6076 /*
6077 * ssvpc register is cleared on read, if zero then no
6078 * spoofed packets in the last interval.
6079 */
6080 if (!ssvpc)
6081 return;
6082
6083 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6084}
6085
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006086/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006087 * ixgbe_watchdog_subtask - check and bring link up
6088 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006089 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006090static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006091{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006092 /* if interface is down do nothing */
6093 if (test_bit(__IXGBE_DOWN, &adapter->state))
6094 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006095
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006096 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006097
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006098 if (adapter->link_up)
6099 ixgbe_watchdog_link_is_up(adapter);
6100 else
6101 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006102
Greg Rosea985b6c32010-11-18 03:02:52 +00006103 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006104 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006105
6106 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006107}
6108
Alexander Duyck70864002011-04-27 09:13:56 +00006109/**
6110 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6111 * @adapter - the ixgbe adapter structure
6112 **/
6113static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6114{
6115 struct ixgbe_hw *hw = &adapter->hw;
6116 s32 err;
6117
6118 /* not searching for SFP so there is nothing to do here */
6119 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6120 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6121 return;
6122
6123 /* someone else is in init, wait until next service event */
6124 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6125 return;
6126
6127 err = hw->phy.ops.identify_sfp(hw);
6128 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6129 goto sfp_out;
6130
6131 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6132 /* If no cable is present, then we need to reset
6133 * the next time we find a good cable. */
6134 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6135 }
6136
6137 /* exit on error */
6138 if (err)
6139 goto sfp_out;
6140
6141 /* exit if reset not needed */
6142 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6143 goto sfp_out;
6144
6145 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6146
6147 /*
6148 * A module may be identified correctly, but the EEPROM may not have
6149 * support for that module. setup_sfp() will fail in that case, so
6150 * we should not allow that module to load.
6151 */
6152 if (hw->mac.type == ixgbe_mac_82598EB)
6153 err = hw->phy.ops.reset(hw);
6154 else
6155 err = hw->mac.ops.setup_sfp(hw);
6156
6157 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6158 goto sfp_out;
6159
6160 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6161 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6162
6163sfp_out:
6164 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6165
6166 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6167 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6168 e_dev_err("failed to initialize because an unsupported "
6169 "SFP+ module type was detected.\n");
6170 e_dev_err("Reload the driver after installing a "
6171 "supported module.\n");
6172 unregister_netdev(adapter->netdev);
6173 }
6174}
6175
6176/**
6177 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6178 * @adapter - the ixgbe adapter structure
6179 **/
6180static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6181{
6182 struct ixgbe_hw *hw = &adapter->hw;
6183 u32 autoneg;
6184 bool negotiation;
6185
6186 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6187 return;
6188
6189 /* someone else is in init, wait until next service event */
6190 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6191 return;
6192
6193 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6194
6195 autoneg = hw->phy.autoneg_advertised;
6196 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6197 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6198 hw->mac.autotry_restart = false;
6199 if (hw->mac.ops.setup_link)
6200 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6201
6202 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6203 adapter->link_check_timeout = jiffies;
6204 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6205}
6206
6207/**
6208 * ixgbe_service_timer - Timer Call-back
6209 * @data: pointer to adapter cast into an unsigned long
6210 **/
6211static void ixgbe_service_timer(unsigned long data)
6212{
6213 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6214 unsigned long next_event_offset;
6215
6216 /* poll faster when waiting for link */
6217 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6218 next_event_offset = HZ / 10;
6219 else
6220 next_event_offset = HZ * 2;
6221
6222 /* Reset the timer */
6223 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6224
6225 ixgbe_service_event_schedule(adapter);
6226}
6227
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006228static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6229{
6230 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6231 return;
6232
6233 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6234
6235 /* If we're already down or resetting, just bail */
6236 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6237 test_bit(__IXGBE_RESETTING, &adapter->state))
6238 return;
6239
6240 ixgbe_dump(adapter);
6241 netdev_err(adapter->netdev, "Reset adapter\n");
6242 adapter->tx_timeout_count++;
6243
6244 ixgbe_reinit_locked(adapter);
6245}
6246
Alexander Duyck70864002011-04-27 09:13:56 +00006247/**
6248 * ixgbe_service_task - manages and runs subtasks
6249 * @work: pointer to work_struct containing our data
6250 **/
6251static void ixgbe_service_task(struct work_struct *work)
6252{
6253 struct ixgbe_adapter *adapter = container_of(work,
6254 struct ixgbe_adapter,
6255 service_task);
6256
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006257 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006258 ixgbe_sfp_detection_subtask(adapter);
6259 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006260 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006261 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006262 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006263 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006264
6265 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006266}
6267
Alexander Duyck897ab152011-05-27 05:31:47 +00006268void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6269 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006270{
6271 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006272 u16 i = tx_ring->next_to_use;
6273
6274 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6275
6276 i++;
6277 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6278
6279 /* set bits to identify this as an advanced context descriptor */
6280 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6281
6282 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6283 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6284 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6285 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6286}
6287
6288static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6289 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6290{
Auke Kok9a799d72007-09-15 14:07:45 -07006291 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006292 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006293 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006294
Alexander Duyck897ab152011-05-27 05:31:47 +00006295 if (!skb_is_gso(skb))
6296 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006297
Alexander Duyck897ab152011-05-27 05:31:47 +00006298 if (skb_header_cloned(skb)) {
6299 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6300 if (err)
6301 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006302 }
6303
Alexander Duyck897ab152011-05-27 05:31:47 +00006304 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6305 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6306
6307 if (protocol == __constant_htons(ETH_P_IP)) {
6308 struct iphdr *iph = ip_hdr(skb);
6309 iph->tot_len = 0;
6310 iph->check = 0;
6311 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6312 iph->daddr, 0,
6313 IPPROTO_TCP,
6314 0);
6315 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6316 } else if (skb_is_gso_v6(skb)) {
6317 ipv6_hdr(skb)->payload_len = 0;
6318 tcp_hdr(skb)->check =
6319 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6320 &ipv6_hdr(skb)->daddr,
6321 0, IPPROTO_TCP, 0);
6322 }
6323
6324 l4len = tcp_hdrlen(skb);
6325 *hdr_len = skb_transport_offset(skb) + l4len;
6326
6327 /* mss_l4len_id: use 1 as index for TSO */
6328 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6329 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6330 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6331
6332 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6333 vlan_macip_lens = skb_network_header_len(skb);
6334 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6335 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6336
6337 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6338 mss_l4len_idx);
6339
6340 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006341}
6342
Alexander Duyck897ab152011-05-27 05:31:47 +00006343static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006344 struct sk_buff *skb, u32 tx_flags,
6345 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006346{
Alexander Duyck897ab152011-05-27 05:31:47 +00006347 u32 vlan_macip_lens = 0;
6348 u32 mss_l4len_idx = 0;
6349 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006350
Alexander Duyck897ab152011-05-27 05:31:47 +00006351 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6352 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6353 return false;
6354 } else {
6355 u8 l4_hdr = 0;
6356 switch (protocol) {
6357 case __constant_htons(ETH_P_IP):
6358 vlan_macip_lens |= skb_network_header_len(skb);
6359 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6360 l4_hdr = ip_hdr(skb)->protocol;
6361 break;
6362 case __constant_htons(ETH_P_IPV6):
6363 vlan_macip_lens |= skb_network_header_len(skb);
6364 l4_hdr = ipv6_hdr(skb)->nexthdr;
6365 break;
6366 default:
6367 if (unlikely(net_ratelimit())) {
6368 dev_warn(tx_ring->dev,
6369 "partial checksum but proto=%x!\n",
6370 skb->protocol);
6371 }
6372 break;
6373 }
Auke Kok9a799d72007-09-15 14:07:45 -07006374
Alexander Duyck897ab152011-05-27 05:31:47 +00006375 switch (l4_hdr) {
6376 case IPPROTO_TCP:
6377 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6378 mss_l4len_idx = tcp_hdrlen(skb) <<
6379 IXGBE_ADVTXD_L4LEN_SHIFT;
6380 break;
6381 case IPPROTO_SCTP:
6382 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6383 mss_l4len_idx = sizeof(struct sctphdr) <<
6384 IXGBE_ADVTXD_L4LEN_SHIFT;
6385 break;
6386 case IPPROTO_UDP:
6387 mss_l4len_idx = sizeof(struct udphdr) <<
6388 IXGBE_ADVTXD_L4LEN_SHIFT;
6389 break;
6390 default:
6391 if (unlikely(net_ratelimit())) {
6392 dev_warn(tx_ring->dev,
6393 "partial checksum but l4 proto=%x!\n",
6394 skb->protocol);
6395 }
6396 break;
6397 }
Auke Kok9a799d72007-09-15 14:07:45 -07006398 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006399
Alexander Duyck897ab152011-05-27 05:31:47 +00006400 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6401 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6402
6403 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6404 type_tucmd, mss_l4len_idx);
6405
6406 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006407}
6408
6409static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006410 struct ixgbe_ring *tx_ring,
6411 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006412 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006413{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006414 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006415 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006416 unsigned int len;
6417 unsigned int total = skb->len;
Alexander Duyck63544e92011-05-27 05:31:42 +00006418 unsigned int offset = 0, size, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006419 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6420 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006421 unsigned int bytecount = skb->len;
6422 u16 gso_segs = 1;
Alexander Duyck63544e92011-05-27 05:31:42 +00006423 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07006424
6425 i = tx_ring->next_to_use;
6426
Yi Zoueacd73f2009-05-13 13:11:06 +00006427 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6428 /* excluding fcoe_crc_eof for FCoE */
6429 total -= sizeof(struct fcoe_crc_eof);
6430
6431 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006432 while (len) {
6433 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6434 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6435
6436 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006437 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006438 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006439 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006440 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006441 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006442 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006443 tx_buffer_info->time_stamp = jiffies;
6444 tx_buffer_info->next_to_watch = i;
6445
6446 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006447 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006448 offset += size;
6449 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006450
6451 if (len) {
6452 i++;
6453 if (i == tx_ring->count)
6454 i = 0;
6455 }
Auke Kok9a799d72007-09-15 14:07:45 -07006456 }
6457
6458 for (f = 0; f < nr_frags; f++) {
6459 struct skb_frag_struct *frag;
6460
6461 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006462 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006463 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006464
6465 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006466 i++;
6467 if (i == tx_ring->count)
6468 i = 0;
6469
Auke Kok9a799d72007-09-15 14:07:45 -07006470 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6471 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6472
6473 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006474 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006475 frag->page,
6476 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006477 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006478 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006479 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006480 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006481 tx_buffer_info->time_stamp = jiffies;
6482 tx_buffer_info->next_to_watch = i;
6483
6484 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006485 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006486 offset += size;
6487 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006488 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006489 if (total == 0)
6490 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006491 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006492
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006493 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6494 gso_segs = skb_shinfo(skb)->gso_segs;
6495#ifdef IXGBE_FCOE
6496 /* adjust for FCoE Sequence Offload */
6497 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6498 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6499 skb_shinfo(skb)->gso_size);
6500#endif /* IXGBE_FCOE */
6501 bytecount += (gso_segs - 1) * hdr_len;
6502
6503 /* multiply data chunks by size of headers */
6504 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6505 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006506 tx_ring->tx_buffer_info[i].skb = skb;
6507 tx_ring->tx_buffer_info[first].next_to_watch = i;
6508
6509 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006510
6511dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006512 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006513
6514 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6515 tx_buffer_info->dma = 0;
6516 tx_buffer_info->time_stamp = 0;
6517 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006518 if (count)
6519 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006520
6521 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006522 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006523 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006524 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006525 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006526 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006527 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006528 }
6529
Anton Blancharde44d38e2010-02-03 13:12:51 +00006530 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006531}
6532
Alexander Duyck84ea2592010-11-16 19:26:49 -08006533static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006534 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006535{
6536 union ixgbe_adv_tx_desc *tx_desc = NULL;
6537 struct ixgbe_tx_buffer *tx_buffer_info;
6538 u32 olinfo_status = 0, cmd_type_len = 0;
6539 unsigned int i;
6540 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6541
6542 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6543
6544 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6545
6546 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6547 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6548
6549 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6550 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6551
6552 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006553 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006554
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006555 /* use index 1 context for tso */
6556 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006557 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6558 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006559 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006560
6561 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6562 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006563 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006564
Yi Zoueacd73f2009-05-13 13:11:06 +00006565 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6566 olinfo_status |= IXGBE_ADVTXD_CC;
6567 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6568 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6569 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6570 }
6571
Auke Kok9a799d72007-09-15 14:07:45 -07006572 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6573
6574 i = tx_ring->next_to_use;
6575 while (count--) {
6576 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006577 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006578 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6579 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006580 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006581 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006582 i++;
6583 if (i == tx_ring->count)
6584 i = 0;
6585 }
6586
6587 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6588
6589 /*
6590 * Force memory writes to complete before letting h/w
6591 * know there are new descriptors to fetch. (Only
6592 * applicable for weak-ordered memory model archs,
6593 * such as IA-64).
6594 */
6595 wmb();
6596
6597 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006598 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006599}
6600
Alexander Duyck69830522011-01-06 14:29:58 +00006601static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6602 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006603{
Alexander Duyck69830522011-01-06 14:29:58 +00006604 struct ixgbe_q_vector *q_vector = ring->q_vector;
6605 union ixgbe_atr_hash_dword input = { .dword = 0 };
6606 union ixgbe_atr_hash_dword common = { .dword = 0 };
6607 union {
6608 unsigned char *network;
6609 struct iphdr *ipv4;
6610 struct ipv6hdr *ipv6;
6611 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006612 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006613 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006614
Alexander Duyck69830522011-01-06 14:29:58 +00006615 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6616 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006617 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006618
Alexander Duyck69830522011-01-06 14:29:58 +00006619 /* do nothing if sampling is disabled */
6620 if (!ring->atr_sample_rate)
6621 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006622
Alexander Duyck69830522011-01-06 14:29:58 +00006623 ring->atr_count++;
6624
6625 /* snag network header to get L4 type and address */
6626 hdr.network = skb_network_header(skb);
6627
6628 /* Currently only IPv4/IPv6 with TCP is supported */
6629 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6630 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6631 (protocol != __constant_htons(ETH_P_IP) ||
6632 hdr.ipv4->protocol != IPPROTO_TCP))
6633 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006634
6635 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006636
Alexander Duyck69830522011-01-06 14:29:58 +00006637 /* skip this packet since the socket is closing */
6638 if (th->fin)
6639 return;
6640
6641 /* sample on all syn packets or once every atr sample count */
6642 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6643 return;
6644
6645 /* reset sample count */
6646 ring->atr_count = 0;
6647
6648 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6649
6650 /*
6651 * src and dst are inverted, think how the receiver sees them
6652 *
6653 * The input is broken into two sections, a non-compressed section
6654 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6655 * is XORed together and stored in the compressed dword.
6656 */
6657 input.formatted.vlan_id = vlan_id;
6658
6659 /*
6660 * since src port and flex bytes occupy the same word XOR them together
6661 * and write the value to source port portion of compressed dword
6662 */
6663 if (vlan_id)
6664 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6665 else
6666 common.port.src ^= th->dest ^ protocol;
6667 common.port.dst ^= th->source;
6668
6669 if (protocol == __constant_htons(ETH_P_IP)) {
6670 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6671 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6672 } else {
6673 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6674 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6675 hdr.ipv6->saddr.s6_addr32[1] ^
6676 hdr.ipv6->saddr.s6_addr32[2] ^
6677 hdr.ipv6->saddr.s6_addr32[3] ^
6678 hdr.ipv6->daddr.s6_addr32[0] ^
6679 hdr.ipv6->daddr.s6_addr32[1] ^
6680 hdr.ipv6->daddr.s6_addr32[2] ^
6681 hdr.ipv6->daddr.s6_addr32[3];
6682 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006683
6684 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006685 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6686 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006687}
6688
Alexander Duyck63544e92011-05-27 05:31:42 +00006689static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006690{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006691 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006692 /* Herbert's original patch had:
6693 * smp_mb__after_netif_stop_queue();
6694 * but since that doesn't exist yet, just open code it. */
6695 smp_mb();
6696
6697 /* We need to check again in a case another CPU has just
6698 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006699 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006700 return -EBUSY;
6701
6702 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006703 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006704 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006705 return 0;
6706}
6707
Alexander Duyck82d4e462011-06-11 01:44:58 +00006708static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006709{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006710 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006711 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006712 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006713}
6714
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006715static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6716{
6717 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006718 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6719 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006720#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006721 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006722
John Fastabende5b64632011-03-08 03:44:52 +00006723 if (((protocol == htons(ETH_P_FCOE)) ||
6724 (protocol == htons(ETH_P_FIP))) &&
6725 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6726 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6727 txq += adapter->ring_feature[RING_F_FCOE].mask;
6728 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006729 }
6730#endif
6731
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006732 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6733 while (unlikely(txq >= dev->real_num_tx_queues))
6734 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006735 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006736 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006737
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006738 return skb_tx_hash(dev, skb);
6739}
6740
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006741netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006742 struct ixgbe_adapter *adapter,
6743 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006744{
Yi Zou5f715822009-12-03 11:32:44 +00006745 int tso;
Alexander Duycka535c302011-05-27 05:31:52 +00006746 u32 tx_flags = 0;
6747#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6748 unsigned short f;
6749#endif
Alexander Duyck63544e92011-05-27 05:31:42 +00006750 u16 first;
Alexander Duycka535c302011-05-27 05:31:52 +00006751 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Hao Zheng5e09a102010-11-11 13:47:59 +00006752 __be16 protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006753 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006754
Alexander Duycka535c302011-05-27 05:31:52 +00006755 /*
6756 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6757 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6758 * + 2 desc gap to keep tail from touching head,
6759 * + 1 desc for context descriptor,
6760 * otherwise try next time
6761 */
6762#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6763 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6764 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6765#else
6766 count += skb_shinfo(skb)->nr_frags;
6767#endif
6768 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6769 tx_ring->tx_stats.tx_busy++;
6770 return NETDEV_TX_BUSY;
6771 }
6772
Hao Zheng5e09a102010-11-11 13:47:59 +00006773 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006774
Jesse Grosseab6d182010-10-20 13:56:03 +00006775 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006776 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006777 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6778 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006779 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006780 }
6781 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6782 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006783 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6784 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006785 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006786 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6787 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006788 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006789
Yi Zou09ad1cc2009-09-03 14:56:10 +00006790#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006791 /* for FCoE with DCB, we force the priority to what
6792 * was specified by the switch */
6793 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006794 (protocol == htons(ETH_P_FCOE)))
6795 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Alexander Duycka535c302011-05-27 05:31:52 +00006796
Robert Loveca77cd52010-03-24 12:45:00 +00006797#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006798 /* record the location of the first descriptor for this packet */
Auke Kok9a799d72007-09-15 14:07:45 -07006799 first = tx_ring->next_to_use;
Alexander Duycka535c302011-05-27 05:31:52 +00006800
Yi Zoueacd73f2009-05-13 13:11:06 +00006801 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6802#ifdef IXGBE_FCOE
6803 /* setup tx offload for FCoE */
Alexander Duyck897ab152011-05-27 05:31:47 +00006804 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6805 if (tso < 0)
6806 goto out_drop;
6807 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006808 tx_flags |= IXGBE_TX_FLAGS_FSO;
6809#endif /* IXGBE_FCOE */
6810 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006811 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006812 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006813 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6814 if (tso < 0)
6815 goto out_drop;
6816 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006817 tx_flags |= IXGBE_TX_FLAGS_TSO;
Alexander Duyck897ab152011-05-27 05:31:47 +00006818 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
Yi Zoueacd73f2009-05-13 13:11:06 +00006819 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006820 }
6821
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006822 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006823 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006824 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006825 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6826 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006827 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006828 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006829
Alexander Duyck44df32c2009-03-31 21:34:23 +00006830 } else {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006831 tx_ring->tx_buffer_info[first].time_stamp = 0;
6832 tx_ring->next_to_use = first;
Alexander Duyck897ab152011-05-27 05:31:47 +00006833 goto out_drop;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006834 }
Auke Kok9a799d72007-09-15 14:07:45 -07006835
6836 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006837
6838out_drop:
6839 dev_kfree_skb_any(skb);
6840 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006841}
6842
Alexander Duyck84418e32010-08-19 13:40:54 +00006843static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6844{
6845 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6846 struct ixgbe_ring *tx_ring;
6847
6848 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006849 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006850}
6851
Auke Kok9a799d72007-09-15 14:07:45 -07006852/**
Auke Kok9a799d72007-09-15 14:07:45 -07006853 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6854 * @netdev: network interface device structure
6855 * @p: pointer to an address structure
6856 *
6857 * Returns 0 on success, negative on failure
6858 **/
6859static int ixgbe_set_mac(struct net_device *netdev, void *p)
6860{
6861 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006862 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006863 struct sockaddr *addr = p;
6864
6865 if (!is_valid_ether_addr(addr->sa_data))
6866 return -EADDRNOTAVAIL;
6867
6868 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006869 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006870
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006871 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6872 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006873
6874 return 0;
6875}
6876
Ben Hutchings6b73e102009-04-29 08:08:58 +00006877static int
6878ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6879{
6880 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6881 struct ixgbe_hw *hw = &adapter->hw;
6882 u16 value;
6883 int rc;
6884
6885 if (prtad != hw->phy.mdio.prtad)
6886 return -EINVAL;
6887 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6888 if (!rc)
6889 rc = value;
6890 return rc;
6891}
6892
6893static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6894 u16 addr, u16 value)
6895{
6896 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6897 struct ixgbe_hw *hw = &adapter->hw;
6898
6899 if (prtad != hw->phy.mdio.prtad)
6900 return -EINVAL;
6901 return hw->phy.ops.write_reg(hw, addr, devad, value);
6902}
6903
6904static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6905{
6906 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6907
6908 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6909}
6910
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006911/**
6912 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006913 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006914 * @netdev: network interface device structure
6915 *
6916 * Returns non-zero on failure
6917 **/
6918static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6919{
6920 int err = 0;
6921 struct ixgbe_adapter *adapter = netdev_priv(dev);
6922 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6923
6924 if (is_valid_ether_addr(mac->san_addr)) {
6925 rtnl_lock();
6926 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6927 rtnl_unlock();
6928 }
6929 return err;
6930}
6931
6932/**
6933 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006934 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006935 * @netdev: network interface device structure
6936 *
6937 * Returns non-zero on failure
6938 **/
6939static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6940{
6941 int err = 0;
6942 struct ixgbe_adapter *adapter = netdev_priv(dev);
6943 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6944
6945 if (is_valid_ether_addr(mac->san_addr)) {
6946 rtnl_lock();
6947 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6948 rtnl_unlock();
6949 }
6950 return err;
6951}
6952
Auke Kok9a799d72007-09-15 14:07:45 -07006953#ifdef CONFIG_NET_POLL_CONTROLLER
6954/*
6955 * Polling 'interrupt' - used by things like netconsole to send skbs
6956 * without having to re-enable interrupts. It's not called while
6957 * the interrupt routine is executing.
6958 */
6959static void ixgbe_netpoll(struct net_device *netdev)
6960{
6961 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006962 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006963
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006964 /* if interface is down do nothing */
6965 if (test_bit(__IXGBE_DOWN, &adapter->state))
6966 return;
6967
Auke Kok9a799d72007-09-15 14:07:45 -07006968 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006969 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6970 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6971 for (i = 0; i < num_q_vectors; i++) {
6972 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
6973 ixgbe_msix_clean_many(0, q_vector);
6974 }
6975 } else {
6976 ixgbe_intr(adapter->pdev->irq, netdev);
6977 }
Auke Kok9a799d72007-09-15 14:07:45 -07006978 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006979}
6980#endif
6981
Eric Dumazetde1036b2010-10-20 23:00:04 +00006982static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6983 struct rtnl_link_stats64 *stats)
6984{
6985 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6986 int i;
6987
Eric Dumazet1a515022010-11-16 19:26:42 -08006988 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00006989 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08006990 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00006991 u64 bytes, packets;
6992 unsigned int start;
6993
Eric Dumazet1a515022010-11-16 19:26:42 -08006994 if (ring) {
6995 do {
6996 start = u64_stats_fetch_begin_bh(&ring->syncp);
6997 packets = ring->stats.packets;
6998 bytes = ring->stats.bytes;
6999 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7000 stats->rx_packets += packets;
7001 stats->rx_bytes += bytes;
7002 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007003 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007004
7005 for (i = 0; i < adapter->num_tx_queues; i++) {
7006 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7007 u64 bytes, packets;
7008 unsigned int start;
7009
7010 if (ring) {
7011 do {
7012 start = u64_stats_fetch_begin_bh(&ring->syncp);
7013 packets = ring->stats.packets;
7014 bytes = ring->stats.bytes;
7015 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7016 stats->tx_packets += packets;
7017 stats->tx_bytes += bytes;
7018 }
7019 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007020 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007021 /* following stats updated by ixgbe_watchdog_task() */
7022 stats->multicast = netdev->stats.multicast;
7023 stats->rx_errors = netdev->stats.rx_errors;
7024 stats->rx_length_errors = netdev->stats.rx_length_errors;
7025 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7026 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7027 return stats;
7028}
7029
John Fastabend8b1c0b22011-05-03 02:26:48 +00007030/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7031 * #adapter: pointer to ixgbe_adapter
7032 * @tc: number of traffic classes currently enabled
7033 *
7034 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7035 * 802.1Q priority maps to a packet buffer that exists.
7036 */
7037static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7038{
7039 struct ixgbe_hw *hw = &adapter->hw;
7040 u32 reg, rsave;
7041 int i;
7042
7043 /* 82598 have a static priority to TC mapping that can not
7044 * be changed so no validation is needed.
7045 */
7046 if (hw->mac.type == ixgbe_mac_82598EB)
7047 return;
7048
7049 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7050 rsave = reg;
7051
7052 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7053 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7054
7055 /* If up2tc is out of bounds default to zero */
7056 if (up2tc > tc)
7057 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7058 }
7059
7060 if (reg != rsave)
7061 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7062
7063 return;
7064}
7065
7066
7067/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7068 * classes.
7069 *
7070 * @netdev: net device to configure
7071 * @tc: number of traffic classes to enable
7072 */
7073int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7074{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007075 struct ixgbe_adapter *adapter = netdev_priv(dev);
7076 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007077
7078 /* If DCB is anabled do not remove traffic classes, multiple
7079 * traffic classes are required to implement DCB
7080 */
7081 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7082 return 0;
7083
7084 /* Hardware supports up to 8 traffic classes */
7085 if (tc > MAX_TRAFFIC_CLASS ||
7086 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7087 return -EINVAL;
7088
7089 /* Hardware has to reinitialize queues and interrupts to
7090 * match packet buffer alignment. Unfortunantly, the
7091 * hardware is not flexible enough to do this dynamically.
7092 */
7093 if (netif_running(dev))
7094 ixgbe_close(dev);
7095 ixgbe_clear_interrupt_scheme(adapter);
7096
7097 if (tc)
7098 netdev_set_num_tc(dev, tc);
7099 else
7100 netdev_reset_tc(dev);
7101
John Fastabend8b1c0b22011-05-03 02:26:48 +00007102 ixgbe_init_interrupt_scheme(adapter);
7103 ixgbe_validate_rtr(adapter, tc);
7104 if (netif_running(dev))
7105 ixgbe_open(dev);
7106
7107 return 0;
7108}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007109
Don Skidmore082757a2011-07-21 05:55:00 +00007110void ixgbe_do_reset(struct net_device *netdev)
7111{
7112 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7113
7114 if (netif_running(netdev))
7115 ixgbe_reinit_locked(adapter);
7116 else
7117 ixgbe_reset(adapter);
7118}
7119
7120static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7121{
7122 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7123
7124#ifdef CONFIG_DCB
7125 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7126 data &= ~NETIF_F_HW_VLAN_RX;
7127#endif
7128
7129 /* return error if RXHASH is being enabled when RSS is not supported */
7130 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7131 data &= ~NETIF_F_RXHASH;
7132
7133 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7134 if (!(data & NETIF_F_RXCSUM))
7135 data &= ~NETIF_F_LRO;
7136
7137 /* Turn off LRO if not RSC capable or invalid ITR settings */
7138 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7139 data &= ~NETIF_F_LRO;
7140 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7141 (adapter->rx_itr_setting != 1 &&
7142 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7143 data &= ~NETIF_F_LRO;
7144 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7145 }
7146
7147 return data;
7148}
7149
7150static int ixgbe_set_features(struct net_device *netdev, u32 data)
7151{
7152 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7153 bool need_reset = false;
7154
7155 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7156 if (!(data & NETIF_F_RXCSUM))
7157 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7158 else
7159 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7160
7161 /* Make sure RSC matches LRO, reset if change */
7162 if (!!(data & NETIF_F_LRO) !=
7163 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7164 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7165 switch (adapter->hw.mac.type) {
7166 case ixgbe_mac_X540:
7167 case ixgbe_mac_82599EB:
7168 need_reset = true;
7169 break;
7170 default:
7171 break;
7172 }
7173 }
7174
7175 /*
7176 * Check if Flow Director n-tuple support was enabled or disabled. If
7177 * the state changed, we need to reset.
7178 */
7179 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7180 /* turn off ATR, enable perfect filters and reset */
7181 if (data & NETIF_F_NTUPLE) {
7182 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7183 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7184 need_reset = true;
7185 }
7186 } else if (!(data & NETIF_F_NTUPLE)) {
7187 /* turn off Flow Director, set ATR and reset */
7188 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7189 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7190 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7191 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7192 need_reset = true;
7193 }
7194
7195 if (need_reset)
7196 ixgbe_do_reset(netdev);
7197
7198 return 0;
7199
7200}
7201
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007202static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007203 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007204 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007205 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007206 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007207 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007208 .ndo_validate_addr = eth_validate_addr,
7209 .ndo_set_mac_address = ixgbe_set_mac,
7210 .ndo_change_mtu = ixgbe_change_mtu,
7211 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007212 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7213 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007214 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007215 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7216 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7217 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7218 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007219 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007220 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007221#ifdef CONFIG_NET_POLL_CONTROLLER
7222 .ndo_poll_controller = ixgbe_netpoll,
7223#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007224#ifdef IXGBE_FCOE
7225 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007226 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007227 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007228 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7229 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007230 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007231#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007232 .ndo_set_features = ixgbe_set_features,
7233 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007234};
7235
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007236static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7237 const struct ixgbe_info *ii)
7238{
7239#ifdef CONFIG_PCI_IOV
7240 struct ixgbe_hw *hw = &adapter->hw;
7241 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007242 int num_vf_macvlans, i;
7243 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007244
Greg Rose3377eba792010-12-07 08:16:45 +00007245 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007246 return;
7247
7248 /* The 82599 supports up to 64 VFs per physical function
7249 * but this implementation limits allocation to 63 so that
7250 * basic networking resources are still available to the
7251 * physical function
7252 */
7253 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7254 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7255 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7256 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007257 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007258 goto err_novfs;
7259 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007260
7261 num_vf_macvlans = hw->mac.num_rar_entries -
7262 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7263
7264 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7265 sizeof(struct vf_macvlans),
7266 GFP_KERNEL);
7267 if (mv_list) {
7268 /* Initialize list of VF macvlans */
7269 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7270 for (i = 0; i < num_vf_macvlans; i++) {
7271 mv_list->vf = -1;
7272 mv_list->free = true;
7273 mv_list->rar_entry = hw->mac.num_rar_entries -
7274 (i + adapter->num_vfs + 1);
7275 list_add(&mv_list->l, &adapter->vf_mvs.l);
7276 mv_list++;
7277 }
7278 }
7279
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007280 /* If call to enable VFs succeeded then allocate memory
7281 * for per VF control structures.
7282 */
7283 adapter->vfinfo =
7284 kcalloc(adapter->num_vfs,
7285 sizeof(struct vf_data_storage), GFP_KERNEL);
7286 if (adapter->vfinfo) {
7287 /* Now that we're sure SR-IOV is enabled
7288 * and memory allocated set up the mailbox parameters
7289 */
7290 ixgbe_init_mbx_params_pf(hw);
7291 memcpy(&hw->mbx.ops, ii->mbx_ops,
7292 sizeof(hw->mbx.ops));
7293
7294 /* Disable RSC when in SR-IOV mode */
7295 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7296 IXGBE_FLAG2_RSC_ENABLED);
7297 return;
7298 }
7299
7300 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007301 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7302 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007303 pci_disable_sriov(adapter->pdev);
7304
7305err_novfs:
7306 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7307 adapter->num_vfs = 0;
7308#endif /* CONFIG_PCI_IOV */
7309}
7310
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007311/**
Auke Kok9a799d72007-09-15 14:07:45 -07007312 * ixgbe_probe - Device Initialization Routine
7313 * @pdev: PCI device information struct
7314 * @ent: entry in ixgbe_pci_tbl
7315 *
7316 * Returns 0 on success, negative on failure
7317 *
7318 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7319 * The OS initialization, configuring of the adapter private structure,
7320 * and a hardware reset occur.
7321 **/
7322static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007323 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007324{
7325 struct net_device *netdev;
7326 struct ixgbe_adapter *adapter = NULL;
7327 struct ixgbe_hw *hw;
7328 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007329 static int cards_found;
7330 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007331 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007332 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007333#ifdef IXGBE_FCOE
7334 u16 device_caps;
7335#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007336 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007337
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007338 /* Catch broken hardware that put the wrong VF device ID in
7339 * the PCIe SR-IOV capability.
7340 */
7341 if (pdev->is_virtfn) {
7342 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7343 pci_name(pdev), pdev->vendor, pdev->device);
7344 return -EINVAL;
7345 }
7346
gouji-new9ce77662009-05-06 10:44:45 +00007347 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007348 if (err)
7349 return err;
7350
Nick Nunley1b507732010-04-27 13:10:27 +00007351 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7352 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007353 pci_using_dac = 1;
7354 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007355 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007356 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007357 err = dma_set_coherent_mask(&pdev->dev,
7358 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007359 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007360 dev_err(&pdev->dev,
7361 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007362 goto err_dma;
7363 }
7364 }
7365 pci_using_dac = 0;
7366 }
7367
gouji-new9ce77662009-05-06 10:44:45 +00007368 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007369 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007370 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007371 dev_err(&pdev->dev,
7372 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007373 goto err_pci_reg;
7374 }
7375
Frans Pop19d5afd2009-10-02 10:04:12 -07007376 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007377
Auke Kok9a799d72007-09-15 14:07:45 -07007378 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007379 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007380
John Fastabende901acd2011-04-26 07:26:08 +00007381#ifdef CONFIG_IXGBE_DCB
7382 indices *= MAX_TRAFFIC_CLASS;
7383#endif
7384
John Fastabendc85a2612010-02-25 23:15:21 +00007385 if (ii->mac == ixgbe_mac_82598EB)
7386 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7387 else
7388 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7389
John Fastabende901acd2011-04-26 07:26:08 +00007390#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007391 indices += min_t(unsigned int, num_possible_cpus(),
7392 IXGBE_MAX_FCOE_INDICES);
7393#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007394 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007395 if (!netdev) {
7396 err = -ENOMEM;
7397 goto err_alloc_etherdev;
7398 }
7399
Auke Kok9a799d72007-09-15 14:07:45 -07007400 SET_NETDEV_DEV(netdev, &pdev->dev);
7401
Auke Kok9a799d72007-09-15 14:07:45 -07007402 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007403 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007404
7405 adapter->netdev = netdev;
7406 adapter->pdev = pdev;
7407 hw = &adapter->hw;
7408 hw->back = adapter;
7409 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7410
Jeff Kirsher05857982008-09-11 19:57:00 -07007411 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007412 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007413 if (!hw->hw_addr) {
7414 err = -EIO;
7415 goto err_ioremap;
7416 }
7417
7418 for (i = 1; i <= 5; i++) {
7419 if (pci_resource_len(pdev, i) == 0)
7420 continue;
7421 }
7422
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007423 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007424 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007425 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007426 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007427
Auke Kok9a799d72007-09-15 14:07:45 -07007428 adapter->bd_number = cards_found;
7429
Auke Kok9a799d72007-09-15 14:07:45 -07007430 /* Setup hw api */
7431 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007432 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007433
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007434 /* EEPROM */
7435 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7436 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7437 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7438 if (!(eec & (1 << 8)))
7439 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7440
7441 /* PHY */
7442 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007443 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007444 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7445 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7446 hw->phy.mdio.mmds = 0;
7447 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7448 hw->phy.mdio.dev = netdev;
7449 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7450 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007451
Don Skidmore8ca783a2009-05-26 20:40:47 -07007452 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007453
7454 /* setup the private structure */
7455 err = ixgbe_sw_init(adapter);
7456 if (err)
7457 goto err_sw_init;
7458
Don Skidmoree86bff02010-02-11 04:14:08 +00007459 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007460 switch (adapter->hw.mac.type) {
7461 case ixgbe_mac_82599EB:
7462 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007463 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007464 break;
7465 default:
7466 break;
7467 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007468
Don Skidmorebf069c92009-05-07 10:39:54 +00007469 /*
7470 * If there is a fan on this device and it has failed log the
7471 * failure.
7472 */
7473 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7474 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7475 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007476 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007477 }
7478
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007479 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007480 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007481 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007482 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007483 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7484 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007485 err = 0;
7486 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007487 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007488 "module type was detected.\n");
7489 e_dev_err("Reload the driver after installing a supported "
7490 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007491 goto err_sw_init;
7492 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007493 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007494 goto err_sw_init;
7495 }
7496
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007497 ixgbe_probe_vf(adapter, ii);
7498
Emil Tantilov396e7992010-07-01 20:05:12 +00007499 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007500 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007501 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007502 NETIF_F_HW_VLAN_TX |
7503 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007504 NETIF_F_HW_VLAN_FILTER |
7505 NETIF_F_TSO |
7506 NETIF_F_TSO6 |
7507 NETIF_F_GRO |
7508 NETIF_F_RXHASH |
7509 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007510
Don Skidmore082757a2011-07-21 05:55:00 +00007511 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007512
Don Skidmore58be7662011-04-12 09:42:11 +00007513 switch (adapter->hw.mac.type) {
7514 case ixgbe_mac_82599EB:
7515 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007516 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007517 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7518 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007519 break;
7520 default:
7521 break;
7522 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007523
Jeff Kirsherad31c402008-06-05 04:05:30 -07007524 netdev->vlan_features |= NETIF_F_TSO;
7525 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007526 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007527 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007528 netdev->vlan_features |= NETIF_F_SG;
7529
Jiri Pirko01789342011-08-16 06:29:00 +00007530 netdev->priv_flags |= IFF_UNICAST_FLT;
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 Skidmore289700db2010-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 Skidmore289700db2010-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 Skidmore289700db2010-12-03 03:32:58 +00007642 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007643 else
Don Skidmore289700db2010-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 */