blob: 44ded0c092da982939193d4e654b78ba5a19ef1f [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];
Alexander Duyckd3d00232011-07-15 02:31:25 +0000388 pr_info(" %5d %5X %5X %016llX %04X %p %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"
Alexander Duyckd3d00232011-07-15 02:31:25 +0000427 " %04X %p %016llX %p", i,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000428 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 Duyckd3d00232011-07-15 02:31:25 +0000646static inline void ixgbe_unmap_tx_resource(struct ixgbe_ring *ring,
647 struct ixgbe_tx_buffer *tx_buffer)
648{
649 if (tx_buffer->dma) {
650 if (tx_buffer->tx_flags & IXGBE_TX_FLAGS_MAPPED_AS_PAGE)
651 dma_unmap_page(ring->dev,
652 tx_buffer->dma,
653 tx_buffer->length,
654 DMA_TO_DEVICE);
655 else
656 dma_unmap_single(ring->dev,
657 tx_buffer->dma,
658 tx_buffer->length,
659 DMA_TO_DEVICE);
660 }
661 tx_buffer->dma = 0;
662}
663
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800664void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
665 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700666{
Alexander Duyckd3d00232011-07-15 02:31:25 +0000667 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
668 if (tx_buffer_info->skb)
Auke Kok9a799d72007-09-15 14:07:45 -0700669 dev_kfree_skb_any(tx_buffer_info->skb);
Alexander Duyckd3d00232011-07-15 02:31:25 +0000670 tx_buffer_info->skb = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -0700671 /* tx_buffer_info must be completely set up in the transmit path */
672}
673
John Fastabendc84d3242010-11-16 19:27:12 -0800674static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700675{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700676 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800677 struct ixgbe_hw_stats *hwstats = &adapter->stats;
678 u32 data = 0;
679 u32 xoff[8] = {0};
680 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700681
John Fastabendc84d3242010-11-16 19:27:12 -0800682 if ((hw->fc.current_mode == ixgbe_fc_full) ||
683 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
684 switch (hw->mac.type) {
685 case ixgbe_mac_82598EB:
686 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
687 break;
688 default:
689 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
690 }
691 hwstats->lxoffrxc += data;
692
693 /* refill credits (no tx hang) if we received xoff */
694 if (!data)
695 return;
696
697 for (i = 0; i < adapter->num_tx_queues; i++)
698 clear_bit(__IXGBE_HANG_CHECK_ARMED,
699 &adapter->tx_ring[i]->state);
700 return;
701 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
702 return;
703
704 /* update stats for each tc, only valid with PFC enabled */
705 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
706 switch (hw->mac.type) {
707 case ixgbe_mac_82598EB:
708 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
709 break;
710 default:
711 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
712 }
713 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700714 }
715
John Fastabendc84d3242010-11-16 19:27:12 -0800716 /* disarm tx queues that have received xoff frames */
717 for (i = 0; i < adapter->num_tx_queues; i++) {
718 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000719 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800720
721 if (xoff[tc])
722 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
723 }
724}
725
726static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
727{
728 return ring->tx_stats.completed;
729}
730
731static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
732{
733 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
734 struct ixgbe_hw *hw = &adapter->hw;
735
736 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
737 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
738
739 if (head != tail)
740 return (head < tail) ?
741 tail - head : (tail + ring->count - head);
742
743 return 0;
744}
745
746static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
747{
748 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
749 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
750 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
751 bool ret = false;
752
753 clear_check_for_tx_hang(tx_ring);
754
755 /*
756 * Check for a hung queue, but be thorough. This verifies
757 * that a transmit has been completed since the previous
758 * check AND there is at least one packet pending. The
759 * ARMED bit is set to indicate a potential hang. The
760 * bit is cleared if a pause frame is received to remove
761 * false hang detection due to PFC or 802.3x frames. By
762 * requiring this to fail twice we avoid races with
763 * pfc clearing the ARMED bit and conditions where we
764 * run the check_tx_hang logic with a transmit completion
765 * pending but without time to complete it yet.
766 */
767 if ((tx_done_old == tx_done) && tx_pending) {
768 /* make sure it is true for two checks in a row */
769 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
770 &tx_ring->state);
771 } else {
772 /* update completed stats and continue */
773 tx_ring->tx_stats.tx_done_old = tx_done;
774 /* reset the countdown */
775 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
776 }
777
778 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700779}
780
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000781/**
782 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
783 * @adapter: driver private struct
784 **/
785static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
786{
787
788 /* Do the reset outside of interrupt context */
789 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
790 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
791 ixgbe_service_event_schedule(adapter);
792 }
793}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700794
Auke Kok9a799d72007-09-15 14:07:45 -0700795/**
796 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000797 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700798 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700799 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000800static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000801 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700802{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000803 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000804 struct ixgbe_tx_buffer *tx_buffer;
805 union ixgbe_adv_tx_desc *tx_desc;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700806 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000807 u16 i = tx_ring->next_to_clean;
808 u16 count;
Auke Kok9a799d72007-09-15 14:07:45 -0700809
Alexander Duyckd3d00232011-07-15 02:31:25 +0000810 tx_buffer = &tx_ring->tx_buffer_info[i];
811 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800812
Alexander Duyckd3d00232011-07-15 02:31:25 +0000813 for (count = 0; count < q_vector->tx.work_limit; count++) {
814 union ixgbe_adv_tx_desc *eop_desc = tx_buffer->next_to_watch;
Auke Kok9a799d72007-09-15 14:07:45 -0700815
Alexander Duyckd3d00232011-07-15 02:31:25 +0000816 /* if next_to_watch is not set then there is no work pending */
817 if (!eop_desc)
818 break;
819
820 /* if DD is not set pending work has not been completed */
821 if (!(eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)))
822 break;
823
824 /* count the packet as being completed */
825 tx_ring->tx_stats.completed++;
826
827 /* clear next_to_watch to prevent false hangs */
828 tx_buffer->next_to_watch = NULL;
829
830 /* prevent any other reads prior to eop_desc being verified */
831 rmb();
832
833 do {
834 ixgbe_unmap_tx_resource(tx_ring, tx_buffer);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800835 tx_desc->wb.status = 0;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000836 if (likely(tx_desc == eop_desc)) {
837 eop_desc = NULL;
838 dev_kfree_skb_any(tx_buffer->skb);
839 tx_buffer->skb = NULL;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800840
Alexander Duyckd3d00232011-07-15 02:31:25 +0000841 total_bytes += tx_buffer->bytecount;
842 total_packets += tx_buffer->gso_segs;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800843 }
844
Alexander Duyckd3d00232011-07-15 02:31:25 +0000845 tx_buffer++;
846 tx_desc++;
847 i++;
848 if (unlikely(i == tx_ring->count)) {
849 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700850
Alexander Duyckd3d00232011-07-15 02:31:25 +0000851 tx_buffer = tx_ring->tx_buffer_info;
852 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
853 }
854
855 } while (eop_desc);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800856 }
857
Auke Kok9a799d72007-09-15 14:07:45 -0700858 tx_ring->next_to_clean = i;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000859 u64_stats_update_begin(&tx_ring->syncp);
Alexander Duyckb9537992010-11-16 19:26:58 -0800860 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000861 tx_ring->stats.packets += total_packets;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000862 u64_stats_update_end(&tx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +0000863 q_vector->tx.total_bytes += total_bytes;
864 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800865
John Fastabendc84d3242010-11-16 19:27:12 -0800866 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800867 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800868 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000869 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
John Fastabendc84d3242010-11-16 19:27:12 -0800870 e_err(drv, "Detected Tx Unit Hang\n"
871 " Tx Queue <%d>\n"
872 " TDH, TDT <%x>, <%x>\n"
873 " next_to_use <%x>\n"
874 " next_to_clean <%x>\n"
875 "tx_buffer_info[next_to_clean]\n"
876 " time_stamp <%lx>\n"
877 " jiffies <%lx>\n",
878 tx_ring->queue_index,
879 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
880 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
Alexander Duyckd3d00232011-07-15 02:31:25 +0000881 tx_ring->next_to_use, i,
882 tx_ring->tx_buffer_info[i].time_stamp, jiffies);
John Fastabendc84d3242010-11-16 19:27:12 -0800883
884 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
885
886 e_info(probe,
887 "tx hang %d detected on queue %d, resetting adapter\n",
888 adapter->tx_timeout_count + 1, tx_ring->queue_index);
889
890 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000891 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800892
893 /* the adapter is about to reset, no point in enabling stuff */
894 return true;
895 }
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800897#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800898 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000899 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800900 /* Make sure that anybody stopping the queue after this
901 * sees the new next_to_clean.
902 */
903 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800904 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800905 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800906 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800907 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800908 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800909 }
Auke Kok9a799d72007-09-15 14:07:45 -0700910
Alexander Duyckbd198052011-06-11 01:45:08 +0000911 return count < q_vector->tx.work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700912}
913
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400914#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800915static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800916 struct ixgbe_ring *rx_ring,
917 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800918{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800919 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800920 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800921 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800922
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800923 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
924 switch (hw->mac.type) {
925 case ixgbe_mac_82598EB:
926 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
927 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
928 break;
929 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800930 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800931 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
932 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
933 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
934 break;
935 default:
936 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800937 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800938 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
939 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
940 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800941 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800942}
943
944static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800945 struct ixgbe_ring *tx_ring,
946 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800947{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000948 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 u32 txctrl;
950 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800951
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800952 switch (hw->mac.type) {
953 case ixgbe_mac_82598EB:
954 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
955 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
956 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
957 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
959 break;
960 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800961 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
963 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
964 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
965 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
966 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800967 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
968 break;
969 default:
970 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800971 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800972}
973
974static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
975{
976 struct ixgbe_adapter *adapter = q_vector->adapter;
977 int cpu = get_cpu();
978 long r_idx;
979 int i;
980
981 if (q_vector->cpu == cpu)
982 goto out_no_update;
983
Alexander Duyck08c88332011-06-11 01:45:03 +0000984 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
985 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800986 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000987 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800988 r_idx + 1);
989 }
990
Alexander Duyck08c88332011-06-11 01:45:03 +0000991 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
992 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800993 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000994 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800995 r_idx + 1);
996 }
997
998 q_vector->cpu = cpu;
999out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001000 put_cpu();
1001}
1002
1003static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1004{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001005 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001006 int i;
1007
1008 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1009 return;
1010
Alexander Duycke35ec122009-05-21 13:07:12 +00001011 /* always use CB2 mode, difference is masked in the CB driver */
1012 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1013
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001014 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1015 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1016 else
1017 num_q_vectors = 1;
1018
1019 for (i = 0; i < num_q_vectors; i++) {
1020 adapter->q_vector[i]->cpu = -1;
1021 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001022 }
1023}
1024
1025static int __ixgbe_notify_dca(struct device *dev, void *data)
1026{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001027 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001028 unsigned long event = *(unsigned long *)data;
1029
Don Skidmore2a72c312011-07-20 02:27:05 +00001030 if (!(adapter->flags & IXGBE_FLAG_DCA_CAPABLE))
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001031 return 0;
1032
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001033 switch (event) {
1034 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001035 /* if we're already enabled, don't do it again */
1036 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1037 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001038 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001039 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001040 ixgbe_setup_dca(adapter);
1041 break;
1042 }
1043 /* Fall Through since DCA is disabled. */
1044 case DCA_PROVIDER_REMOVE:
1045 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1046 dca_remove_requester(dev);
1047 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1048 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1049 }
1050 break;
1051 }
1052
Denis V. Lunev652f0932008-03-27 14:39:17 +03001053 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001054}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001055#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001056
1057static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1058 struct sk_buff *skb)
1059{
1060 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1061}
1062
Auke Kok9a799d72007-09-15 14:07:45 -07001063/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001064 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1065 * @adapter: address of board private structure
1066 * @rx_desc: advanced rx descriptor
1067 *
1068 * Returns : true if it is FCoE pkt
1069 */
1070static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1071 union ixgbe_adv_rx_desc *rx_desc)
1072{
1073 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1074
1075 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1076 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1077 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1078 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1079}
1080
1081/**
Auke Kok9a799d72007-09-15 14:07:45 -07001082 * ixgbe_receive_skb - Send a completed packet up the stack
1083 * @adapter: board private structure
1084 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001085 * @status: hardware indication of status of receive
1086 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1087 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001088 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001089static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001090 struct sk_buff *skb, u8 status,
1091 struct ixgbe_ring *ring,
1092 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001093{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001094 struct ixgbe_adapter *adapter = q_vector->adapter;
1095 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001096 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1097 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001098
Jesse Grossf62bbb52010-10-20 13:56:10 +00001099 if (is_vlan && (tag & VLAN_VID_MASK))
1100 __vlan_hwaccel_put_tag(skb, tag);
1101
1102 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1103 napi_gro_receive(napi, skb);
1104 else
1105 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001106}
1107
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001108/**
1109 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1110 * @adapter: address of board private structure
1111 * @status_err: hardware indication of status of receive
1112 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001113 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001114 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001115static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001116 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001117 struct sk_buff *skb,
1118 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001119{
Alexander Duyckff886df2011-06-11 01:45:13 +00001120 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001121
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001122 /* Rx csum disabled */
1123 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001124 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001125
1126 /* if IP and error */
1127 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1128 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001129 adapter->hw_csum_rx_error++;
1130 return;
1131 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001132
1133 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1134 return;
1135
1136 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001137 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1138
1139 /*
1140 * 82599 errata, UDP frames with a 0 checksum can be marked as
1141 * checksum errors.
1142 */
1143 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1144 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1145 return;
1146
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001147 adapter->hw_csum_rx_error++;
1148 return;
1149 }
1150
Auke Kok9a799d72007-09-15 14:07:45 -07001151 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001152 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001153}
1154
Alexander Duyck84ea2592010-11-16 19:26:49 -08001155static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001156{
1157 /*
1158 * Force memory writes to complete before letting h/w
1159 * know there are new descriptors to fetch. (Only
1160 * applicable for weak-ordered memory model archs,
1161 * such as IA-64).
1162 */
1163 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001164 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001165}
1166
Auke Kok9a799d72007-09-15 14:07:45 -07001167/**
1168 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001169 * @rx_ring: ring to place buffers on
1170 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001171 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001172void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001173{
Auke Kok9a799d72007-09-15 14:07:45 -07001174 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001175 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001176 struct sk_buff *skb;
1177 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001178
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001179 /* do nothing if no valid netdev defined */
1180 if (!rx_ring->netdev)
1181 return;
1182
Auke Kok9a799d72007-09-15 14:07:45 -07001183 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001184 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001185 bi = &rx_ring->rx_buffer_info[i];
1186 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001187
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001188 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001189 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001190 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001191 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001192 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001193 goto no_buffers;
1194 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001195 /* initialize queue mapping */
1196 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001197 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001198 }
Auke Kok9a799d72007-09-15 14:07:45 -07001199
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001200 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001201 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001202 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001203 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001204 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001205 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001206 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001207 bi->dma = 0;
1208 goto no_buffers;
1209 }
Auke Kok9a799d72007-09-15 14:07:45 -07001210 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001211
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001212 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001213 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001214 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001215 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001216 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001217 goto no_buffers;
1218 }
1219 }
1220
1221 if (!bi->page_dma) {
1222 /* use a half page if we're re-using */
1223 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001224 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001225 bi->page,
1226 bi->page_offset,
1227 PAGE_SIZE / 2,
1228 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001229 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001230 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001231 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001232 bi->page_dma = 0;
1233 goto no_buffers;
1234 }
1235 }
1236
1237 /* Refresh the desc even if buffer_addrs didn't change
1238 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001239 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1240 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001241 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001242 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001243 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001244 }
1245
1246 i++;
1247 if (i == rx_ring->count)
1248 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001249 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001250
Auke Kok9a799d72007-09-15 14:07:45 -07001251no_buffers:
1252 if (rx_ring->next_to_use != i) {
1253 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001254 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001255 }
1256}
1257
Alexander Duyckc267fc12010-11-16 19:27:00 -08001258static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001259{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001260 /* HW will not DMA in data larger than the given buffer, even if it
1261 * parses the (NFS, of course) header to be larger. In that case, it
1262 * fills the header buffer and spills the rest into the page.
1263 */
1264 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1265 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1266 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1267 if (hlen > IXGBE_RX_HDR_SIZE)
1268 hlen = IXGBE_RX_HDR_SIZE;
1269 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001270}
1271
Alexander Duyckf8212f92009-04-27 22:42:37 +00001272/**
1273 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1274 * @skb: pointer to the last skb in the rsc queue
1275 *
1276 * This function changes a queue full of hw rsc buffers into a completed
1277 * packet. It uses the ->prev pointers to find the first packet and then
1278 * turns it into the frag list owner.
1279 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001280static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001281{
1282 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001283 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001284
1285 while (skb->prev) {
1286 struct sk_buff *prev = skb->prev;
1287 frag_list_size += skb->len;
1288 skb->prev = NULL;
1289 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001290 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001291 }
1292
1293 skb_shinfo(skb)->frag_list = skb->next;
1294 skb->next = NULL;
1295 skb->len += frag_list_size;
1296 skb->data_len += frag_list_size;
1297 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001298 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1299
Alexander Duyckf8212f92009-04-27 22:42:37 +00001300 return skb;
1301}
1302
Alexander Duyckaa801752010-11-16 19:27:02 -08001303static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1304{
1305 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1306 IXGBE_RXDADV_RSCCNT_MASK);
1307}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001308
Alexander Duyckc267fc12010-11-16 19:27:00 -08001309static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001310 struct ixgbe_ring *rx_ring,
1311 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001312{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001313 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001314 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1315 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1316 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001317 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001318 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001319#ifdef IXGBE_FCOE
1320 int ddp_bytes = 0;
1321#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001322 u32 staterr;
1323 u16 i;
1324 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001325 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001326
1327 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001328 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001329 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001330
1331 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001332 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001333
Milton Miller3c945e52010-02-19 17:44:42 +00001334 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001335
Alexander Duyckc267fc12010-11-16 19:27:00 -08001336 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1337
Auke Kok9a799d72007-09-15 14:07:45 -07001338 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001339 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001340 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001341
Alexander Duyckc267fc12010-11-16 19:27:00 -08001342 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001343 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001344
1345 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001346 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001347 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001348 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001349 !(staterr & IXGBE_RXD_STAT_EOP) &&
1350 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001351 /*
1352 * When HWRSC is enabled, delay unmapping
1353 * of the first packet. It carries the
1354 * header information, HW may still
1355 * access the header after the writeback.
1356 * Only unmap it when EOP is reached
1357 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001358 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001359 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001360 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001361 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001362 rx_buffer_info->dma,
1363 rx_ring->rx_buf_len,
1364 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001365 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001366 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001367
1368 if (ring_is_ps_enabled(rx_ring)) {
1369 hlen = ixgbe_get_hlen(rx_desc);
1370 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1371 } else {
1372 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1373 }
1374
1375 skb_put(skb, hlen);
1376 } else {
1377 /* assume packet split since header is unmapped */
1378 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001379 }
1380
1381 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001382 dma_unmap_page(rx_ring->dev,
1383 rx_buffer_info->page_dma,
1384 PAGE_SIZE / 2,
1385 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001386 rx_buffer_info->page_dma = 0;
1387 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001388 rx_buffer_info->page,
1389 rx_buffer_info->page_offset,
1390 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001391
Alexander Duyckc267fc12010-11-16 19:27:00 -08001392 if ((page_count(rx_buffer_info->page) == 1) &&
1393 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001394 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001395 else
1396 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001397
1398 skb->len += upper_len;
1399 skb->data_len += upper_len;
1400 skb->truesize += upper_len;
1401 }
1402
1403 i++;
1404 if (i == rx_ring->count)
1405 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001406
Alexander Duyck31f05a22010-08-19 13:40:31 +00001407 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001408 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001409 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001410
Alexander Duyckaa801752010-11-16 19:27:02 -08001411 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001412 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1413 IXGBE_RXDADV_NEXTP_SHIFT;
1414 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001415 } else {
1416 next_buffer = &rx_ring->rx_buffer_info[i];
1417 }
1418
Alexander Duyckc267fc12010-11-16 19:27:00 -08001419 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001420 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001421 rx_buffer_info->skb = next_buffer->skb;
1422 rx_buffer_info->dma = next_buffer->dma;
1423 next_buffer->skb = skb;
1424 next_buffer->dma = 0;
1425 } else {
1426 skb->next = next_buffer->skb;
1427 skb->next->prev = skb;
1428 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001429 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001430 goto next_desc;
1431 }
1432
Alexander Duyckaa801752010-11-16 19:27:02 -08001433 if (skb->prev) {
1434 skb = ixgbe_transform_rsc_queue(skb);
1435 /* if we got here without RSC the packet is invalid */
1436 if (!pkt_is_rsc) {
1437 __pskb_trim(skb, 0);
1438 rx_buffer_info->skb = skb;
1439 goto next_desc;
1440 }
1441 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001442
1443 if (ring_is_rsc_enabled(rx_ring)) {
1444 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1445 dma_unmap_single(rx_ring->dev,
1446 IXGBE_RSC_CB(skb)->dma,
1447 rx_ring->rx_buf_len,
1448 DMA_FROM_DEVICE);
1449 IXGBE_RSC_CB(skb)->dma = 0;
1450 IXGBE_RSC_CB(skb)->delay_unmap = false;
1451 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001452 }
1453 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001454 if (ring_is_ps_enabled(rx_ring))
1455 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001456 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001457 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001458 rx_ring->rx_stats.rsc_count +=
1459 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001460 rx_ring->rx_stats.rsc_flush++;
1461 }
1462
1463 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001464 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1465 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001466 goto next_desc;
1467 }
1468
Alexander Duyckff886df2011-06-11 01:45:13 +00001469 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001470 if (adapter->netdev->features & NETIF_F_RXHASH)
1471 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001472
1473 /* probably a little skewed due to removing CRC */
1474 total_rx_bytes += skb->len;
1475 total_rx_packets++;
1476
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001477 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001478#ifdef IXGBE_FCOE
1479 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001480 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1481 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1482 staterr);
Yi Zou3d8fd382009-06-08 14:38:44 +00001483 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001484 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001485 }
Yi Zou332d4a72009-05-13 13:11:53 +00001486#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001487 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001488
1489next_desc:
1490 rx_desc->wb.upper.status_error = 0;
1491
Alexander Duyckc267fc12010-11-16 19:27:00 -08001492 (*work_done)++;
1493 if (*work_done >= work_to_do)
1494 break;
1495
Auke Kok9a799d72007-09-15 14:07:45 -07001496 /* return some buffers to hardware, one at a time is too slow */
1497 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001498 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001499 cleaned_count = 0;
1500 }
1501
1502 /* use prefetched values */
1503 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001504 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001505 }
1506
Auke Kok9a799d72007-09-15 14:07:45 -07001507 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001508 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001509
1510 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001511 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001512
Yi Zou3d8fd382009-06-08 14:38:44 +00001513#ifdef IXGBE_FCOE
1514 /* include DDPed FCoE data */
1515 if (ddp_bytes > 0) {
1516 unsigned int mss;
1517
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001518 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001519 sizeof(struct fc_frame_header) -
1520 sizeof(struct fcoe_crc_eof);
1521 if (mss > 512)
1522 mss &= ~511;
1523 total_rx_bytes += ddp_bytes;
1524 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1525 }
1526#endif /* IXGBE_FCOE */
1527
Alexander Duyckc267fc12010-11-16 19:27:00 -08001528 u64_stats_update_begin(&rx_ring->syncp);
1529 rx_ring->stats.packets += total_rx_packets;
1530 rx_ring->stats.bytes += total_rx_bytes;
1531 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001532 q_vector->rx.total_packets += total_rx_packets;
1533 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001534}
1535
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001536static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001537/**
1538 * ixgbe_configure_msix - Configure MSI-X hardware
1539 * @adapter: board private structure
1540 *
1541 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1542 * interrupts.
1543 **/
1544static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1545{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001546 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001547 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001549
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001550 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1551
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001552 /*
1553 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001554 * corresponding register.
1555 */
1556 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001557 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001558 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001559 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001560 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001561
Alexander Duyck08c88332011-06-11 01:45:03 +00001562 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001563 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1564 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001565 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001566 adapter->num_rx_queues,
1567 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001568 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001569 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001570 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001571
Alexander Duyck08c88332011-06-11 01:45:03 +00001572 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001573 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1574 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001575 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001576 adapter->num_tx_queues,
1577 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001578 }
1579
Alexander Duyck08c88332011-06-11 01:45:03 +00001580 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001581 /* tx only */
1582 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001583 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001584 /* rx or mixed */
1585 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001586
Alexander Duyckfe49f042009-06-04 16:00:09 +00001587 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001588 /* If ATR is enabled, set interrupt affinity */
1589 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001590 /*
1591 * Allocate the affinity_hint cpumask, assign the mask
1592 * for this vector, and set our affinity_hint for
1593 * this irq.
1594 */
1595 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1596 GFP_KERNEL))
1597 return;
1598 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1599 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1600 q_vector->affinity_mask);
1601 }
Auke Kok9a799d72007-09-15 14:07:45 -07001602 }
1603
Alexander Duyckbd508172010-11-16 19:27:03 -08001604 switch (adapter->hw.mac.type) {
1605 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001606 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001607 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001608 break;
1609 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001610 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001611 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001612 break;
1613
1614 default:
1615 break;
1616 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001617 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001618
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001619 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001620 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001621 if (adapter->num_vfs)
1622 mask &= ~(IXGBE_EIMS_OTHER |
1623 IXGBE_EIMS_MAILBOX |
1624 IXGBE_EIMS_LSC);
1625 else
1626 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001627 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001628}
1629
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001630enum latency_range {
1631 lowest_latency = 0,
1632 low_latency = 1,
1633 bulk_latency = 2,
1634 latency_invalid = 255
1635};
1636
1637/**
1638 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001639 * @q_vector: structure containing interrupt and ring information
1640 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001641 *
1642 * Stores a new ITR value based on packets and byte
1643 * counts during the last interrupt. The advantage of per interrupt
1644 * computation is faster updates and more accurate ITR for the current
1645 * traffic pattern. Constants in this function were computed
1646 * based on theoretical maximum wire speed and thresholds were set based
1647 * on testing data as well as attempting to minimize response time
1648 * while increasing bulk throughput.
1649 * this functionality is controlled by the InterruptThrottleRate module
1650 * parameter (see ixgbe_param.c)
1651 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001652static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1653 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001654{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001655 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001656 struct ixgbe_adapter *adapter = q_vector->adapter;
1657 int bytes = ring_container->total_bytes;
1658 int packets = ring_container->total_packets;
1659 u32 timepassed_us;
1660 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001661
1662 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001663 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001664
1665 /* simple throttlerate management
1666 * 0-20MB/s lowest (100000 ints/s)
1667 * 20-100MB/s low (20000 ints/s)
1668 * 100-1249MB/s bulk (8000 ints/s)
1669 */
1670 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001671 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001672 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1673
1674 switch (itr_setting) {
1675 case lowest_latency:
1676 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001677 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001678 break;
1679 case low_latency:
1680 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001681 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001682 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001683 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001684 break;
1685 case bulk_latency:
1686 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001687 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001688 break;
1689 }
1690
Alexander Duyckbd198052011-06-11 01:45:08 +00001691 /* clear work counters since we have the values we need */
1692 ring_container->total_bytes = 0;
1693 ring_container->total_packets = 0;
1694
1695 /* write updated itr to ring container */
1696 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001697}
1698
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001699/**
1700 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001701 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001702 *
1703 * This function is made to be called by ethtool and by the driver
1704 * when it needs to update EITR registers at runtime. Hardware
1705 * specific quirks/differences are taken care of here.
1706 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001707void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001708{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001709 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001710 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001711 int v_idx = q_vector->v_idx;
1712 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1713
Alexander Duyckbd508172010-11-16 19:27:03 -08001714 switch (adapter->hw.mac.type) {
1715 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001716 /* must write high and low 16 bits to reset counter */
1717 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001718 break;
1719 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001720 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001721 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001722 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001723 * max interrupt rate, but there is an errata where it can
1724 * not be zero with RSC
1725 */
1726 if (itr_reg == 8 &&
1727 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1728 itr_reg = 0;
1729
1730 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001731 * set the WDIS bit to not clear the timer bits and cause an
1732 * immediate assertion of the interrupt
1733 */
1734 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001735 break;
1736 default:
1737 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001738 }
1739 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1740}
1741
Alexander Duyckbd198052011-06-11 01:45:08 +00001742static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001743{
Alexander Duyckbd198052011-06-11 01:45:08 +00001744 u32 new_itr = q_vector->eitr;
1745 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001746
Alexander Duyckbd198052011-06-11 01:45:08 +00001747 ixgbe_update_itr(q_vector, &q_vector->tx);
1748 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001749
Alexander Duyck08c88332011-06-11 01:45:03 +00001750 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001751
1752 switch (current_itr) {
1753 /* counts and packets in update_itr are dependent on these numbers */
1754 case lowest_latency:
1755 new_itr = 100000;
1756 break;
1757 case low_latency:
1758 new_itr = 20000; /* aka hwitr = ~200 */
1759 break;
1760 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001761 new_itr = 8000;
1762 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001763 default:
1764 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001765 }
1766
1767 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001768 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001769 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001770
Alexander Duyckbd198052011-06-11 01:45:08 +00001771 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001772 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001773
1774 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001775 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001776}
1777
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001778/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001779 * ixgbe_check_overtemp_subtask - check for over tempurature
1780 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001781 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001782static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001783{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001784 struct ixgbe_hw *hw = &adapter->hw;
1785 u32 eicr = adapter->interrupt_event;
1786
Alexander Duyckf0f97782011-04-22 04:08:09 +00001787 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001788 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001789
Alexander Duyckf0f97782011-04-22 04:08:09 +00001790 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1791 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1792 return;
1793
1794 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1795
Joe Perches7ca647b2010-09-07 21:35:40 +00001796 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001797 case IXGBE_DEV_ID_82599_T3_LOM:
1798 /*
1799 * Since the warning interrupt is for both ports
1800 * we don't have to check if:
1801 * - This interrupt wasn't for our port.
1802 * - We may have missed the interrupt so always have to
1803 * check if we got a LSC
1804 */
1805 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1806 !(eicr & IXGBE_EICR_LSC))
1807 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001808
Alexander Duyckf0f97782011-04-22 04:08:09 +00001809 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1810 u32 autoneg;
1811 bool link_up = false;
1812
Joe Perches7ca647b2010-09-07 21:35:40 +00001813 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1814
Alexander Duyckf0f97782011-04-22 04:08:09 +00001815 if (link_up)
1816 return;
1817 }
1818
1819 /* Check if this is not due to overtemp */
1820 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1821 return;
1822
1823 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001824 default:
1825 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1826 return;
1827 break;
1828 }
1829 e_crit(drv,
1830 "Network adapter has been stopped because it has over heated. "
1831 "Restart the computer. If the problem persists, "
1832 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001833
1834 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001835}
1836
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001837static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1838{
1839 struct ixgbe_hw *hw = &adapter->hw;
1840
1841 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1842 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001843 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001844 /* write to clear the interrupt */
1845 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1846 }
1847}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001848
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001849static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1850{
1851 struct ixgbe_hw *hw = &adapter->hw;
1852
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001853 if (eicr & IXGBE_EICR_GPI_SDP2) {
1854 /* Clear the interrupt */
1855 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001856 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1857 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1858 ixgbe_service_event_schedule(adapter);
1859 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001860 }
1861
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001862 if (eicr & IXGBE_EICR_GPI_SDP1) {
1863 /* Clear the interrupt */
1864 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001865 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1866 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1867 ixgbe_service_event_schedule(adapter);
1868 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001869 }
1870}
1871
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001872static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1873{
1874 struct ixgbe_hw *hw = &adapter->hw;
1875
1876 adapter->lsc_int++;
1877 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1878 adapter->link_check_timeout = jiffies;
1879 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1880 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001881 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001882 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001883 }
1884}
1885
Auke Kok9a799d72007-09-15 14:07:45 -07001886static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1887{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001888 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001889 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001890 u32 eicr;
1891
1892 /*
1893 * Workaround for Silicon errata. Use clear-by-write instead
1894 * of clear-by-read. Reading with EICS will return the
1895 * interrupt causes without clearing, which later be done
1896 * with the write to EICR.
1897 */
1898 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1899 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001900
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001901 if (eicr & IXGBE_EICR_LSC)
1902 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001903
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001904 if (eicr & IXGBE_EICR_MAILBOX)
1905 ixgbe_msg_task(adapter);
1906
Alexander Duyckbd508172010-11-16 19:27:03 -08001907 switch (hw->mac.type) {
1908 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001909 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001910 /* Handle Flow Director Full threshold interrupt */
1911 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001912 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001913 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001914 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001915 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001916 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001917 &ring->state))
1918 reinit_count++;
1919 }
1920 if (reinit_count) {
1921 /* no more flow director interrupts until after init */
1922 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1923 eicr &= ~IXGBE_EICR_FLOW_DIR;
1924 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1925 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001926 }
1927 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001928 ixgbe_check_sfp_event(adapter, eicr);
1929 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1930 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1931 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1932 adapter->interrupt_event = eicr;
1933 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1934 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001935 }
1936 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001937 break;
1938 default:
1939 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001940 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001941
1942 ixgbe_check_fan_failure(adapter, eicr);
1943
Alexander Duyck70864002011-04-27 09:13:56 +00001944 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001945 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001946 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1947 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001948
1949 return IRQ_HANDLED;
1950}
1951
Alexander Duyckfe49f042009-06-04 16:00:09 +00001952static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1953 u64 qmask)
1954{
1955 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001956 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001957
Alexander Duyckbd508172010-11-16 19:27:03 -08001958 switch (hw->mac.type) {
1959 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001960 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001961 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1962 break;
1963 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001964 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001965 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001966 if (mask)
1967 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001968 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001969 if (mask)
1970 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1971 break;
1972 default:
1973 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001974 }
1975 /* skip the flush */
1976}
1977
1978static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001979 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001980{
1981 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001982 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001983
Alexander Duyckbd508172010-11-16 19:27:03 -08001984 switch (hw->mac.type) {
1985 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001986 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001987 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1988 break;
1989 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001990 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001991 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001992 if (mask)
1993 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001994 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001995 if (mask)
1996 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1997 break;
1998 default:
1999 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002000 }
2001 /* skip the flush */
2002}
2003
Auke Kok9a799d72007-09-15 14:07:45 -07002004static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2005{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002006 struct ixgbe_q_vector *q_vector = data;
2007 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002008 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002009 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002010
Alexander Duyck08c88332011-06-11 01:45:03 +00002011 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002012 return IRQ_HANDLED;
2013
Alexander Duyck08c88332011-06-11 01:45:03 +00002014 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2015 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002016 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002017 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002018 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002019 }
2020
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002021 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002022 napi_schedule(&q_vector->napi);
2023
Auke Kok9a799d72007-09-15 14:07:45 -07002024 return IRQ_HANDLED;
2025}
2026
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002027/**
2028 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2029 * @irq: unused
2030 * @data: pointer to our q_vector struct for this interrupt vector
2031 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002032static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2033{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002034 struct ixgbe_q_vector *q_vector = data;
2035 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002036 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002037 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002038 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002039
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002040#ifdef CONFIG_IXGBE_DCA
2041 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2042 ixgbe_update_dca(q_vector);
2043#endif
2044
Alexander Duyck08c88332011-06-11 01:45:03 +00002045 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2046 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002047 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002048 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002049 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002050 }
2051
Alexander Duyck08c88332011-06-11 01:45:03 +00002052 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002053 return IRQ_HANDLED;
2054
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002055 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002056 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002057
Auke Kok9a799d72007-09-15 14:07:45 -07002058 return IRQ_HANDLED;
2059}
2060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002061static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2062{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002063 struct ixgbe_q_vector *q_vector = data;
2064 struct ixgbe_adapter *adapter = q_vector->adapter;
2065 struct ixgbe_ring *ring;
2066 int r_idx;
2067 int i;
2068
Alexander Duyck08c88332011-06-11 01:45:03 +00002069 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002070 return IRQ_HANDLED;
2071
Alexander Duyck08c88332011-06-11 01:45:03 +00002072 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2073 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002074 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002075 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002076 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002077 }
2078
Alexander Duyck08c88332011-06-11 01:45:03 +00002079 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2080 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002081 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002082 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002083 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002084 }
2085
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002086 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002087 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002088
2089 return IRQ_HANDLED;
2090}
2091
2092/**
2093 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2094 * @napi: napi struct with our devices info in it
2095 * @budget: amount of work driver is allowed to do this pass, in packets
2096 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002097 * This function is optimized for cleaning one queue only on a single
2098 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002099 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002100static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2101{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002102 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002103 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002104 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002105 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002106 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002107 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002108
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002109#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002110 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002111 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002112#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002113
Alexander Duyck08c88332011-06-11 01:45:03 +00002114 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002115 rx_ring = adapter->rx_ring[r_idx];
2116
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002117 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002118
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002119 /* If all Rx work done, exit the polling mode */
2120 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002121 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002122 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002123 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002124 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002125 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002126 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002127 }
2128
2129 return work_done;
2130}
2131
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002132/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002133 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002134 * @napi: napi struct with our devices info in it
2135 * @budget: amount of work driver is allowed to do this pass, in packets
2136 *
2137 * This function will clean more than one rx queue associated with a
2138 * q_vector.
2139 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002140static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002141{
2142 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002143 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002144 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002145 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002146 int work_done = 0, i;
2147 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002148 bool tx_clean_complete = true;
2149
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002150#ifdef CONFIG_IXGBE_DCA
2151 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2152 ixgbe_update_dca(q_vector);
2153#endif
2154
Alexander Duyck08c88332011-06-11 01:45:03 +00002155 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2156 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002157 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002158 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002159 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002160 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002161 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002162
2163 /* attempt to distribute budget to each queue fairly, but don't allow
2164 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002165 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002166 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002167 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2168 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002169 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002170 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002171 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002172 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002173 }
2174
Alexander Duyck08c88332011-06-11 01:45:03 +00002175 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002176 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002177 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002178 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002179 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002180 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002181 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002182 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002183 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002184 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002185 return 0;
2186 }
2187
2188 return work_done;
2189}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002190
2191/**
2192 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2193 * @napi: napi struct with our devices info in it
2194 * @budget: amount of work driver is allowed to do this pass, in packets
2195 *
2196 * This function is optimized for cleaning one queue only on a single
2197 * q_vector!!!
2198 **/
2199static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2200{
2201 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002202 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002203 struct ixgbe_adapter *adapter = q_vector->adapter;
2204 struct ixgbe_ring *tx_ring = NULL;
2205 int work_done = 0;
2206 long r_idx;
2207
Alexander Duyck91281fd2009-06-04 16:00:27 +00002208#ifdef CONFIG_IXGBE_DCA
2209 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002210 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002211#endif
2212
Alexander Duyck08c88332011-06-11 01:45:03 +00002213 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002214 tx_ring = adapter->tx_ring[r_idx];
2215
Alexander Duyck91281fd2009-06-04 16:00:27 +00002216 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2217 work_done = budget;
2218
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002219 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002220 if (work_done < budget) {
2221 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002222 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002223 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002224 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002225 ixgbe_irq_enable_queues(adapter,
2226 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002227 }
2228
2229 return work_done;
2230}
2231
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002232static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002233 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002234{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002235 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002236 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002237
Alexander Duyck08c88332011-06-11 01:45:03 +00002238 set_bit(r_idx, q_vector->rx.idx);
2239 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002240 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002241}
Auke Kok9a799d72007-09-15 14:07:45 -07002242
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002243static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002244 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002246 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002247 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002248
Alexander Duyck08c88332011-06-11 01:45:03 +00002249 set_bit(t_idx, q_vector->tx.idx);
2250 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002251 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002252 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002253}
Auke Kok9a799d72007-09-15 14:07:45 -07002254
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002255/**
2256 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2257 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002258 *
2259 * This function maps descriptor rings to the queue-specific vectors
2260 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2261 * one vector per ring/queue, but on a constrained vector budget, we
2262 * group the rings as "efficiently" as possible. You would add new
2263 * mapping configurations in here.
2264 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002265static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002266{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002267 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268 int v_start = 0;
2269 int rxr_idx = 0, txr_idx = 0;
2270 int rxr_remaining = adapter->num_rx_queues;
2271 int txr_remaining = adapter->num_tx_queues;
2272 int i, j;
2273 int rqpv, tqpv;
2274 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002275
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002276 /* No mapping required if MSI-X is disabled. */
2277 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002278 goto out;
2279
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002280 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2281
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002282 /*
2283 * The ideal configuration...
2284 * We have enough vectors to map one per queue.
2285 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002286 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002287 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2288 map_vector_to_rxq(adapter, v_start, rxr_idx);
2289
2290 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2291 map_vector_to_txq(adapter, v_start, txr_idx);
2292
2293 goto out;
2294 }
2295
2296 /*
2297 * If we don't have enough vectors for a 1-to-1
2298 * mapping, we'll have to group them so there are
2299 * multiple queues per vector.
2300 */
2301 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002302 for (i = v_start; i < q_vectors; i++) {
2303 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002304 for (j = 0; j < rqpv; j++) {
2305 map_vector_to_rxq(adapter, i, rxr_idx);
2306 rxr_idx++;
2307 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002308 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002309 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002310 for (j = 0; j < tqpv; j++) {
2311 map_vector_to_txq(adapter, i, txr_idx);
2312 txr_idx++;
2313 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002314 }
Auke Kok9a799d72007-09-15 14:07:45 -07002315 }
Auke Kok9a799d72007-09-15 14:07:45 -07002316out:
Auke Kok9a799d72007-09-15 14:07:45 -07002317 return err;
2318}
2319
2320/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002321 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2322 * @adapter: board private structure
2323 *
2324 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2325 * interrupts from the kernel.
2326 **/
2327static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2328{
2329 struct net_device *netdev = adapter->netdev;
2330 irqreturn_t (*handler)(int, void *);
2331 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002332 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002333
2334 /* Decrement for Other and TCP Timer vectors */
2335 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2336
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002337 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002338 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002339 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002340
Alexander Duyck08c88332011-06-11 01:45:03 +00002341#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002342 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002343 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2344 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002345 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002346 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002347 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2348 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002349
Joe Perchese8e9f692010-09-07 21:34:53 +00002350 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002351 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2352 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002353 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002354 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2355 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002356 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002357 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2358 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002359 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002360 } else {
2361 /* skip this unused q_vector */
2362 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002363 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002364 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002365 handler, 0, q_vector->name,
2366 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002368 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002369 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002370 goto free_queue_irqs;
2371 }
2372 }
2373
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002374 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002375 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002376 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002377 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002378 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002379 goto free_queue_irqs;
2380 }
2381
2382 return 0;
2383
2384free_queue_irqs:
2385 for (i = vector - 1; i >= 0; i--)
2386 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002387 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002388 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2389 pci_disable_msix(adapter->pdev);
2390 kfree(adapter->msix_entries);
2391 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002392 return err;
2393}
2394
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002395/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002396 * ixgbe_irq_enable - Enable default interrupt generation settings
2397 * @adapter: board private structure
2398 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002399static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2400 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002401{
2402 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002403
2404 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002405 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2406 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002407 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2408 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002409 switch (adapter->hw.mac.type) {
2410 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002411 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002412 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002413 mask |= IXGBE_EIMS_GPI_SDP1;
2414 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002415 if (adapter->num_vfs)
2416 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002417 break;
2418 default:
2419 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002420 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002421 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002422 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002423
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002424 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002425 if (queues)
2426 ixgbe_irq_enable_queues(adapter, ~0);
2427 if (flush)
2428 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002429
2430 if (adapter->num_vfs > 32) {
2431 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2432 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2433 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002434}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002435
2436/**
2437 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002438 * @irq: interrupt number
2439 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002440 **/
2441static irqreturn_t ixgbe_intr(int irq, void *data)
2442{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002443 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002444 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002445 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002446 u32 eicr;
2447
Don Skidmore54037502009-02-21 15:42:56 -08002448 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002449 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002450 * before the read of EICR.
2451 */
2452 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2453
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002454 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2455 * therefore no explict interrupt disable is necessary */
2456 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002457 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002458 /*
2459 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002460 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002461 * have disabled interrupts due to EIAM
2462 * finish the workaround of silicon errata on 82598. Unmask
2463 * the interrupt that we masked before the EICR read.
2464 */
2465 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2466 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002467 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002468 }
Auke Kok9a799d72007-09-15 14:07:45 -07002469
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002470 if (eicr & IXGBE_EICR_LSC)
2471 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002472
Alexander Duyckbd508172010-11-16 19:27:03 -08002473 switch (hw->mac.type) {
2474 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002475 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002476 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2477 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002478 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2479 adapter->interrupt_event = eicr;
2480 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2481 ixgbe_service_event_schedule(adapter);
2482 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002483 }
2484 break;
2485 default:
2486 break;
2487 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002488
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002489 ixgbe_check_fan_failure(adapter, eicr);
2490
Alexander Duyck7a921c92009-05-06 10:43:28 +00002491 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002492 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002493 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002494 }
2495
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002496 /*
2497 * re-enable link(maybe) and non-queue interrupts, no flush.
2498 * ixgbe_poll will re-enable the queue interrupts
2499 */
2500
2501 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2502 ixgbe_irq_enable(adapter, false, false);
2503
Auke Kok9a799d72007-09-15 14:07:45 -07002504 return IRQ_HANDLED;
2505}
2506
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002507static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2508{
2509 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2510
2511 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002512 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002513 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2514 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2515 q_vector->rx.count = 0;
2516 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002517 }
2518}
2519
Auke Kok9a799d72007-09-15 14:07:45 -07002520/**
2521 * ixgbe_request_irq - initialize interrupts
2522 * @adapter: board private structure
2523 *
2524 * Attempts to configure interrupts using the best available
2525 * capabilities of the hardware and kernel.
2526 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002527static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002528{
2529 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002530 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002531
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2533 err = ixgbe_request_msix_irqs(adapter);
2534 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002535 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002536 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002537 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002538 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002539 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002540 }
2541
Auke Kok9a799d72007-09-15 14:07:45 -07002542 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002543 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002544
Auke Kok9a799d72007-09-15 14:07:45 -07002545 return err;
2546}
2547
2548static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2549{
Auke Kok9a799d72007-09-15 14:07:45 -07002550 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002551 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002552
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 q_vectors = adapter->num_msix_vectors;
2554
2555 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002556 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 i--;
2559 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002560 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002561 if (!adapter->q_vector[i]->rx.count &&
2562 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002563 continue;
2564
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002566 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 }
2568
2569 ixgbe_reset_q_vectors(adapter);
2570 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002571 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002572 }
2573}
2574
2575/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002576 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2577 * @adapter: board private structure
2578 **/
2579static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2580{
Alexander Duyckbd508172010-11-16 19:27:03 -08002581 switch (adapter->hw.mac.type) {
2582 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002583 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002584 break;
2585 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002586 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002587 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2588 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002589 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002590 if (adapter->num_vfs > 32)
2591 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002592 break;
2593 default:
2594 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002595 }
2596 IXGBE_WRITE_FLUSH(&adapter->hw);
2597 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2598 int i;
2599 for (i = 0; i < adapter->num_msix_vectors; i++)
2600 synchronize_irq(adapter->msix_entries[i].vector);
2601 } else {
2602 synchronize_irq(adapter->pdev->irq);
2603 }
2604}
2605
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002606/**
Auke Kok9a799d72007-09-15 14:07:45 -07002607 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2608 *
2609 **/
2610static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2611{
Auke Kok9a799d72007-09-15 14:07:45 -07002612 struct ixgbe_hw *hw = &adapter->hw;
2613
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002614 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002615 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002616
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002617 ixgbe_set_ivar(adapter, 0, 0, 0);
2618 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002619
2620 map_vector_to_rxq(adapter, 0, 0);
2621 map_vector_to_txq(adapter, 0, 0);
2622
Emil Tantilov396e7992010-07-01 20:05:12 +00002623 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002624}
2625
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002626/**
2627 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2628 * @adapter: board private structure
2629 * @ring: structure containing ring specific data
2630 *
2631 * Configure the Tx descriptor ring after a reset.
2632 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002633void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2634 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002635{
2636 struct ixgbe_hw *hw = &adapter->hw;
2637 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002638 int wait_loop = 10;
2639 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002640 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002641
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002642 /* disable queue to avoid issues while updating state */
2643 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2644 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2645 txdctl & ~IXGBE_TXDCTL_ENABLE);
2646 IXGBE_WRITE_FLUSH(hw);
2647
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002648 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002649 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002650 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2651 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2652 ring->count * sizeof(union ixgbe_adv_tx_desc));
2653 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2654 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002655 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002656
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002657 /* configure fetching thresholds */
2658 if (adapter->rx_itr_setting == 0) {
2659 /* cannot set wthresh when itr==0 */
2660 txdctl &= ~0x007F0000;
2661 } else {
2662 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2663 txdctl |= (8 << 16);
2664 }
2665 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2666 /* PThresh workaround for Tx hang with DFP enabled. */
2667 txdctl |= 32;
2668 }
2669
2670 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002671 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2672 adapter->atr_sample_rate) {
2673 ring->atr_sample_rate = adapter->atr_sample_rate;
2674 ring->atr_count = 0;
2675 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2676 } else {
2677 ring->atr_sample_rate = 0;
2678 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002679
John Fastabendc84d3242010-11-16 19:27:12 -08002680 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2681
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002682 /* enable queue */
2683 txdctl |= IXGBE_TXDCTL_ENABLE;
2684 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2685
2686 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2687 if (hw->mac.type == ixgbe_mac_82598EB &&
2688 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2689 return;
2690
2691 /* poll to verify queue is enabled */
2692 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002693 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002694 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2695 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2696 if (!wait_loop)
2697 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002698}
2699
Alexander Duyck120ff942010-08-19 13:34:50 +00002700static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2701{
2702 struct ixgbe_hw *hw = &adapter->hw;
2703 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002704 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002705 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002706
2707 if (hw->mac.type == ixgbe_mac_82598EB)
2708 return;
2709
2710 /* disable the arbiter while setting MTQC */
2711 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2712 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2713 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2714
2715 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002716 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002717 case (IXGBE_FLAG_SRIOV_ENABLED):
2718 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2719 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2720 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002721 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002722 if (!tcs)
2723 reg = IXGBE_MTQC_64Q_1PB;
2724 else if (tcs <= 4)
2725 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2726 else
2727 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2728
2729 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2730
2731 /* Enable Security TX Buffer IFG for multiple pb */
2732 if (tcs) {
2733 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2734 reg |= IXGBE_SECTX_DCB;
2735 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2736 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002737 break;
2738 }
2739
2740 /* re-enable the arbiter */
2741 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2742 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2743}
2744
Auke Kok9a799d72007-09-15 14:07:45 -07002745/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002746 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002747 * @adapter: board private structure
2748 *
2749 * Configure the Tx unit of the MAC after a reset.
2750 **/
2751static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2752{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002753 struct ixgbe_hw *hw = &adapter->hw;
2754 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002755 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002756
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002757 ixgbe_setup_mtqc(adapter);
2758
2759 if (hw->mac.type != ixgbe_mac_82598EB) {
2760 /* DMATXCTL.EN must be before Tx queues are enabled */
2761 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2762 dmatxctl |= IXGBE_DMATXCTL_TE;
2763 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2764 }
2765
Auke Kok9a799d72007-09-15 14:07:45 -07002766 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002767 for (i = 0; i < adapter->num_tx_queues; i++)
2768 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002769}
2770
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002771#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002772
Yi Zoua6616b42009-08-06 13:05:23 +00002773static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002774 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002775{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002776 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002777 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002778
Alexander Duyckbd508172010-11-16 19:27:03 -08002779 switch (adapter->hw.mac.type) {
2780 case ixgbe_mac_82598EB: {
2781 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2782 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002783 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002784 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002785 break;
2786 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002787 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002788 default:
2789 break;
2790 }
2791
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002792 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002793
2794 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2795 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002796 if (adapter->num_vfs)
2797 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002798
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002799 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2800 IXGBE_SRRCTL_BSIZEHDR_MASK;
2801
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002802 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002803#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2804 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2805#else
2806 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2807#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002808 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002809 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002810 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2811 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002812 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002813 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002814
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002815 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002816}
2817
Alexander Duyck05abb122010-08-19 13:35:41 +00002818static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002819{
Alexander Duyck05abb122010-08-19 13:35:41 +00002820 struct ixgbe_hw *hw = &adapter->hw;
2821 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002822 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2823 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002824 u32 mrqc = 0, reta = 0;
2825 u32 rxcsum;
2826 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002827 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002828 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2829
2830 if (tcs)
2831 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002832
Alexander Duyck05abb122010-08-19 13:35:41 +00002833 /* Fill out hash function seeds */
2834 for (i = 0; i < 10; i++)
2835 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002836
Alexander Duyck05abb122010-08-19 13:35:41 +00002837 /* Fill out redirection table */
2838 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002839 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002840 j = 0;
2841 /* reta = 4-byte sliding window of
2842 * 0x00..(indices-1)(indices-1)00..etc. */
2843 reta = (reta << 8) | (j * 0x11);
2844 if ((i & 3) == 3)
2845 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2846 }
2847
2848 /* Disable indicating checksum in descriptor, enables RSS hash */
2849 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2850 rxcsum |= IXGBE_RXCSUM_PCSD;
2851 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2852
John Fastabend8b1c0b22011-05-03 02:26:48 +00002853 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2854 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002855 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002856 } else {
2857 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2858 | IXGBE_FLAG_SRIOV_ENABLED);
2859
2860 switch (mask) {
2861 case (IXGBE_FLAG_RSS_ENABLED):
2862 if (!tcs)
2863 mrqc = IXGBE_MRQC_RSSEN;
2864 else if (tcs <= 4)
2865 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2866 else
2867 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2868 break;
2869 case (IXGBE_FLAG_SRIOV_ENABLED):
2870 mrqc = IXGBE_MRQC_VMDQEN;
2871 break;
2872 default:
2873 break;
2874 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002875 }
2876
Alexander Duyck05abb122010-08-19 13:35:41 +00002877 /* Perform hash on these packet types */
2878 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2879 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2880 | IXGBE_MRQC_RSS_FIELD_IPV6
2881 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2882
2883 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002884}
2885
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002886/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002887 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2888 * @adapter: address of board private structure
2889 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002890 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002891static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002892 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002893{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002894 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002895 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002896 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002897 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002898
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002899 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002900 return;
2901
2902 rx_buf_len = ring->rx_buf_len;
2903 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002904 rscctrl |= IXGBE_RSCCTL_RSCEN;
2905 /*
2906 * we must limit the number of descriptors so that the
2907 * total size of max desc * buf_len is not greater
2908 * than 65535
2909 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002910 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002911#if (MAX_SKB_FRAGS > 16)
2912 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2913#elif (MAX_SKB_FRAGS > 8)
2914 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2915#elif (MAX_SKB_FRAGS > 4)
2916 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2917#else
2918 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2919#endif
2920 } else {
2921 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2922 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2923 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2924 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2925 else
2926 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2927 }
Alexander Duyck73670962010-08-19 13:38:34 +00002928 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002929}
2930
Alexander Duyck9e10e042010-08-19 13:40:06 +00002931/**
2932 * ixgbe_set_uta - Set unicast filter table address
2933 * @adapter: board private structure
2934 *
2935 * The unicast table address is a register array of 32-bit registers.
2936 * The table is meant to be used in a way similar to how the MTA is used
2937 * however due to certain limitations in the hardware it is necessary to
2938 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2939 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2940 **/
2941static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2942{
2943 struct ixgbe_hw *hw = &adapter->hw;
2944 int i;
2945
2946 /* The UTA table only exists on 82599 hardware and newer */
2947 if (hw->mac.type < ixgbe_mac_82599EB)
2948 return;
2949
2950 /* we only need to do this if VMDq is enabled */
2951 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2952 return;
2953
2954 for (i = 0; i < 128; i++)
2955 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2956}
2957
2958#define IXGBE_MAX_RX_DESC_POLL 10
2959static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2960 struct ixgbe_ring *ring)
2961{
2962 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002963 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2964 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002965 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002966
2967 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2968 if (hw->mac.type == ixgbe_mac_82598EB &&
2969 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2970 return;
2971
2972 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002973 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002974 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2975 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2976
2977 if (!wait_loop) {
2978 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2979 "the polling period\n", reg_idx);
2980 }
2981}
2982
Yi Zou2d39d572011-01-06 14:29:56 +00002983void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2984 struct ixgbe_ring *ring)
2985{
2986 struct ixgbe_hw *hw = &adapter->hw;
2987 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2988 u32 rxdctl;
2989 u8 reg_idx = ring->reg_idx;
2990
2991 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2992 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2993
2994 /* write value back with RXDCTL.ENABLE bit cleared */
2995 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2996
2997 if (hw->mac.type == ixgbe_mac_82598EB &&
2998 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2999 return;
3000
3001 /* the hardware may take up to 100us to really disable the rx queue */
3002 do {
3003 udelay(10);
3004 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3005 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3006
3007 if (!wait_loop) {
3008 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3009 "the polling period\n", reg_idx);
3010 }
3011}
3012
Alexander Duyck84418e32010-08-19 13:40:54 +00003013void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3014 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003015{
3016 struct ixgbe_hw *hw = &adapter->hw;
3017 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003018 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003019 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003020
Alexander Duyck9e10e042010-08-19 13:40:06 +00003021 /* disable queue to avoid issues while updating state */
3022 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003023 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003024
Alexander Duyckacd37172010-08-19 13:36:05 +00003025 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3026 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3027 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3028 ring->count * sizeof(union ixgbe_adv_rx_desc));
3029 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3030 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003031 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003032
3033 ixgbe_configure_srrctl(adapter, ring);
3034 ixgbe_configure_rscctl(adapter, ring);
3035
Greg Rosee9f98072011-01-26 01:06:07 +00003036 /* If operating in IOV mode set RLPML for X540 */
3037 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3038 hw->mac.type == ixgbe_mac_X540) {
3039 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3040 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3041 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3042 }
3043
Alexander Duyck9e10e042010-08-19 13:40:06 +00003044 if (hw->mac.type == ixgbe_mac_82598EB) {
3045 /*
3046 * enable cache line friendly hardware writes:
3047 * PTHRESH=32 descriptors (half the internal cache),
3048 * this also removes ugly rx_no_buffer_count increment
3049 * HTHRESH=4 descriptors (to minimize latency on fetch)
3050 * WTHRESH=8 burst writeback up to two cache lines
3051 */
3052 rxdctl &= ~0x3FFFFF;
3053 rxdctl |= 0x080420;
3054 }
3055
3056 /* enable receive descriptor ring */
3057 rxdctl |= IXGBE_RXDCTL_ENABLE;
3058 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3059
3060 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003061 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003062}
3063
Alexander Duyck48654522010-08-19 13:36:27 +00003064static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3065{
3066 struct ixgbe_hw *hw = &adapter->hw;
3067 int p;
3068
3069 /* PSRTYPE must be initialized in non 82598 adapters */
3070 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003071 IXGBE_PSRTYPE_UDPHDR |
3072 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003073 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003074 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003075
3076 if (hw->mac.type == ixgbe_mac_82598EB)
3077 return;
3078
3079 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3080 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3081
3082 for (p = 0; p < adapter->num_rx_pools; p++)
3083 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3084 psrtype);
3085}
3086
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003087static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3088{
3089 struct ixgbe_hw *hw = &adapter->hw;
3090 u32 gcr_ext;
3091 u32 vt_reg_bits;
3092 u32 reg_offset, vf_shift;
3093 u32 vmdctl;
3094
3095 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3096 return;
3097
3098 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3099 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3100 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3101 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3102
3103 vf_shift = adapter->num_vfs % 32;
3104 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3105
3106 /* Enable only the PF's pool for Tx/Rx */
3107 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3108 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3109 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3110 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3111 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3112
3113 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3114 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3115
3116 /*
3117 * Set up VF register offsets for selected VT Mode,
3118 * i.e. 32 or 64 VFs for SR-IOV
3119 */
3120 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3121 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3122 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3123 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3124
3125 /* enable Tx loopback for VF/PF communication */
3126 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003127 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003128 hw->mac.ops.set_mac_anti_spoofing(hw,
3129 (adapter->antispoofing_enabled =
3130 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003131 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003132}
3133
Alexander Duyck477de6e2010-08-19 13:38:11 +00003134static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003135{
Auke Kok9a799d72007-09-15 14:07:45 -07003136 struct ixgbe_hw *hw = &adapter->hw;
3137 struct net_device *netdev = adapter->netdev;
3138 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003139 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003140 struct ixgbe_ring *rx_ring;
3141 int i;
3142 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003143
Auke Kok9a799d72007-09-15 14:07:45 -07003144 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003145 /* On by default */
3146 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3147
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003148 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003149 if (adapter->num_vfs)
3150 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3151
3152 /* Disable packet split due to 82599 erratum #45 */
3153 if (hw->mac.type == ixgbe_mac_82599EB)
3154 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003155
3156 /* Set the RX buffer length according to the mode */
3157 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003158 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003159 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003160 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003161 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003162 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003163 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003164 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3165 }
3166
3167#ifdef IXGBE_FCOE
3168 /* adjust max frame to be able to do baby jumbo for FCoE */
3169 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3170 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3171 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3172
3173#endif /* IXGBE_FCOE */
3174 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3175 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3176 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3177 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3178
3179 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003180 }
3181
Auke Kok9a799d72007-09-15 14:07:45 -07003182 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003183 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3184 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003185 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3186
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003187 /*
3188 * Setup the HW Rx Head and Tail Descriptor Pointers and
3189 * the Base and Length of the Rx Descriptor Ring
3190 */
Auke Kok9a799d72007-09-15 14:07:45 -07003191 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003192 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003193 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003194
Yi Zou6e455b892009-08-06 13:05:44 +00003195 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003196 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003197 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003198 clear_ring_ps_enabled(rx_ring);
3199
3200 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3201 set_ring_rsc_enabled(rx_ring);
3202 else
3203 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003204
Yi Zou63f39bd2009-05-17 12:34:35 +00003205#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003206 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003207 struct ixgbe_ring_feature *f;
3208 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003209 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003210 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003211 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3212 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003213 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003214 } else if (!ring_is_rsc_enabled(rx_ring) &&
3215 !ring_is_ps_enabled(rx_ring)) {
3216 rx_ring->rx_buf_len =
3217 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003218 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003219 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003220#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003221 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003222}
3223
Alexander Duyck73670962010-08-19 13:38:34 +00003224static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3225{
3226 struct ixgbe_hw *hw = &adapter->hw;
3227 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3228
3229 switch (hw->mac.type) {
3230 case ixgbe_mac_82598EB:
3231 /*
3232 * For VMDq support of different descriptor types or
3233 * buffer sizes through the use of multiple SRRCTL
3234 * registers, RDRXCTL.MVMEN must be set to 1
3235 *
3236 * also, the manual doesn't mention it clearly but DCA hints
3237 * will only use queue 0's tags unless this bit is set. Side
3238 * effects of setting this bit are only that SRRCTL must be
3239 * fully programmed [0..15]
3240 */
3241 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3242 break;
3243 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003244 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003245 /* Disable RSC for ACK packets */
3246 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3247 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3248 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3249 /* hardware requires some bits to be set by default */
3250 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3251 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3252 break;
3253 default:
3254 /* We should do nothing since we don't know this hardware */
3255 return;
3256 }
3257
3258 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3259}
3260
Alexander Duyck477de6e2010-08-19 13:38:11 +00003261/**
3262 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3263 * @adapter: board private structure
3264 *
3265 * Configure the Rx unit of the MAC after a reset.
3266 **/
3267static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3268{
3269 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003270 int i;
3271 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003272
3273 /* disable receives while setting up the descriptors */
3274 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3275 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3276
3277 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003278 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003279
Alexander Duyck9e10e042010-08-19 13:40:06 +00003280 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003281 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003282
Alexander Duyck9e10e042010-08-19 13:40:06 +00003283 ixgbe_set_uta(adapter);
3284
Alexander Duyck477de6e2010-08-19 13:38:11 +00003285 /* set_rx_buffer_len must be called before ring initialization */
3286 ixgbe_set_rx_buffer_len(adapter);
3287
3288 /*
3289 * Setup the HW Rx Head and Tail Descriptor Pointers and
3290 * the Base and Length of the Rx Descriptor Ring
3291 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003292 for (i = 0; i < adapter->num_rx_queues; i++)
3293 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003294
Alexander Duyck9e10e042010-08-19 13:40:06 +00003295 /* disable drop enable for 82598 parts */
3296 if (hw->mac.type == ixgbe_mac_82598EB)
3297 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3298
3299 /* enable all receives */
3300 rxctrl |= IXGBE_RXCTRL_RXEN;
3301 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003302}
3303
Auke Kok9a799d72007-09-15 14:07:45 -07003304static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3305{
3306 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003307 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003308 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003309
3310 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003311 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003312 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003313}
3314
3315static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3316{
3317 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003318 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003319 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003320
Auke Kok9a799d72007-09-15 14:07:45 -07003321 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003322 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003323 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003324}
3325
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003326/**
3327 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3328 * @adapter: driver data
3329 */
3330static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3331{
3332 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003333 u32 vlnctrl;
3334
3335 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3336 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3337 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3338}
3339
3340/**
3341 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3342 * @adapter: driver data
3343 */
3344static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3345{
3346 struct ixgbe_hw *hw = &adapter->hw;
3347 u32 vlnctrl;
3348
3349 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3350 vlnctrl |= IXGBE_VLNCTRL_VFE;
3351 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3352 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3353}
3354
3355/**
3356 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3357 * @adapter: driver data
3358 */
3359static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3360{
3361 struct ixgbe_hw *hw = &adapter->hw;
3362 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003363 int i, j;
3364
3365 switch (hw->mac.type) {
3366 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003367 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3368 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003369 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3370 break;
3371 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003372 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003373 for (i = 0; i < adapter->num_rx_queues; i++) {
3374 j = adapter->rx_ring[i]->reg_idx;
3375 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3376 vlnctrl &= ~IXGBE_RXDCTL_VME;
3377 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3378 }
3379 break;
3380 default:
3381 break;
3382 }
3383}
3384
3385/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003386 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003387 * @adapter: driver data
3388 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003389static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003390{
3391 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003392 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003393 int i, j;
3394
3395 switch (hw->mac.type) {
3396 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003397 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3398 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003399 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3400 break;
3401 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003402 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003403 for (i = 0; i < adapter->num_rx_queues; i++) {
3404 j = adapter->rx_ring[i]->reg_idx;
3405 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3406 vlnctrl |= IXGBE_RXDCTL_VME;
3407 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3408 }
3409 break;
3410 default:
3411 break;
3412 }
3413}
3414
Auke Kok9a799d72007-09-15 14:07:45 -07003415static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3416{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003417 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003418
Jesse Grossf62bbb52010-10-20 13:56:10 +00003419 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3420
3421 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3422 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003423}
3424
3425/**
Alexander Duyck28500622010-06-15 09:25:48 +00003426 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3427 * @netdev: network interface device structure
3428 *
3429 * Writes unicast address list to the RAR table.
3430 * Returns: -ENOMEM on failure/insufficient address space
3431 * 0 on no addresses written
3432 * X on writing X addresses to the RAR table
3433 **/
3434static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3435{
3436 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3437 struct ixgbe_hw *hw = &adapter->hw;
3438 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003439 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003440 int count = 0;
3441
3442 /* return ENOMEM indicating insufficient memory for addresses */
3443 if (netdev_uc_count(netdev) > rar_entries)
3444 return -ENOMEM;
3445
3446 if (!netdev_uc_empty(netdev) && rar_entries) {
3447 struct netdev_hw_addr *ha;
3448 /* return error if we do not support writing to RAR table */
3449 if (!hw->mac.ops.set_rar)
3450 return -ENOMEM;
3451
3452 netdev_for_each_uc_addr(ha, netdev) {
3453 if (!rar_entries)
3454 break;
3455 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3456 vfn, IXGBE_RAH_AV);
3457 count++;
3458 }
3459 }
3460 /* write the addresses in reverse order to avoid write combining */
3461 for (; rar_entries > 0 ; rar_entries--)
3462 hw->mac.ops.clear_rar(hw, rar_entries);
3463
3464 return count;
3465}
3466
3467/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003468 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003469 * @netdev: network interface device structure
3470 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003471 * The set_rx_method entry point is called whenever the unicast/multicast
3472 * address list or the network interface flags are updated. This routine is
3473 * responsible for configuring the hardware for proper unicast, multicast and
3474 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003475 **/
Greg Rose7f870472010-01-09 02:25:29 +00003476void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003477{
3478 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3479 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003480 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3481 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003482
3483 /* Check for Promiscuous and All Multicast modes */
3484
3485 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3486
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003487 /* set all bits that we expect to always be set */
3488 fctrl |= IXGBE_FCTRL_BAM;
3489 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3490 fctrl |= IXGBE_FCTRL_PMCF;
3491
Alexander Duyck28500622010-06-15 09:25:48 +00003492 /* clear the bits we are changing the status of */
3493 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3494
Auke Kok9a799d72007-09-15 14:07:45 -07003495 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003496 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003497 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003498 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003499 /* don't hardware filter vlans in promisc mode */
3500 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003501 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003502 if (netdev->flags & IFF_ALLMULTI) {
3503 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003504 vmolr |= IXGBE_VMOLR_MPE;
3505 } else {
3506 /*
3507 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003508 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003509 * that we can at least receive multicast traffic
3510 */
3511 hw->mac.ops.update_mc_addr_list(hw, netdev);
3512 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003513 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003514 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003515 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003516 /*
3517 * Write addresses to available RAR registers, if there is not
3518 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003519 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003520 */
3521 count = ixgbe_write_uc_addr_list(netdev);
3522 if (count < 0) {
3523 fctrl |= IXGBE_FCTRL_UPE;
3524 vmolr |= IXGBE_VMOLR_ROPE;
3525 }
3526 }
3527
3528 if (adapter->num_vfs) {
3529 ixgbe_restore_vf_multicasts(adapter);
3530 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3531 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3532 IXGBE_VMOLR_ROPE);
3533 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003534 }
3535
3536 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003537
3538 if (netdev->features & NETIF_F_HW_VLAN_RX)
3539 ixgbe_vlan_strip_enable(adapter);
3540 else
3541 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003542}
3543
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003544static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3545{
3546 int q_idx;
3547 struct ixgbe_q_vector *q_vector;
3548 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3549
3550 /* legacy and MSI only use one vector */
3551 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3552 q_vectors = 1;
3553
3554 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003555 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003556 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003557 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003558 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003559 if (!q_vector->rx.count || !q_vector->tx.count) {
3560 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003561 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003562 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003563 napi->poll = &ixgbe_clean_rxonly;
3564 }
3565 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003566
3567 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003568 }
3569}
3570
3571static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3572{
3573 int q_idx;
3574 struct ixgbe_q_vector *q_vector;
3575 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3576
3577 /* legacy and MSI only use one vector */
3578 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3579 q_vectors = 1;
3580
3581 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003582 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003583 napi_disable(&q_vector->napi);
3584 }
3585}
3586
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003587#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003588/*
3589 * ixgbe_configure_dcb - Configure DCB hardware
3590 * @adapter: ixgbe adapter struct
3591 *
3592 * This is called by the driver on open to configure the DCB hardware.
3593 * This is also called by the gennetlink interface when reconfiguring
3594 * the DCB state.
3595 */
3596static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3597{
3598 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003599 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003600
Alexander Duyck67ebd792010-08-19 13:34:04 +00003601 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3602 if (hw->mac.type == ixgbe_mac_82598EB)
3603 netif_set_gso_max_size(adapter->netdev, 65536);
3604 return;
3605 }
3606
3607 if (hw->mac.type == ixgbe_mac_82598EB)
3608 netif_set_gso_max_size(adapter->netdev, 32768);
3609
Alexander Duyck2f90b862008-11-20 20:52:10 -08003610
Alexander Duyck2f90b862008-11-20 20:52:10 -08003611 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003612 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003613
Alexander Duyck2f90b862008-11-20 20:52:10 -08003614 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003615
3616 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003617 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
Alexander Duyck971060b2011-07-15 02:31:30 +00003618#ifdef IXGBE_FCOE
John Fastabendc27931d2011-02-23 05:58:25 +00003619 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3620 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3621#endif
3622 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3623 DCB_TX_CONFIG);
3624 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3625 DCB_RX_CONFIG);
3626 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3627 } else {
3628 struct net_device *dev = adapter->netdev;
3629
3630 if (adapter->ixgbe_ieee_ets)
3631 dev->dcbnl_ops->ieee_setets(dev,
3632 adapter->ixgbe_ieee_ets);
3633 if (adapter->ixgbe_ieee_pfc)
3634 dev->dcbnl_ops->ieee_setpfc(dev,
3635 adapter->ixgbe_ieee_pfc);
3636 }
John Fastabend8187cd42011-02-23 05:58:08 +00003637
3638 /* Enable RSS Hash per TC */
3639 if (hw->mac.type != ixgbe_mac_82598EB) {
3640 int i;
3641 u32 reg = 0;
3642
3643 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3644 u8 msb = 0;
3645 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3646
3647 while (cnt >>= 1)
3648 msb++;
3649
3650 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3651 }
3652 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3653 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003654}
3655
3656#endif
John Fastabend80605c652011-05-02 12:34:10 +00003657
3658static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3659{
3660 int hdrm = 0;
3661 int num_tc = netdev_get_num_tc(adapter->netdev);
3662 struct ixgbe_hw *hw = &adapter->hw;
3663
3664 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3665 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3666 hdrm = 64 << adapter->fdir_pballoc;
3667
3668 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3669}
3670
Alexander Duycke4911d52011-05-11 07:18:52 +00003671static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3672{
3673 struct ixgbe_hw *hw = &adapter->hw;
3674 struct hlist_node *node, *node2;
3675 struct ixgbe_fdir_filter *filter;
3676
3677 spin_lock(&adapter->fdir_perfect_lock);
3678
3679 if (!hlist_empty(&adapter->fdir_filter_list))
3680 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3681
3682 hlist_for_each_entry_safe(filter, node, node2,
3683 &adapter->fdir_filter_list, fdir_node) {
3684 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003685 &filter->filter,
3686 filter->sw_idx,
3687 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3688 IXGBE_FDIR_DROP_QUEUE :
3689 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003690 }
3691
3692 spin_unlock(&adapter->fdir_perfect_lock);
3693}
3694
Auke Kok9a799d72007-09-15 14:07:45 -07003695static void ixgbe_configure(struct ixgbe_adapter *adapter)
3696{
3697 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003698 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003699 int i;
3700
John Fastabend80605c652011-05-02 12:34:10 +00003701 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003702#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003703 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003704#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003705
Jesse Grossf62bbb52010-10-20 13:56:10 +00003706 ixgbe_set_rx_mode(netdev);
3707 ixgbe_restore_vlan(adapter);
3708
Yi Zoueacd73f2009-05-13 13:11:06 +00003709#ifdef IXGBE_FCOE
3710 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3711 ixgbe_configure_fcoe(adapter);
3712
3713#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003714 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3715 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003716 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003717 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003718 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003719 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3720 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3721 adapter->fdir_pballoc);
3722 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003723 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003724 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003725
Auke Kok9a799d72007-09-15 14:07:45 -07003726 ixgbe_configure_tx(adapter);
3727 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003728}
3729
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003730static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3731{
3732 switch (hw->phy.type) {
3733 case ixgbe_phy_sfp_avago:
3734 case ixgbe_phy_sfp_ftl:
3735 case ixgbe_phy_sfp_intel:
3736 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003737 case ixgbe_phy_sfp_passive_tyco:
3738 case ixgbe_phy_sfp_passive_unknown:
3739 case ixgbe_phy_sfp_active_unknown:
3740 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003741 return true;
3742 default:
3743 return false;
3744 }
3745}
3746
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003747/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003748 * ixgbe_sfp_link_config - set up SFP+ link
3749 * @adapter: pointer to private adapter struct
3750 **/
3751static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3752{
Alexander Duyck70864002011-04-27 09:13:56 +00003753 /*
3754 * We are assuming the worst case scenerio here, and that
3755 * is that an SFP was inserted/removed after the reset
3756 * but before SFP detection was enabled. As such the best
3757 * solution is to just start searching as soon as we start
3758 */
3759 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3760 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003761
Alexander Duyck70864002011-04-27 09:13:56 +00003762 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003763}
3764
3765/**
3766 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003767 * @hw: pointer to private hardware struct
3768 *
3769 * Returns 0 on success, negative on failure
3770 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003771static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003772{
3773 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003774 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003775 u32 ret = IXGBE_ERR_LINK_SETUP;
3776
3777 if (hw->mac.ops.check_link)
3778 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3779
3780 if (ret)
3781 goto link_cfg_out;
3782
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003783 autoneg = hw->phy.autoneg_advertised;
3784 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003785 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3786 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003787 if (ret)
3788 goto link_cfg_out;
3789
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003790 if (hw->mac.ops.setup_link)
3791 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003792link_cfg_out:
3793 return ret;
3794}
3795
Alexander Duycka34bcff2010-08-19 13:39:20 +00003796static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003797{
Auke Kok9a799d72007-09-15 14:07:45 -07003798 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003799 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003800
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003801 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003802 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3803 IXGBE_GPIE_OCD;
3804 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003805 /*
3806 * use EIAM to auto-mask when MSI-X interrupt is asserted
3807 * this saves a register write for every interrupt
3808 */
3809 switch (hw->mac.type) {
3810 case ixgbe_mac_82598EB:
3811 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3812 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003813 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003814 case ixgbe_mac_X540:
3815 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003816 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3817 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3818 break;
3819 }
3820 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003821 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3822 * specifically only auto mask tx and rx interrupts */
3823 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003824 }
3825
Alexander Duycka34bcff2010-08-19 13:39:20 +00003826 /* XXX: to interrupt immediately for EICS writes, enable this */
3827 /* gpie |= IXGBE_GPIE_EIMEN; */
3828
3829 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3830 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3831 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003832 }
3833
Alexander Duycka34bcff2010-08-19 13:39:20 +00003834 /* Enable fan failure interrupt */
3835 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003836 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003837
Don Skidmore2698b202011-04-13 07:01:52 +00003838 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003839 gpie |= IXGBE_SDP1_GPIEN;
3840 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003841 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003842
3843 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3844}
3845
3846static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3847{
3848 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003849 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003850 u32 ctrl_ext;
3851
3852 ixgbe_get_hw_control(adapter);
3853 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003854
Auke Kok9a799d72007-09-15 14:07:45 -07003855 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3856 ixgbe_configure_msix(adapter);
3857 else
3858 ixgbe_configure_msi_and_legacy(adapter);
3859
Don Skidmorec6ecf392010-12-03 03:31:51 +00003860 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3861 if (hw->mac.ops.enable_tx_laser &&
3862 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003863 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003864 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003865 hw->mac.ops.enable_tx_laser(hw);
3866
Auke Kok9a799d72007-09-15 14:07:45 -07003867 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003868 ixgbe_napi_enable_all(adapter);
3869
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003870 if (ixgbe_is_sfp(hw)) {
3871 ixgbe_sfp_link_config(adapter);
3872 } else {
3873 err = ixgbe_non_sfp_link_config(hw);
3874 if (err)
3875 e_err(probe, "link_config FAILED %d\n", err);
3876 }
3877
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003878 /* clear any pending interrupts, may auto mask */
3879 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003880 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003881
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003882 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003883 * If this adapter has a fan, check to see if we had a failure
3884 * before we enabled the interrupt.
3885 */
3886 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3887 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3888 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003889 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003890 }
3891
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003892 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003893 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003894
Auke Kok9a799d72007-09-15 14:07:45 -07003895 /* bring the link up in the watchdog, this could race with our first
3896 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003897 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3898 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003899 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003900
3901 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3902 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3903 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3904 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3905
Auke Kok9a799d72007-09-15 14:07:45 -07003906 return 0;
3907}
3908
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003909void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3910{
3911 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003912 /* put off any impending NetWatchDogTimeout */
3913 adapter->netdev->trans_start = jiffies;
3914
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003915 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003916 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003917 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003918 /*
3919 * If SR-IOV enabled then wait a bit before bringing the adapter
3920 * back up to give the VFs time to respond to the reset. The
3921 * two second wait is based upon the watchdog timer cycle in
3922 * the VF driver.
3923 */
3924 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3925 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003926 ixgbe_up(adapter);
3927 clear_bit(__IXGBE_RESETTING, &adapter->state);
3928}
3929
Auke Kok9a799d72007-09-15 14:07:45 -07003930int ixgbe_up(struct ixgbe_adapter *adapter)
3931{
3932 /* hardware has been reset, we need to reload some things */
3933 ixgbe_configure(adapter);
3934
3935 return ixgbe_up_complete(adapter);
3936}
3937
3938void ixgbe_reset(struct ixgbe_adapter *adapter)
3939{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003940 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003941 int err;
3942
Alexander Duyck70864002011-04-27 09:13:56 +00003943 /* lock SFP init bit to prevent race conditions with the watchdog */
3944 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3945 usleep_range(1000, 2000);
3946
3947 /* clear all SFP and link config related flags while holding SFP_INIT */
3948 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3949 IXGBE_FLAG2_SFP_NEEDS_RESET);
3950 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3951
Don Skidmore8ca783a2009-05-26 20:40:47 -07003952 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003953 switch (err) {
3954 case 0:
3955 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003956 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003957 break;
3958 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003959 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003960 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003961 case IXGBE_ERR_EEPROM_VERSION:
3962 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003963 e_dev_warn("This device is a pre-production adapter/LOM. "
3964 "Please be aware there may be issuesassociated with "
3965 "your hardware. If you are experiencing problems "
3966 "please contact your Intel or hardware "
3967 "representative who provided you with this "
3968 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003969 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003970 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003971 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003972 }
Auke Kok9a799d72007-09-15 14:07:45 -07003973
Alexander Duyck70864002011-04-27 09:13:56 +00003974 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3975
Auke Kok9a799d72007-09-15 14:07:45 -07003976 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003977 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3978 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003979}
3980
Auke Kok9a799d72007-09-15 14:07:45 -07003981/**
3982 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003983 * @rx_ring: ring to free buffers from
3984 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003985static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003986{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003987 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003988 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003989 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003990
Alexander Duyck84418e32010-08-19 13:40:54 +00003991 /* ring already cleared, nothing to do */
3992 if (!rx_ring->rx_buffer_info)
3993 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003994
Alexander Duyck84418e32010-08-19 13:40:54 +00003995 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003996 for (i = 0; i < rx_ring->count; i++) {
3997 struct ixgbe_rx_buffer *rx_buffer_info;
3998
3999 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4000 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004001 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004002 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004003 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004004 rx_buffer_info->dma = 0;
4005 }
4006 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004007 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004008 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004009 do {
4010 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004011 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004012 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004013 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004014 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004015 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004016 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004017 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004018 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004019 skb = skb->prev;
4020 dev_kfree_skb(this);
4021 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004022 }
4023 if (!rx_buffer_info->page)
4024 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004025 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004026 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004027 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004028 rx_buffer_info->page_dma = 0;
4029 }
Auke Kok9a799d72007-09-15 14:07:45 -07004030 put_page(rx_buffer_info->page);
4031 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004032 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004033 }
4034
4035 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4036 memset(rx_ring->rx_buffer_info, 0, size);
4037
4038 /* Zero out the descriptor ring */
4039 memset(rx_ring->desc, 0, rx_ring->size);
4040
4041 rx_ring->next_to_clean = 0;
4042 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004043}
4044
4045/**
4046 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004047 * @tx_ring: ring to be cleaned
4048 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004049static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004050{
4051 struct ixgbe_tx_buffer *tx_buffer_info;
4052 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004053 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004054
Alexander Duyck84418e32010-08-19 13:40:54 +00004055 /* ring already cleared, nothing to do */
4056 if (!tx_ring->tx_buffer_info)
4057 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004058
Alexander Duyck84418e32010-08-19 13:40:54 +00004059 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004060 for (i = 0; i < tx_ring->count; i++) {
4061 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004062 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004063 }
4064
4065 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4066 memset(tx_ring->tx_buffer_info, 0, size);
4067
4068 /* Zero out the descriptor ring */
4069 memset(tx_ring->desc, 0, tx_ring->size);
4070
4071 tx_ring->next_to_use = 0;
4072 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004073}
4074
4075/**
Auke Kok9a799d72007-09-15 14:07:45 -07004076 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4077 * @adapter: board private structure
4078 **/
4079static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4080{
4081 int i;
4082
4083 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004084 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004085}
4086
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004087/**
4088 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4089 * @adapter: board private structure
4090 **/
4091static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4092{
4093 int i;
4094
4095 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004096 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004097}
4098
Alexander Duycke4911d52011-05-11 07:18:52 +00004099static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4100{
4101 struct hlist_node *node, *node2;
4102 struct ixgbe_fdir_filter *filter;
4103
4104 spin_lock(&adapter->fdir_perfect_lock);
4105
4106 hlist_for_each_entry_safe(filter, node, node2,
4107 &adapter->fdir_filter_list, fdir_node) {
4108 hlist_del(&filter->fdir_node);
4109 kfree(filter);
4110 }
4111 adapter->fdir_filter_count = 0;
4112
4113 spin_unlock(&adapter->fdir_perfect_lock);
4114}
4115
Auke Kok9a799d72007-09-15 14:07:45 -07004116void ixgbe_down(struct ixgbe_adapter *adapter)
4117{
4118 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004119 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004120 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004121 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004122 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004123
4124 /* signal that we are down to the interrupt handler */
4125 set_bit(__IXGBE_DOWN, &adapter->state);
4126
4127 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004128 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4129 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004130
Yi Zou2d39d572011-01-06 14:29:56 +00004131 /* disable all enabled rx queues */
4132 for (i = 0; i < adapter->num_rx_queues; i++)
4133 /* this call also flushes the previous write */
4134 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4135
Don Skidmore032b4322011-03-18 09:32:53 +00004136 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004137
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004138 netif_tx_stop_all_queues(netdev);
4139
Alexander Duyck70864002011-04-27 09:13:56 +00004140 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004141 netif_carrier_off(netdev);
4142 netif_tx_disable(netdev);
4143
4144 ixgbe_irq_disable(adapter);
4145
4146 ixgbe_napi_disable_all(adapter);
4147
Alexander Duyckd034acf2011-04-27 09:25:34 +00004148 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4149 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004150 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4151
4152 del_timer_sync(&adapter->service_timer);
4153
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004154 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004155 if (adapter->num_vfs) {
4156 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004157 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004158
Auke Kok9a799d72007-09-15 14:07:45 -07004159 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004160 ixgbe_disable_tx_rx(adapter);
4161
4162 /* Mark all the VFs as inactive */
4163 for (i = 0 ; i < adapter->num_vfs; i++)
4164 adapter->vfinfo[i].clear_to_send = 0;
4165 }
4166
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004167 /* Cleanup the affinity_hint CPU mask memory and callback */
4168 for (i = 0; i < num_q_vectors; i++) {
4169 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4170 /* clear the affinity_mask in the IRQ descriptor */
4171 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4172 /* release the CPU mask memory */
4173 free_cpumask_var(q_vector->affinity_mask);
4174 }
4175
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004176 /* disable transmits in the hardware now that interrupts are off */
4177 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004178 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004179 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004180 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004181
4182 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004183 switch (hw->mac.type) {
4184 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004185 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004186 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004187 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4188 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004189 break;
4190 default:
4191 break;
4192 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004193
Paul Larson6f4a0e42008-06-24 17:00:56 -07004194 if (!pci_channel_offline(adapter->pdev))
4195 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004196
4197 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4198 if (hw->mac.ops.disable_tx_laser &&
4199 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004200 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004201 (hw->mac.type == ixgbe_mac_82599EB))))
4202 hw->mac.ops.disable_tx_laser(hw);
4203
Auke Kok9a799d72007-09-15 14:07:45 -07004204 ixgbe_clean_all_tx_rings(adapter);
4205 ixgbe_clean_all_rx_rings(adapter);
4206
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004207#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004208 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004209 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004210#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004211}
4212
Auke Kok9a799d72007-09-15 14:07:45 -07004213/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004214 * ixgbe_poll - NAPI Rx polling callback
4215 * @napi: structure for representing this polling device
4216 * @budget: how many packets driver is allowed to clean
4217 *
4218 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004219 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004220static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004221{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004222 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004223 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004224 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004225 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004226
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004227#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004228 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4229 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004230#endif
4231
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004232 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4233 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004234
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004235 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004236 work_done = budget;
4237
David S. Miller53e52c72008-01-07 21:06:12 -08004238 /* If budget not fully consumed, exit the polling mode */
4239 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004240 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004241 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004242 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004243 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004244 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004245 }
Auke Kok9a799d72007-09-15 14:07:45 -07004246 return work_done;
4247}
4248
4249/**
4250 * ixgbe_tx_timeout - Respond to a Tx Hang
4251 * @netdev: network interface device structure
4252 **/
4253static void ixgbe_tx_timeout(struct net_device *netdev)
4254{
4255 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4256
4257 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004258 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004259}
4260
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004261/**
4262 * ixgbe_set_rss_queues: Allocate queues for RSS
4263 * @adapter: board private structure to initialize
4264 *
4265 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4266 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4267 *
4268 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004269static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4270{
4271 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004272 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004273
4274 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004275 f->mask = 0xF;
4276 adapter->num_rx_queues = f->indices;
4277 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004278 ret = true;
4279 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004280 ret = false;
4281 }
4282
4283 return ret;
4284}
4285
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004286/**
4287 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4288 * @adapter: board private structure to initialize
4289 *
4290 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4291 * to the original CPU that initiated the Tx session. This runs in addition
4292 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4293 * Rx load across CPUs using RSS.
4294 *
4295 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004296static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004297{
4298 bool ret = false;
4299 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4300
4301 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4302 f_fdir->mask = 0;
4303
4304 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004305 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4306 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004307 adapter->num_tx_queues = f_fdir->indices;
4308 adapter->num_rx_queues = f_fdir->indices;
4309 ret = true;
4310 } else {
4311 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004312 }
4313 return ret;
4314}
4315
Yi Zou0331a832009-05-17 12:33:52 +00004316#ifdef IXGBE_FCOE
4317/**
4318 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4319 * @adapter: board private structure to initialize
4320 *
4321 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4322 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4323 * rx queues out of the max number of rx queues, instead, it is used as the
4324 * index of the first rx queue used by FCoE.
4325 *
4326 **/
4327static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4328{
Yi Zou0331a832009-05-17 12:33:52 +00004329 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4330
John Fastabende5b64632011-03-08 03:44:52 +00004331 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4332 return false;
4333
John Fastabende901acd2011-04-26 07:26:08 +00004334 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004335
John Fastabende901acd2011-04-26 07:26:08 +00004336 adapter->num_rx_queues = 1;
4337 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004338
John Fastabende901acd2011-04-26 07:26:08 +00004339 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4340 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004341 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004342 ixgbe_set_fdir_queues(adapter);
4343 else
4344 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004345 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004346
John Fastabende901acd2011-04-26 07:26:08 +00004347 /* adding FCoE rx rings to the end */
4348 f->mask = adapter->num_rx_queues;
4349 adapter->num_rx_queues += f->indices;
4350 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004351
John Fastabende5b64632011-03-08 03:44:52 +00004352 return true;
4353}
4354#endif /* IXGBE_FCOE */
4355
John Fastabende901acd2011-04-26 07:26:08 +00004356/* Artificial max queue cap per traffic class in DCB mode */
4357#define DCB_QUEUE_CAP 8
4358
John Fastabende5b64632011-03-08 03:44:52 +00004359#ifdef CONFIG_IXGBE_DCB
4360static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4361{
John Fastabende901acd2011-04-26 07:26:08 +00004362 int per_tc_q, q, i, offset = 0;
4363 struct net_device *dev = adapter->netdev;
4364 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004365
John Fastabende901acd2011-04-26 07:26:08 +00004366 if (!tcs)
4367 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004368
John Fastabende901acd2011-04-26 07:26:08 +00004369 /* Map queue offset and counts onto allocated tx queues */
4370 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4371 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004372
John Fastabend8b1c0b22011-05-03 02:26:48 +00004373 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004374 netdev_set_prio_tc_map(dev, i, i);
4375 netdev_set_tc_queue(dev, i, q, offset);
4376 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004377 }
4378
John Fastabende901acd2011-04-26 07:26:08 +00004379 adapter->num_tx_queues = q * tcs;
4380 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004381
4382#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004383 /* FCoE enabled queues require special configuration indexed
4384 * by feature specific indices and mask. Here we map FCoE
4385 * indices onto the DCB queue pairs allowing FCoE to own
4386 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004387 */
John Fastabende901acd2011-04-26 07:26:08 +00004388 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4389 int tc;
4390 struct ixgbe_ring_feature *f =
4391 &adapter->ring_feature[RING_F_FCOE];
4392
4393 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4394 f->indices = dev->tc_to_txq[tc].count;
4395 f->mask = dev->tc_to_txq[tc].offset;
4396 }
John Fastabende5b64632011-03-08 03:44:52 +00004397#endif
4398
John Fastabende901acd2011-04-26 07:26:08 +00004399 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004400}
John Fastabende5b64632011-03-08 03:44:52 +00004401#endif
Yi Zou0331a832009-05-17 12:33:52 +00004402
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004403/**
4404 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4405 * @adapter: board private structure to initialize
4406 *
4407 * IOV doesn't actually use anything, so just NAK the
4408 * request for now and let the other queue routines
4409 * figure out what to do.
4410 */
4411static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4412{
4413 return false;
4414}
4415
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004416/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004417 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004418 * @adapter: board private structure to initialize
4419 *
4420 * This is the top level queue allocation routine. The order here is very
4421 * important, starting with the "most" number of features turned on at once,
4422 * and ending with the smallest set of features. This way large combinations
4423 * can be allocated if they're turned on, and smaller combinations are the
4424 * fallthrough conditions.
4425 *
4426 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004427static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004428{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004429 /* Start with base case */
4430 adapter->num_rx_queues = 1;
4431 adapter->num_tx_queues = 1;
4432 adapter->num_rx_pools = adapter->num_rx_queues;
4433 adapter->num_rx_queues_per_pool = 1;
4434
4435 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004436 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004437
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004438#ifdef CONFIG_IXGBE_DCB
4439 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004440 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004441
4442#endif
John Fastabende5b64632011-03-08 03:44:52 +00004443#ifdef IXGBE_FCOE
4444 if (ixgbe_set_fcoe_queues(adapter))
4445 goto done;
4446
4447#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004448 if (ixgbe_set_fdir_queues(adapter))
4449 goto done;
4450
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004451 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004452 goto done;
4453
4454 /* fallback to base case */
4455 adapter->num_rx_queues = 1;
4456 adapter->num_tx_queues = 1;
4457
4458done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004459 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004460 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004461 return netif_set_real_num_rx_queues(adapter->netdev,
4462 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004463}
4464
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004465static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004466 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004467{
4468 int err, vector_threshold;
4469
4470 /* We'll want at least 3 (vector_threshold):
4471 * 1) TxQ[0] Cleanup
4472 * 2) RxQ[0] Cleanup
4473 * 3) Other (Link Status Change, etc.)
4474 * 4) TCP Timer (optional)
4475 */
4476 vector_threshold = MIN_MSIX_COUNT;
4477
4478 /* The more we get, the more we will assign to Tx/Rx Cleanup
4479 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4480 * Right now, we simply care about how many we'll get; we'll
4481 * set them up later while requesting irq's.
4482 */
4483 while (vectors >= vector_threshold) {
4484 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004485 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004486 if (!err) /* Success in acquiring all requested vectors. */
4487 break;
4488 else if (err < 0)
4489 vectors = 0; /* Nasty failure, quit now */
4490 else /* err == number of vectors we should try again with */
4491 vectors = err;
4492 }
4493
4494 if (vectors < vector_threshold) {
4495 /* Can't allocate enough MSI-X interrupts? Oh well.
4496 * This just means we'll go with either a single MSI
4497 * vector or fall back to legacy interrupts.
4498 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004499 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4500 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004501 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4502 kfree(adapter->msix_entries);
4503 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004504 } else {
4505 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004506 /*
4507 * Adjust for only the vectors we'll use, which is minimum
4508 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4509 * vectors we were allocated.
4510 */
4511 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004512 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004513 }
4514}
4515
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004516/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004517 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004518 * @adapter: board private structure to initialize
4519 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004520 * Cache the descriptor ring offsets for RSS to the assigned rings.
4521 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004522 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004523static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004524{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004525 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004526
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004527 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4528 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004529
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004530 for (i = 0; i < adapter->num_rx_queues; i++)
4531 adapter->rx_ring[i]->reg_idx = i;
4532 for (i = 0; i < adapter->num_tx_queues; i++)
4533 adapter->tx_ring[i]->reg_idx = i;
4534
4535 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004536}
4537
4538#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004539
4540/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004541static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4542 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004543{
4544 struct net_device *dev = adapter->netdev;
4545 struct ixgbe_hw *hw = &adapter->hw;
4546 u8 num_tcs = netdev_get_num_tc(dev);
4547
4548 *tx = 0;
4549 *rx = 0;
4550
4551 switch (hw->mac.type) {
4552 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004553 *tx = tc << 2;
4554 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004555 break;
4556 case ixgbe_mac_82599EB:
4557 case ixgbe_mac_X540:
4558 if (num_tcs == 8) {
4559 if (tc < 3) {
4560 *tx = tc << 5;
4561 *rx = tc << 4;
4562 } else if (tc < 5) {
4563 *tx = ((tc + 2) << 4);
4564 *rx = tc << 4;
4565 } else if (tc < num_tcs) {
4566 *tx = ((tc + 8) << 3);
4567 *rx = tc << 4;
4568 }
4569 } else if (num_tcs == 4) {
4570 *rx = tc << 5;
4571 switch (tc) {
4572 case 0:
4573 *tx = 0;
4574 break;
4575 case 1:
4576 *tx = 64;
4577 break;
4578 case 2:
4579 *tx = 96;
4580 break;
4581 case 3:
4582 *tx = 112;
4583 break;
4584 default:
4585 break;
4586 }
4587 }
4588 break;
4589 default:
4590 break;
4591 }
4592}
4593
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004594/**
4595 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4596 * @adapter: board private structure to initialize
4597 *
4598 * Cache the descriptor ring offsets for DCB to the assigned rings.
4599 *
4600 **/
4601static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4602{
John Fastabende5b64632011-03-08 03:44:52 +00004603 struct net_device *dev = adapter->netdev;
4604 int i, j, k;
4605 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004606
John Fastabend8b1c0b22011-05-03 02:26:48 +00004607 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004608 return false;
4609
John Fastabende5b64632011-03-08 03:44:52 +00004610 for (i = 0, k = 0; i < num_tcs; i++) {
4611 unsigned int tx_s, rx_s;
4612 u16 count = dev->tc_to_txq[i].count;
4613
4614 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4615 for (j = 0; j < count; j++, k++) {
4616 adapter->tx_ring[k]->reg_idx = tx_s + j;
4617 adapter->rx_ring[k]->reg_idx = rx_s + j;
4618 adapter->tx_ring[k]->dcb_tc = i;
4619 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004620 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004621 }
John Fastabende5b64632011-03-08 03:44:52 +00004622
4623 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004624}
4625#endif
4626
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004627/**
4628 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4629 * @adapter: board private structure to initialize
4630 *
4631 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4632 *
4633 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004634static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004635{
4636 int i;
4637 bool ret = false;
4638
Alexander Duyck03ecf912011-05-20 07:36:17 +00004639 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4640 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004641 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004642 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004643 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004644 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004645 ret = true;
4646 }
4647
4648 return ret;
4649}
4650
Yi Zou0331a832009-05-17 12:33:52 +00004651#ifdef IXGBE_FCOE
4652/**
4653 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4654 * @adapter: board private structure to initialize
4655 *
4656 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4657 *
4658 */
4659static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4660{
Yi Zou0331a832009-05-17 12:33:52 +00004661 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004662 int i;
4663 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004664
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004665 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4666 return false;
4667
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004668 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004669 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004670 ixgbe_cache_ring_fdir(adapter);
4671 else
4672 ixgbe_cache_ring_rss(adapter);
4673
4674 fcoe_rx_i = f->mask;
4675 fcoe_tx_i = f->mask;
4676 }
4677 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4678 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4679 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4680 }
4681 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004682}
4683
4684#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004685/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004686 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4687 * @adapter: board private structure to initialize
4688 *
4689 * SR-IOV doesn't use any descriptor rings but changes the default if
4690 * no other mapping is used.
4691 *
4692 */
4693static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4694{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004695 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4696 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004697 if (adapter->num_vfs)
4698 return true;
4699 else
4700 return false;
4701}
4702
4703/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004704 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4705 * @adapter: board private structure to initialize
4706 *
4707 * Once we know the feature-set enabled for the device, we'll cache
4708 * the register offset the descriptor ring is assigned to.
4709 *
4710 * Note, the order the various feature calls is important. It must start with
4711 * the "most" features enabled at the same time, then trickle down to the
4712 * least amount of features turned on at once.
4713 **/
4714static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4715{
4716 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004717 adapter->rx_ring[0]->reg_idx = 0;
4718 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004719
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004720 if (ixgbe_cache_ring_sriov(adapter))
4721 return;
4722
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004723#ifdef CONFIG_IXGBE_DCB
4724 if (ixgbe_cache_ring_dcb(adapter))
4725 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004726#endif
John Fastabende5b64632011-03-08 03:44:52 +00004727
4728#ifdef IXGBE_FCOE
4729 if (ixgbe_cache_ring_fcoe(adapter))
4730 return;
4731#endif /* IXGBE_FCOE */
4732
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004733 if (ixgbe_cache_ring_fdir(adapter))
4734 return;
4735
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004736 if (ixgbe_cache_ring_rss(adapter))
4737 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004738}
4739
Auke Kok9a799d72007-09-15 14:07:45 -07004740/**
4741 * ixgbe_alloc_queues - Allocate memory for all rings
4742 * @adapter: board private structure to initialize
4743 *
4744 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004745 * number of queues at compile-time. The polling_netdev array is
4746 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004747 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004748static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004749{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004750 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004751
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004752 if (nid < 0 || !node_online(nid))
4753 nid = first_online_node;
4754
4755 for (; tx < adapter->num_tx_queues; tx++) {
4756 struct ixgbe_ring *ring;
4757
4758 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004759 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004760 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004761 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004762 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004763 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004764 ring->queue_index = tx;
4765 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004766 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004767 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004768
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004769 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004770 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004771
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004772 for (; rx < adapter->num_rx_queues; rx++) {
4773 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004774
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004775 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004776 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004777 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004778 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004779 goto err_allocation;
4780 ring->count = adapter->rx_ring_count;
4781 ring->queue_index = rx;
4782 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004783 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004784 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004785
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004786 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004787 }
4788
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004789 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004790
4791 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004792
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004793err_allocation:
4794 while (tx)
4795 kfree(adapter->tx_ring[--tx]);
4796
4797 while (rx)
4798 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004799 return -ENOMEM;
4800}
4801
4802/**
4803 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4804 * @adapter: board private structure to initialize
4805 *
4806 * Attempt to configure the interrupts using the best available
4807 * capabilities of the hardware and the kernel.
4808 **/
Al Virofeea6a52008-11-27 15:34:07 -08004809static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004810{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004811 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004812 int err = 0;
4813 int vector, v_budget;
4814
4815 /*
4816 * It's easy to be greedy for MSI-X vectors, but it really
4817 * doesn't do us much good if we have a lot more vectors
4818 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004819 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004820 */
4821 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004822 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004823
4824 /*
4825 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004826 * hw.mac->max_msix_vectors vectors. With features
4827 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4828 * descriptor queues supported by our device. Thus, we cap it off in
4829 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004830 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004831 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004832
4833 /* A failure in MSI-X entry allocation isn't fatal, but it does
4834 * mean we disable MSI-X capabilities of the adapter. */
4835 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004836 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004837 if (adapter->msix_entries) {
4838 for (vector = 0; vector < v_budget; vector++)
4839 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004840
Alexander Duyck7a921c92009-05-06 10:43:28 +00004841 ixgbe_acquire_msix_vectors(adapter, v_budget);
4842
4843 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4844 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004845 }
David S. Miller26d27842010-05-03 15:18:22 -07004846
Alexander Duyck7a921c92009-05-06 10:43:28 +00004847 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4848 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004849 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004850 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004851 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004852 "queues are disabled. Disabling Flow Director\n");
4853 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004854 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004855 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004856 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4857 ixgbe_disable_sriov(adapter);
4858
Ben Hutchings847f53f2010-09-27 08:28:56 +00004859 err = ixgbe_set_num_queues(adapter);
4860 if (err)
4861 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004862
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004863 err = pci_enable_msi(adapter->pdev);
4864 if (!err) {
4865 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4866 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004867 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4868 "Unable to allocate MSI interrupt, "
4869 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004870 /* reset err */
4871 err = 0;
4872 }
4873
4874out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004875 return err;
4876}
4877
Alexander Duyck7a921c92009-05-06 10:43:28 +00004878/**
4879 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4880 * @adapter: board private structure to initialize
4881 *
4882 * We allocate one q_vector per queue interrupt. If allocation fails we
4883 * return -ENOMEM.
4884 **/
4885static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4886{
4887 int q_idx, num_q_vectors;
4888 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004889 int (*poll)(struct napi_struct *, int);
4890
4891 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4892 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004893 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004894 } else {
4895 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004896 poll = &ixgbe_poll;
4897 }
4898
4899 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004900 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004901 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004902 if (!q_vector)
4903 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004904 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004905 if (!q_vector)
4906 goto err_out;
4907 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004908 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004909 q_vector->eitr = adapter->tx_eitr_param;
4910 else
4911 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004912 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004913 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004914 adapter->q_vector[q_idx] = q_vector;
4915 }
4916
4917 return 0;
4918
4919err_out:
4920 while (q_idx) {
4921 q_idx--;
4922 q_vector = adapter->q_vector[q_idx];
4923 netif_napi_del(&q_vector->napi);
4924 kfree(q_vector);
4925 adapter->q_vector[q_idx] = NULL;
4926 }
4927 return -ENOMEM;
4928}
4929
4930/**
4931 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4932 * @adapter: board private structure to initialize
4933 *
4934 * This function frees the memory allocated to the q_vectors. In addition if
4935 * NAPI is enabled it will delete any references to the NAPI struct prior
4936 * to freeing the q_vector.
4937 **/
4938static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4939{
4940 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004941
Alexander Duyck91281fd2009-06-04 16:00:27 +00004942 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004943 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004944 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004945 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004946
4947 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4948 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004949 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004950 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004951 kfree(q_vector);
4952 }
4953}
4954
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004955static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004956{
4957 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4958 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4959 pci_disable_msix(adapter->pdev);
4960 kfree(adapter->msix_entries);
4961 adapter->msix_entries = NULL;
4962 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4963 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4964 pci_disable_msi(adapter->pdev);
4965 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004966}
4967
4968/**
4969 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4970 * @adapter: board private structure to initialize
4971 *
4972 * We determine which interrupt scheme to use based on...
4973 * - Kernel support (MSI, MSI-X)
4974 * - which can be user-defined (via MODULE_PARAM)
4975 * - Hardware queue count (num_*_queues)
4976 * - defined by miscellaneous hardware support/features (RSS, etc.)
4977 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004978int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004979{
4980 int err;
4981
4982 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004983 err = ixgbe_set_num_queues(adapter);
4984 if (err)
4985 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004986
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004987 err = ixgbe_set_interrupt_capability(adapter);
4988 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004989 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004990 goto err_set_interrupt;
4991 }
4992
Alexander Duyck7a921c92009-05-06 10:43:28 +00004993 err = ixgbe_alloc_q_vectors(adapter);
4994 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004995 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004996 goto err_alloc_q_vectors;
4997 }
4998
4999 err = ixgbe_alloc_queues(adapter);
5000 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005001 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005002 goto err_alloc_queues;
5003 }
5004
Emil Tantilov849c4542010-06-03 16:53:41 +00005005 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005006 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5007 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005008
5009 set_bit(__IXGBE_DOWN, &adapter->state);
5010
5011 return 0;
5012
Alexander Duyck7a921c92009-05-06 10:43:28 +00005013err_alloc_queues:
5014 ixgbe_free_q_vectors(adapter);
5015err_alloc_q_vectors:
5016 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005017err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005018 return err;
5019}
5020
5021/**
5022 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5023 * @adapter: board private structure to clear interrupt scheme on
5024 *
5025 * We go through and clear interrupt specific resources and reset the structure
5026 * to pre-load conditions
5027 **/
5028void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5029{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005030 int i;
5031
5032 for (i = 0; i < adapter->num_tx_queues; i++) {
5033 kfree(adapter->tx_ring[i]);
5034 adapter->tx_ring[i] = NULL;
5035 }
5036 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005037 struct ixgbe_ring *ring = adapter->rx_ring[i];
5038
5039 /* ixgbe_get_stats64() might access this ring, we must wait
5040 * a grace period before freeing it.
5041 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005042 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005043 adapter->rx_ring[i] = NULL;
5044 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005045
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005046 adapter->num_tx_queues = 0;
5047 adapter->num_rx_queues = 0;
5048
Alexander Duyck7a921c92009-05-06 10:43:28 +00005049 ixgbe_free_q_vectors(adapter);
5050 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005051}
5052
5053/**
5054 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5055 * @adapter: board private structure to initialize
5056 *
5057 * ixgbe_sw_init initializes the Adapter private data structure.
5058 * Fields are initialized based on PCI device information and
5059 * OS network device settings (MTU size).
5060 **/
5061static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5062{
5063 struct ixgbe_hw *hw = &adapter->hw;
5064 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005065 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005066 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005067#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005068 int j;
5069 struct tc_configuration *tc;
5070#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005071 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005072
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005073 /* PCI config space info */
5074
5075 hw->vendor_id = pdev->vendor;
5076 hw->device_id = pdev->device;
5077 hw->revision_id = pdev->revision;
5078 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5079 hw->subsystem_device_id = pdev->subsystem_device;
5080
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005081 /* Set capability flags */
5082 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5083 adapter->ring_feature[RING_F_RSS].indices = rss;
5084 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005085 switch (hw->mac.type) {
5086 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005087 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5088 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005089 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005090 break;
5091 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005092 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005093 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005094 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5095 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005096 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5097 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005098 /* Flow Director hash filters enabled */
5099 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5100 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005101 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005102 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005103 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005104#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005105 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5106 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5107 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005108#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005109 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005110 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005111#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005112#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005113 break;
5114 default:
5115 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005116 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005117
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005118 /* n-tuple support exists, always init our spinlock */
5119 spin_lock_init(&adapter->fdir_perfect_lock);
5120
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005121#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005122 /* Configure DCB traffic classes */
5123 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5124 tc = &adapter->dcb_cfg.tc_config[j];
5125 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5126 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5127 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5128 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5129 tc->dcb_pfc = pfc_disabled;
5130 }
5131 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5132 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005133 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005134 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005135 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005136 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005137 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005138
5139#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005140
5141 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005142 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005143 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005144#ifdef CONFIG_DCB
5145 adapter->last_lfc_mode = hw->fc.current_mode;
5146#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005147 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5148 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005149 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5150 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005151 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005152
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005153 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005154 adapter->rx_itr_setting = 1;
5155 adapter->rx_eitr_param = 20000;
5156 adapter->tx_itr_setting = 1;
5157 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005158
5159 /* set defaults for eitr in MegaBytes */
5160 adapter->eitr_low = 10;
5161 adapter->eitr_high = 20;
5162
5163 /* set default ring sizes */
5164 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5165 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5166
Alexander Duyckbd198052011-06-11 01:45:08 +00005167 /* set default work limits */
5168 adapter->tx_work_limit = adapter->tx_ring_count;
5169
Auke Kok9a799d72007-09-15 14:07:45 -07005170 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005171 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005172 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005173 return -EIO;
5174 }
5175
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005176 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005177 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5178
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005179 /* get assigned NUMA node */
5180 adapter->node = dev_to_node(&pdev->dev);
5181
Auke Kok9a799d72007-09-15 14:07:45 -07005182 set_bit(__IXGBE_DOWN, &adapter->state);
5183
5184 return 0;
5185}
5186
5187/**
5188 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005189 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005190 *
5191 * Return 0 on success, negative on failure
5192 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005193int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005194{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005195 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005196 int size;
5197
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005198 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005199 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005200 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005201 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005202 if (!tx_ring->tx_buffer_info)
5203 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005204
5205 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005206 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005207 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005208
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005209 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005210 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005211 if (!tx_ring->desc)
5212 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005213
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005214 tx_ring->next_to_use = 0;
5215 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005216 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005217
5218err:
5219 vfree(tx_ring->tx_buffer_info);
5220 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005221 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005222 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005223}
5224
5225/**
Alexander Duyck69888672008-09-11 20:05:39 -07005226 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5227 * @adapter: board private structure
5228 *
5229 * If this function returns with an error, then it's possible one or
5230 * more of the rings is populated (while the rest are not). It is the
5231 * callers duty to clean those orphaned rings.
5232 *
5233 * Return 0 on success, negative on failure
5234 **/
5235static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5236{
5237 int i, err = 0;
5238
5239 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005240 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005241 if (!err)
5242 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005243 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005244 break;
5245 }
5246
5247 return err;
5248}
5249
5250/**
Auke Kok9a799d72007-09-15 14:07:45 -07005251 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005252 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005253 *
5254 * Returns 0 on success, negative on failure
5255 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005256int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005257{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005258 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005259 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005260
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005261 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005262 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005263 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005264 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005265 if (!rx_ring->rx_buffer_info)
5266 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005267
Auke Kok9a799d72007-09-15 14:07:45 -07005268 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005269 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5270 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005271
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005272 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005273 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005274
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005275 if (!rx_ring->desc)
5276 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005277
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005278 rx_ring->next_to_clean = 0;
5279 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005280
5281 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005282err:
5283 vfree(rx_ring->rx_buffer_info);
5284 rx_ring->rx_buffer_info = NULL;
5285 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005286 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005287}
5288
5289/**
Alexander Duyck69888672008-09-11 20:05:39 -07005290 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5291 * @adapter: board private structure
5292 *
5293 * If this function returns with an error, then it's possible one or
5294 * more of the rings is populated (while the rest are not). It is the
5295 * callers duty to clean those orphaned rings.
5296 *
5297 * Return 0 on success, negative on failure
5298 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005299static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5300{
5301 int i, err = 0;
5302
5303 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005304 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005305 if (!err)
5306 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005307 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005308 break;
5309 }
5310
5311 return err;
5312}
5313
5314/**
Auke Kok9a799d72007-09-15 14:07:45 -07005315 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005316 * @tx_ring: Tx descriptor ring for a specific queue
5317 *
5318 * Free all transmit software resources
5319 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005320void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005321{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005323
5324 vfree(tx_ring->tx_buffer_info);
5325 tx_ring->tx_buffer_info = NULL;
5326
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005327 /* if not set, then don't free */
5328 if (!tx_ring->desc)
5329 return;
5330
5331 dma_free_coherent(tx_ring->dev, tx_ring->size,
5332 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005333
5334 tx_ring->desc = NULL;
5335}
5336
5337/**
5338 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5339 * @adapter: board private structure
5340 *
5341 * Free all transmit software resources
5342 **/
5343static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5344{
5345 int i;
5346
5347 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005348 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005349 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005350}
5351
5352/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005353 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005354 * @rx_ring: ring to clean the resources from
5355 *
5356 * Free all receive software resources
5357 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005358void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005359{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005360 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005361
5362 vfree(rx_ring->rx_buffer_info);
5363 rx_ring->rx_buffer_info = NULL;
5364
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005365 /* if not set, then don't free */
5366 if (!rx_ring->desc)
5367 return;
5368
5369 dma_free_coherent(rx_ring->dev, rx_ring->size,
5370 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005371
5372 rx_ring->desc = NULL;
5373}
5374
5375/**
5376 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5377 * @adapter: board private structure
5378 *
5379 * Free all receive software resources
5380 **/
5381static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5382{
5383 int i;
5384
5385 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005386 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005387 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005388}
5389
5390/**
Auke Kok9a799d72007-09-15 14:07:45 -07005391 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5392 * @netdev: network interface device structure
5393 * @new_mtu: new value for maximum frame size
5394 *
5395 * Returns 0 on success, negative on failure
5396 **/
5397static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5398{
5399 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005400 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005401 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5402
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005403 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005404 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5405 hw->mac.type != ixgbe_mac_X540) {
5406 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5407 return -EINVAL;
5408 } else {
5409 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5410 return -EINVAL;
5411 }
Auke Kok9a799d72007-09-15 14:07:45 -07005412
Emil Tantilov396e7992010-07-01 20:05:12 +00005413 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005414 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005415 netdev->mtu = new_mtu;
5416
John Fastabend16b61be2010-11-16 19:26:44 -08005417 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5418 hw->fc.low_water = FC_LOW_WATER(max_frame);
5419
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005420 if (netif_running(netdev))
5421 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005422
5423 return 0;
5424}
5425
5426/**
5427 * ixgbe_open - Called when a network interface is made active
5428 * @netdev: network interface device structure
5429 *
5430 * Returns 0 on success, negative value on failure
5431 *
5432 * The open entry point is called when a network interface is made
5433 * active by the system (IFF_UP). At this point all resources needed
5434 * for transmit and receive operations are allocated, the interrupt
5435 * handler is registered with the OS, the watchdog timer is started,
5436 * and the stack is notified that the interface is ready.
5437 **/
5438static int ixgbe_open(struct net_device *netdev)
5439{
5440 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5441 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005442
Auke Kok4bebfaa2008-02-11 09:26:01 -08005443 /* disallow open during test */
5444 if (test_bit(__IXGBE_TESTING, &adapter->state))
5445 return -EBUSY;
5446
Jesse Brandeburg54386462009-04-17 20:44:27 +00005447 netif_carrier_off(netdev);
5448
Auke Kok9a799d72007-09-15 14:07:45 -07005449 /* allocate transmit descriptors */
5450 err = ixgbe_setup_all_tx_resources(adapter);
5451 if (err)
5452 goto err_setup_tx;
5453
Auke Kok9a799d72007-09-15 14:07:45 -07005454 /* allocate receive descriptors */
5455 err = ixgbe_setup_all_rx_resources(adapter);
5456 if (err)
5457 goto err_setup_rx;
5458
5459 ixgbe_configure(adapter);
5460
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005461 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005462 if (err)
5463 goto err_req_irq;
5464
Auke Kok9a799d72007-09-15 14:07:45 -07005465 err = ixgbe_up_complete(adapter);
5466 if (err)
5467 goto err_up;
5468
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005469 netif_tx_start_all_queues(netdev);
5470
Auke Kok9a799d72007-09-15 14:07:45 -07005471 return 0;
5472
5473err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005474 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005475 ixgbe_free_irq(adapter);
5476err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005477err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005478 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005479err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005480 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005481 ixgbe_reset(adapter);
5482
5483 return err;
5484}
5485
5486/**
5487 * ixgbe_close - Disables a network interface
5488 * @netdev: network interface device structure
5489 *
5490 * Returns 0, this is not allowed to fail
5491 *
5492 * The close entry point is called when an interface is de-activated
5493 * by the OS. The hardware is still under the drivers control, but
5494 * needs to be disabled. A global MAC reset is issued to stop the
5495 * hardware, and all transmit and receive resources are freed.
5496 **/
5497static int ixgbe_close(struct net_device *netdev)
5498{
5499 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005500
5501 ixgbe_down(adapter);
5502 ixgbe_free_irq(adapter);
5503
Alexander Duycke4911d52011-05-11 07:18:52 +00005504 ixgbe_fdir_filter_exit(adapter);
5505
Auke Kok9a799d72007-09-15 14:07:45 -07005506 ixgbe_free_all_tx_resources(adapter);
5507 ixgbe_free_all_rx_resources(adapter);
5508
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005509 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005510
5511 return 0;
5512}
5513
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005514#ifdef CONFIG_PM
5515static int ixgbe_resume(struct pci_dev *pdev)
5516{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005517 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5518 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005519 u32 err;
5520
5521 pci_set_power_state(pdev, PCI_D0);
5522 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005523 /*
5524 * pci_restore_state clears dev->state_saved so call
5525 * pci_save_state to restore it.
5526 */
5527 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005528
5529 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005530 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005531 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005532 return err;
5533 }
5534 pci_set_master(pdev);
5535
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005536 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005537
5538 err = ixgbe_init_interrupt_scheme(adapter);
5539 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005540 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005541 return err;
5542 }
5543
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005544 ixgbe_reset(adapter);
5545
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005546 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5547
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005548 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005549 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005550 if (err)
5551 return err;
5552 }
5553
5554 netif_device_attach(netdev);
5555
5556 return 0;
5557}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005558#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005559
5560static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005561{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005562 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5563 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005564 struct ixgbe_hw *hw = &adapter->hw;
5565 u32 ctrl, fctrl;
5566 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005567#ifdef CONFIG_PM
5568 int retval = 0;
5569#endif
5570
5571 netif_device_detach(netdev);
5572
5573 if (netif_running(netdev)) {
5574 ixgbe_down(adapter);
5575 ixgbe_free_irq(adapter);
5576 ixgbe_free_all_tx_resources(adapter);
5577 ixgbe_free_all_rx_resources(adapter);
5578 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005579
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005580 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005581#ifdef CONFIG_DCB
5582 kfree(adapter->ixgbe_ieee_pfc);
5583 kfree(adapter->ixgbe_ieee_ets);
5584#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005585
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005586#ifdef CONFIG_PM
5587 retval = pci_save_state(pdev);
5588 if (retval)
5589 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005590
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005591#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005592 if (wufc) {
5593 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005594
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005595 /* turn on all-multi mode if wake on multicast is enabled */
5596 if (wufc & IXGBE_WUFC_MC) {
5597 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5598 fctrl |= IXGBE_FCTRL_MPE;
5599 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5600 }
5601
5602 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5603 ctrl |= IXGBE_CTRL_GIO_DIS;
5604 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5605
5606 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5607 } else {
5608 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5609 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5610 }
5611
Alexander Duyckbd508172010-11-16 19:27:03 -08005612 switch (hw->mac.type) {
5613 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005614 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005615 break;
5616 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005617 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005618 pci_wake_from_d3(pdev, !!wufc);
5619 break;
5620 default:
5621 break;
5622 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005623
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005624 *enable_wake = !!wufc;
5625
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005626 ixgbe_release_hw_control(adapter);
5627
5628 pci_disable_device(pdev);
5629
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005630 return 0;
5631}
5632
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005633#ifdef CONFIG_PM
5634static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5635{
5636 int retval;
5637 bool wake;
5638
5639 retval = __ixgbe_shutdown(pdev, &wake);
5640 if (retval)
5641 return retval;
5642
5643 if (wake) {
5644 pci_prepare_to_sleep(pdev);
5645 } else {
5646 pci_wake_from_d3(pdev, false);
5647 pci_set_power_state(pdev, PCI_D3hot);
5648 }
5649
5650 return 0;
5651}
5652#endif /* CONFIG_PM */
5653
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005654static void ixgbe_shutdown(struct pci_dev *pdev)
5655{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005656 bool wake;
5657
5658 __ixgbe_shutdown(pdev, &wake);
5659
5660 if (system_state == SYSTEM_POWER_OFF) {
5661 pci_wake_from_d3(pdev, wake);
5662 pci_set_power_state(pdev, PCI_D3hot);
5663 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005664}
5665
5666/**
Auke Kok9a799d72007-09-15 14:07:45 -07005667 * ixgbe_update_stats - Update the board statistics counters.
5668 * @adapter: board private structure
5669 **/
5670void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5671{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005672 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005673 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005674 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005675 u64 total_mpc = 0;
5676 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005677 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5678 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5679 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005680
Don Skidmored08935c2010-06-11 13:20:29 +00005681 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5682 test_bit(__IXGBE_RESETTING, &adapter->state))
5683 return;
5684
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005685 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005686 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005687 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005688 for (i = 0; i < 16; i++)
5689 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005690 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005691 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005692 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5693 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005694 }
5695 adapter->rsc_total_count = rsc_count;
5696 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005697 }
5698
Alexander Duyck5b7da512010-11-16 19:26:50 -08005699 for (i = 0; i < adapter->num_rx_queues; i++) {
5700 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5701 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5702 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5703 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5704 bytes += rx_ring->stats.bytes;
5705 packets += rx_ring->stats.packets;
5706 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005707 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005708 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5709 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5710 netdev->stats.rx_bytes = bytes;
5711 netdev->stats.rx_packets = packets;
5712
5713 bytes = 0;
5714 packets = 0;
5715 /* gather some stats to the adapter struct that are per queue */
5716 for (i = 0; i < adapter->num_tx_queues; i++) {
5717 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5718 restart_queue += tx_ring->tx_stats.restart_queue;
5719 tx_busy += tx_ring->tx_stats.tx_busy;
5720 bytes += tx_ring->stats.bytes;
5721 packets += tx_ring->stats.packets;
5722 }
5723 adapter->restart_queue = restart_queue;
5724 adapter->tx_busy = tx_busy;
5725 netdev->stats.tx_bytes = bytes;
5726 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005727
Joe Perches7ca647b2010-09-07 21:35:40 +00005728 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005729 for (i = 0; i < 8; i++) {
5730 /* for packet buffers not used, the register should read 0 */
5731 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5732 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005733 hwstats->mpc[i] += mpc;
5734 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005735 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005736 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5737 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5738 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5739 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5740 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005741 switch (hw->mac.type) {
5742 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005743 hwstats->pxonrxc[i] +=
5744 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005745 break;
5746 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005747 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005748 hwstats->pxonrxc[i] +=
5749 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005750 break;
5751 default:
5752 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005753 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005754 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5755 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005756 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005757 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005758 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005759 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005760
John Fastabendc84d3242010-11-16 19:27:12 -08005761 ixgbe_update_xoff_received(adapter);
5762
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005763 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005764 switch (hw->mac.type) {
5765 case ixgbe_mac_82598EB:
5766 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005767 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5768 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5769 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5770 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005771 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005772 /* OS2BMC stats are X540 only*/
5773 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5774 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5775 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5776 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5777 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005778 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005779 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005780 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005781 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005782 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005783 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005784 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005785 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5786 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005787#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005788 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5789 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5790 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5791 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5792 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5793 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005794#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005795 break;
5796 default:
5797 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005798 }
Auke Kok9a799d72007-09-15 14:07:45 -07005799 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005800 hwstats->bprc += bprc;
5801 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005802 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005803 hwstats->mprc -= bprc;
5804 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5805 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5806 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5807 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5808 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5809 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5810 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5811 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005812 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005813 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005814 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005815 hwstats->lxofftxc += lxoff;
5816 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5817 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5818 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005819 /*
5820 * 82598 errata - tx of flow control packets is included in tx counters
5821 */
5822 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005823 hwstats->gptc -= xon_off_tot;
5824 hwstats->mptc -= xon_off_tot;
5825 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5826 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5827 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5828 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5829 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5830 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5831 hwstats->ptc64 -= xon_off_tot;
5832 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5833 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5834 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5835 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5836 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5837 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005838
5839 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005840 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005841
5842 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005843 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005844 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005845 netdev->stats.rx_length_errors = hwstats->rlec;
5846 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005847 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005848}
5849
5850/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005851 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5852 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005853 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005854static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005855{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005856 struct ixgbe_hw *hw = &adapter->hw;
5857 int i;
5858
Alexander Duyckd034acf2011-04-27 09:25:34 +00005859 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5860 return;
5861
5862 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5863
5864 /* if interface is down do nothing */
5865 if (test_bit(__IXGBE_DOWN, &adapter->state))
5866 return;
5867
5868 /* do nothing if we are not using signature filters */
5869 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5870 return;
5871
5872 adapter->fdir_overflow++;
5873
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005874 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5875 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005876 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005877 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005878 /* re-enable flow director interrupts */
5879 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005880 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005881 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005882 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005883 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005884}
5885
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005886/**
5887 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5888 * @adapter - pointer to the device adapter structure
5889 *
5890 * This function serves two purposes. First it strobes the interrupt lines
5891 * in order to make certain interrupts are occuring. Secondly it sets the
5892 * bits needed to check for TX hangs. As a result we should immediately
5893 * determine if a hang has occured.
5894 */
5895static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5896{
Auke Kok9a799d72007-09-15 14:07:45 -07005897 struct ixgbe_hw *hw = &adapter->hw;
5898 u64 eics = 0;
5899 int i;
5900
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005901 /* If we're down or resetting, just bail */
5902 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5903 test_bit(__IXGBE_RESETTING, &adapter->state))
5904 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005905
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005906 /* Force detection of hung controller */
5907 if (netif_carrier_ok(adapter->netdev)) {
5908 for (i = 0; i < adapter->num_tx_queues; i++)
5909 set_check_for_tx_hang(adapter->tx_ring[i]);
5910 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005911
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005912 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005913 /*
5914 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005915 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005916 * would set *both* EIMS and EICS for any bit in EIAM
5917 */
5918 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5919 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005920 } else {
5921 /* get one bit for every active tx/rx interrupt vector */
5922 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5923 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005924 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005925 eics |= ((u64)1 << i);
5926 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005927 }
5928
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005929 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005930 ixgbe_irq_rearm_queues(adapter, eics);
5931
Alexander Duyckfe49f042009-06-04 16:00:09 +00005932}
5933
5934/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005935 * ixgbe_watchdog_update_link - update the link status
5936 * @adapter - pointer to the device adapter structure
5937 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005938 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005939static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005940{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005941 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005942 u32 link_speed = adapter->link_speed;
5943 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005944 int i;
5945
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005946 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5947 return;
5948
5949 if (hw->mac.ops.check_link) {
5950 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005951 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005952 /* always assume link is up, if no check link function */
5953 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5954 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005955 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005956 if (link_up) {
5957 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5958 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5959 hw->mac.ops.fc_enable(hw, i);
5960 } else {
5961 hw->mac.ops.fc_enable(hw, 0);
5962 }
5963 }
5964
5965 if (link_up ||
5966 time_after(jiffies, (adapter->link_check_timeout +
5967 IXGBE_TRY_LINK_TIMEOUT))) {
5968 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5969 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5970 IXGBE_WRITE_FLUSH(hw);
5971 }
5972
5973 adapter->link_up = link_up;
5974 adapter->link_speed = link_speed;
5975}
5976
5977/**
5978 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5979 * print link up message
5980 * @adapter - pointer to the device adapter structure
5981 **/
5982static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5983{
5984 struct net_device *netdev = adapter->netdev;
5985 struct ixgbe_hw *hw = &adapter->hw;
5986 u32 link_speed = adapter->link_speed;
5987 bool flow_rx, flow_tx;
5988
5989 /* only continue if link was previously down */
5990 if (netif_carrier_ok(netdev))
5991 return;
5992
5993 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5994
5995 switch (hw->mac.type) {
5996 case ixgbe_mac_82598EB: {
5997 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5998 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5999 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6000 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6001 }
6002 break;
6003 case ixgbe_mac_X540:
6004 case ixgbe_mac_82599EB: {
6005 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6006 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6007 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6008 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6009 }
6010 break;
6011 default:
6012 flow_tx = false;
6013 flow_rx = false;
6014 break;
6015 }
6016 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6017 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6018 "10 Gbps" :
6019 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6020 "1 Gbps" :
6021 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6022 "100 Mbps" :
6023 "unknown speed"))),
6024 ((flow_rx && flow_tx) ? "RX/TX" :
6025 (flow_rx ? "RX" :
6026 (flow_tx ? "TX" : "None"))));
6027
6028 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006029 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006030}
6031
6032/**
6033 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6034 * print link down message
6035 * @adapter - pointer to the adapter structure
6036 **/
6037static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6038{
6039 struct net_device *netdev = adapter->netdev;
6040 struct ixgbe_hw *hw = &adapter->hw;
6041
6042 adapter->link_up = false;
6043 adapter->link_speed = 0;
6044
6045 /* only continue if link was up previously */
6046 if (!netif_carrier_ok(netdev))
6047 return;
6048
6049 /* poll for SFP+ cable when link is down */
6050 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6051 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6052
6053 e_info(drv, "NIC Link is Down\n");
6054 netif_carrier_off(netdev);
6055}
6056
6057/**
6058 * ixgbe_watchdog_flush_tx - flush queues on link down
6059 * @adapter - pointer to the device adapter structure
6060 **/
6061static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6062{
6063 int i;
6064 int some_tx_pending = 0;
6065
6066 if (!netif_carrier_ok(adapter->netdev)) {
6067 for (i = 0; i < adapter->num_tx_queues; i++) {
6068 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6069 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6070 some_tx_pending = 1;
6071 break;
6072 }
6073 }
6074
6075 if (some_tx_pending) {
6076 /* We've lost link, so the controller stops DMA,
6077 * but we've got queued Tx work that's never going
6078 * to get done, so reset controller to flush Tx.
6079 * (Do the reset outside of interrupt context).
6080 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006081 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006082 }
6083 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006084}
6085
Greg Rosea985b6c32010-11-18 03:02:52 +00006086static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6087{
6088 u32 ssvpc;
6089
6090 /* Do not perform spoof check for 82598 */
6091 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6092 return;
6093
6094 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6095
6096 /*
6097 * ssvpc register is cleared on read, if zero then no
6098 * spoofed packets in the last interval.
6099 */
6100 if (!ssvpc)
6101 return;
6102
6103 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6104}
6105
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006106/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006107 * ixgbe_watchdog_subtask - check and bring link up
6108 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006109 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006110static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006111{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006112 /* if interface is down do nothing */
6113 if (test_bit(__IXGBE_DOWN, &adapter->state))
6114 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006115
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006116 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006117
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006118 if (adapter->link_up)
6119 ixgbe_watchdog_link_is_up(adapter);
6120 else
6121 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006122
Greg Rosea985b6c32010-11-18 03:02:52 +00006123 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006124 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006125
6126 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006127}
6128
Alexander Duyck70864002011-04-27 09:13:56 +00006129/**
6130 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6131 * @adapter - the ixgbe adapter structure
6132 **/
6133static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6134{
6135 struct ixgbe_hw *hw = &adapter->hw;
6136 s32 err;
6137
6138 /* not searching for SFP so there is nothing to do here */
6139 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6140 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6141 return;
6142
6143 /* someone else is in init, wait until next service event */
6144 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6145 return;
6146
6147 err = hw->phy.ops.identify_sfp(hw);
6148 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6149 goto sfp_out;
6150
6151 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6152 /* If no cable is present, then we need to reset
6153 * the next time we find a good cable. */
6154 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6155 }
6156
6157 /* exit on error */
6158 if (err)
6159 goto sfp_out;
6160
6161 /* exit if reset not needed */
6162 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6163 goto sfp_out;
6164
6165 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6166
6167 /*
6168 * A module may be identified correctly, but the EEPROM may not have
6169 * support for that module. setup_sfp() will fail in that case, so
6170 * we should not allow that module to load.
6171 */
6172 if (hw->mac.type == ixgbe_mac_82598EB)
6173 err = hw->phy.ops.reset(hw);
6174 else
6175 err = hw->mac.ops.setup_sfp(hw);
6176
6177 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6178 goto sfp_out;
6179
6180 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6181 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6182
6183sfp_out:
6184 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6185
6186 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6187 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6188 e_dev_err("failed to initialize because an unsupported "
6189 "SFP+ module type was detected.\n");
6190 e_dev_err("Reload the driver after installing a "
6191 "supported module.\n");
6192 unregister_netdev(adapter->netdev);
6193 }
6194}
6195
6196/**
6197 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6198 * @adapter - the ixgbe adapter structure
6199 **/
6200static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6201{
6202 struct ixgbe_hw *hw = &adapter->hw;
6203 u32 autoneg;
6204 bool negotiation;
6205
6206 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6207 return;
6208
6209 /* someone else is in init, wait until next service event */
6210 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6211 return;
6212
6213 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6214
6215 autoneg = hw->phy.autoneg_advertised;
6216 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6217 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6218 hw->mac.autotry_restart = false;
6219 if (hw->mac.ops.setup_link)
6220 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6221
6222 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6223 adapter->link_check_timeout = jiffies;
6224 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6225}
6226
6227/**
6228 * ixgbe_service_timer - Timer Call-back
6229 * @data: pointer to adapter cast into an unsigned long
6230 **/
6231static void ixgbe_service_timer(unsigned long data)
6232{
6233 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6234 unsigned long next_event_offset;
6235
6236 /* poll faster when waiting for link */
6237 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6238 next_event_offset = HZ / 10;
6239 else
6240 next_event_offset = HZ * 2;
6241
6242 /* Reset the timer */
6243 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6244
6245 ixgbe_service_event_schedule(adapter);
6246}
6247
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006248static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6249{
6250 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6251 return;
6252
6253 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6254
6255 /* If we're already down or resetting, just bail */
6256 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6257 test_bit(__IXGBE_RESETTING, &adapter->state))
6258 return;
6259
6260 ixgbe_dump(adapter);
6261 netdev_err(adapter->netdev, "Reset adapter\n");
6262 adapter->tx_timeout_count++;
6263
6264 ixgbe_reinit_locked(adapter);
6265}
6266
Alexander Duyck70864002011-04-27 09:13:56 +00006267/**
6268 * ixgbe_service_task - manages and runs subtasks
6269 * @work: pointer to work_struct containing our data
6270 **/
6271static void ixgbe_service_task(struct work_struct *work)
6272{
6273 struct ixgbe_adapter *adapter = container_of(work,
6274 struct ixgbe_adapter,
6275 service_task);
6276
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006277 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006278 ixgbe_sfp_detection_subtask(adapter);
6279 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006280 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006281 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006282 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006283 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006284
6285 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006286}
6287
Alexander Duyck897ab152011-05-27 05:31:47 +00006288void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6289 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006290{
6291 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006292 u16 i = tx_ring->next_to_use;
6293
6294 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6295
6296 i++;
6297 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6298
6299 /* set bits to identify this as an advanced context descriptor */
6300 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6301
6302 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6303 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6304 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6305 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6306}
6307
6308static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6309 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6310{
Auke Kok9a799d72007-09-15 14:07:45 -07006311 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006312 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006313 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006314
Alexander Duyck897ab152011-05-27 05:31:47 +00006315 if (!skb_is_gso(skb))
6316 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006317
Alexander Duyck897ab152011-05-27 05:31:47 +00006318 if (skb_header_cloned(skb)) {
6319 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6320 if (err)
6321 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006322 }
6323
Alexander Duyck897ab152011-05-27 05:31:47 +00006324 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6325 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6326
6327 if (protocol == __constant_htons(ETH_P_IP)) {
6328 struct iphdr *iph = ip_hdr(skb);
6329 iph->tot_len = 0;
6330 iph->check = 0;
6331 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6332 iph->daddr, 0,
6333 IPPROTO_TCP,
6334 0);
6335 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6336 } else if (skb_is_gso_v6(skb)) {
6337 ipv6_hdr(skb)->payload_len = 0;
6338 tcp_hdr(skb)->check =
6339 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6340 &ipv6_hdr(skb)->daddr,
6341 0, IPPROTO_TCP, 0);
6342 }
6343
6344 l4len = tcp_hdrlen(skb);
6345 *hdr_len = skb_transport_offset(skb) + l4len;
6346
6347 /* mss_l4len_id: use 1 as index for TSO */
6348 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6349 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6350 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6351
6352 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6353 vlan_macip_lens = skb_network_header_len(skb);
6354 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6355 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6356
6357 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6358 mss_l4len_idx);
6359
6360 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006361}
6362
Alexander Duyck897ab152011-05-27 05:31:47 +00006363static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006364 struct sk_buff *skb, u32 tx_flags,
6365 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006366{
Alexander Duyck897ab152011-05-27 05:31:47 +00006367 u32 vlan_macip_lens = 0;
6368 u32 mss_l4len_idx = 0;
6369 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006370
Alexander Duyck897ab152011-05-27 05:31:47 +00006371 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006372 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck897ab152011-05-27 05:31:47 +00006373 return false;
6374 } else {
6375 u8 l4_hdr = 0;
6376 switch (protocol) {
6377 case __constant_htons(ETH_P_IP):
6378 vlan_macip_lens |= skb_network_header_len(skb);
6379 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6380 l4_hdr = ip_hdr(skb)->protocol;
6381 break;
6382 case __constant_htons(ETH_P_IPV6):
6383 vlan_macip_lens |= skb_network_header_len(skb);
6384 l4_hdr = ipv6_hdr(skb)->nexthdr;
6385 break;
6386 default:
6387 if (unlikely(net_ratelimit())) {
6388 dev_warn(tx_ring->dev,
6389 "partial checksum but proto=%x!\n",
6390 skb->protocol);
6391 }
6392 break;
6393 }
Auke Kok9a799d72007-09-15 14:07:45 -07006394
Alexander Duyck897ab152011-05-27 05:31:47 +00006395 switch (l4_hdr) {
6396 case IPPROTO_TCP:
6397 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6398 mss_l4len_idx = tcp_hdrlen(skb) <<
6399 IXGBE_ADVTXD_L4LEN_SHIFT;
6400 break;
6401 case IPPROTO_SCTP:
6402 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6403 mss_l4len_idx = sizeof(struct sctphdr) <<
6404 IXGBE_ADVTXD_L4LEN_SHIFT;
6405 break;
6406 case IPPROTO_UDP:
6407 mss_l4len_idx = sizeof(struct udphdr) <<
6408 IXGBE_ADVTXD_L4LEN_SHIFT;
6409 break;
6410 default:
6411 if (unlikely(net_ratelimit())) {
6412 dev_warn(tx_ring->dev,
6413 "partial checksum but l4 proto=%x!\n",
6414 skb->protocol);
6415 }
6416 break;
6417 }
Auke Kok9a799d72007-09-15 14:07:45 -07006418 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006419
Alexander Duyck897ab152011-05-27 05:31:47 +00006420 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6421 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6422
6423 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6424 type_tucmd, mss_l4len_idx);
6425
6426 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006427}
6428
Alexander Duyckd3d00232011-07-15 02:31:25 +00006429static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6430{
6431 /* set type for advanced descriptor with frame checksum insertion */
6432 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6433 IXGBE_ADVTXD_DCMD_IFCS |
6434 IXGBE_ADVTXD_DCMD_DEXT);
6435
6436 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006437 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006438 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6439
6440 /* set segmentation enable bits for TSO/FSO */
6441#ifdef IXGBE_FCOE
6442 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6443#else
6444 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6445#endif
6446 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6447
6448 return cmd_type;
6449}
6450
6451static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6452{
6453 __le32 olinfo_status =
6454 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6455
6456 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6457 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6458 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6459 /* enble IPv4 checksum for TSO */
6460 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6461 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6462 }
6463
6464 /* enable L4 checksum for TSO and TX checksum offload */
6465 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6466 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6467
6468#ifdef IXGBE_FCOE
6469 /* use index 1 context for FCOE/FSO */
6470 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6471 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6472 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6473
6474#endif
6475 return olinfo_status;
6476}
6477
6478#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6479 IXGBE_TXD_CMD_RS)
6480
6481static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6482 struct sk_buff *skb,
6483 struct ixgbe_tx_buffer *first,
6484 u32 tx_flags,
6485 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006486{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006487 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006488 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006489 union ixgbe_adv_tx_desc *tx_desc;
6490 dma_addr_t dma;
6491 __le32 cmd_type, olinfo_status;
6492 struct skb_frag_struct *frag;
6493 unsigned int f = 0;
6494 unsigned int data_len = skb->data_len;
6495 unsigned int size = skb_headlen(skb);
6496 u32 offset = 0;
6497 u32 paylen = skb->len - hdr_len;
6498 u16 i = tx_ring->next_to_use;
6499 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006500
Alexander Duyckd3d00232011-07-15 02:31:25 +00006501#ifdef IXGBE_FCOE
6502 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6503 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6504 data_len -= sizeof(struct fcoe_crc_eof);
6505 } else {
6506 size -= sizeof(struct fcoe_crc_eof) - data_len;
6507 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006508 }
Auke Kok9a799d72007-09-15 14:07:45 -07006509 }
6510
Alexander Duyckd3d00232011-07-15 02:31:25 +00006511#endif
6512 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6513 if (dma_mapping_error(dev, dma))
6514 goto dma_error;
6515
6516 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6517 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6518
6519 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6520
6521 for (;;) {
6522 while (size > IXGBE_MAX_DATA_PER_TXD) {
6523 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6524 tx_desc->read.cmd_type_len =
6525 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6526 tx_desc->read.olinfo_status = olinfo_status;
6527
6528 offset += IXGBE_MAX_DATA_PER_TXD;
6529 size -= IXGBE_MAX_DATA_PER_TXD;
6530
6531 tx_desc++;
6532 i++;
6533 if (i == tx_ring->count) {
6534 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6535 i = 0;
6536 }
6537 }
6538
6539 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6540 tx_buffer_info->length = offset + size;
6541 tx_buffer_info->tx_flags = tx_flags;
6542 tx_buffer_info->dma = dma;
6543
6544 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6545 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6546 tx_desc->read.olinfo_status = olinfo_status;
6547
6548 if (!data_len)
6549 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006550
6551 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006552#ifdef IXGBE_FCOE
6553 size = min_t(unsigned int, data_len, frag->size);
6554#else
6555 size = frag->size;
6556#endif
6557 data_len -= size;
6558 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006559
Alexander Duyckd3d00232011-07-15 02:31:25 +00006560 offset = 0;
6561 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006562
Alexander Duyckd3d00232011-07-15 02:31:25 +00006563 dma = dma_map_page(dev, frag->page, frag->page_offset,
6564 size, DMA_TO_DEVICE);
6565 if (dma_mapping_error(dev, dma))
6566 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006567
Alexander Duyckd3d00232011-07-15 02:31:25 +00006568 tx_desc++;
6569 i++;
6570 if (i == tx_ring->count) {
6571 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6572 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006573 }
6574 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006575
Alexander Duyckd3d00232011-07-15 02:31:25 +00006576 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6577
6578 i++;
6579 if (i == tx_ring->count)
6580 i = 0;
6581
6582 tx_ring->next_to_use = i;
6583
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006584 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6585 gso_segs = skb_shinfo(skb)->gso_segs;
6586#ifdef IXGBE_FCOE
6587 /* adjust for FCoE Sequence Offload */
6588 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6589 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6590 skb_shinfo(skb)->gso_size);
6591#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006592 else
6593 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006594
6595 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006596 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6597 tx_buffer_info->gso_segs = gso_segs;
6598 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006599
Alexander Duyckd3d00232011-07-15 02:31:25 +00006600 /* set the timestamp */
6601 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006602
6603 /*
6604 * Force memory writes to complete before letting h/w
6605 * know there are new descriptors to fetch. (Only
6606 * applicable for weak-ordered memory model archs,
6607 * such as IA-64).
6608 */
6609 wmb();
6610
Alexander Duyckd3d00232011-07-15 02:31:25 +00006611 /* set next_to_watch value indicating a packet is present */
6612 first->next_to_watch = tx_desc;
6613
6614 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006615 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006616
6617 return;
6618dma_error:
6619 dev_err(dev, "TX DMA map failed\n");
6620
6621 /* clear dma mappings for failed tx_buffer_info map */
6622 for (;;) {
6623 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6624 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6625 if (tx_buffer_info == first)
6626 break;
6627 if (i == 0)
6628 i = tx_ring->count;
6629 i--;
6630 }
6631
6632 dev_kfree_skb_any(skb);
6633
6634 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006635}
6636
Alexander Duyck69830522011-01-06 14:29:58 +00006637static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6638 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006639{
Alexander Duyck69830522011-01-06 14:29:58 +00006640 struct ixgbe_q_vector *q_vector = ring->q_vector;
6641 union ixgbe_atr_hash_dword input = { .dword = 0 };
6642 union ixgbe_atr_hash_dword common = { .dword = 0 };
6643 union {
6644 unsigned char *network;
6645 struct iphdr *ipv4;
6646 struct ipv6hdr *ipv6;
6647 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006648 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006649 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006650
Alexander Duyck69830522011-01-06 14:29:58 +00006651 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6652 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006653 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006654
Alexander Duyck69830522011-01-06 14:29:58 +00006655 /* do nothing if sampling is disabled */
6656 if (!ring->atr_sample_rate)
6657 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006658
Alexander Duyck69830522011-01-06 14:29:58 +00006659 ring->atr_count++;
6660
6661 /* snag network header to get L4 type and address */
6662 hdr.network = skb_network_header(skb);
6663
6664 /* Currently only IPv4/IPv6 with TCP is supported */
6665 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6666 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6667 (protocol != __constant_htons(ETH_P_IP) ||
6668 hdr.ipv4->protocol != IPPROTO_TCP))
6669 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006670
6671 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006672
Alexander Duyck66f32a82011-06-29 05:43:22 +00006673 /* skip this packet since it is invalid or the socket is closing */
6674 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006675 return;
6676
6677 /* sample on all syn packets or once every atr sample count */
6678 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6679 return;
6680
6681 /* reset sample count */
6682 ring->atr_count = 0;
6683
6684 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6685
6686 /*
6687 * src and dst are inverted, think how the receiver sees them
6688 *
6689 * The input is broken into two sections, a non-compressed section
6690 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6691 * is XORed together and stored in the compressed dword.
6692 */
6693 input.formatted.vlan_id = vlan_id;
6694
6695 /*
6696 * since src port and flex bytes occupy the same word XOR them together
6697 * and write the value to source port portion of compressed dword
6698 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006699 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006700 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6701 else
6702 common.port.src ^= th->dest ^ protocol;
6703 common.port.dst ^= th->source;
6704
6705 if (protocol == __constant_htons(ETH_P_IP)) {
6706 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6707 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6708 } else {
6709 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6710 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6711 hdr.ipv6->saddr.s6_addr32[1] ^
6712 hdr.ipv6->saddr.s6_addr32[2] ^
6713 hdr.ipv6->saddr.s6_addr32[3] ^
6714 hdr.ipv6->daddr.s6_addr32[0] ^
6715 hdr.ipv6->daddr.s6_addr32[1] ^
6716 hdr.ipv6->daddr.s6_addr32[2] ^
6717 hdr.ipv6->daddr.s6_addr32[3];
6718 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006719
6720 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006721 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6722 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006723}
6724
Alexander Duyck63544e92011-05-27 05:31:42 +00006725static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006726{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006727 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006728 /* Herbert's original patch had:
6729 * smp_mb__after_netif_stop_queue();
6730 * but since that doesn't exist yet, just open code it. */
6731 smp_mb();
6732
6733 /* We need to check again in a case another CPU has just
6734 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006735 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006736 return -EBUSY;
6737
6738 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006739 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006740 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006741 return 0;
6742}
6743
Alexander Duyck82d4e462011-06-11 01:44:58 +00006744static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006745{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006746 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006747 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006748 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006749}
6750
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006751static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6752{
6753 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006754 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6755 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006756#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006757 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006758
John Fastabende5b64632011-03-08 03:44:52 +00006759 if (((protocol == htons(ETH_P_FCOE)) ||
6760 (protocol == htons(ETH_P_FIP))) &&
6761 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6762 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6763 txq += adapter->ring_feature[RING_F_FCOE].mask;
6764 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006765 }
6766#endif
6767
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006768 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6769 while (unlikely(txq >= dev->real_num_tx_queues))
6770 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006771 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006772 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006773
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006774 return skb_tx_hash(dev, skb);
6775}
6776
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006777netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006778 struct ixgbe_adapter *adapter,
6779 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006780{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006781 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006782 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006783 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006784#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6785 unsigned short f;
6786#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006787 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006788 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006789 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006790
Alexander Duycka535c302011-05-27 05:31:52 +00006791 /*
6792 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6793 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6794 * + 2 desc gap to keep tail from touching head,
6795 * + 1 desc for context descriptor,
6796 * otherwise try next time
6797 */
6798#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6799 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6800 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6801#else
6802 count += skb_shinfo(skb)->nr_frags;
6803#endif
6804 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6805 tx_ring->tx_stats.tx_busy++;
6806 return NETDEV_TX_BUSY;
6807 }
6808
Alexander Duyck66f32a82011-06-29 05:43:22 +00006809 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006810 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006811 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6812 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6813 /* else if it is a SW VLAN check the next protocol and store the tag */
6814 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6815 struct vlan_hdr *vhdr, _vhdr;
6816 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6817 if (!vhdr)
6818 goto out_drop;
6819
6820 protocol = vhdr->h_vlan_encapsulated_proto;
6821 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6822 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006823 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006824
Alexander Duyck66f32a82011-06-29 05:43:22 +00006825 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6826 skb->priority != TC_PRIO_CONTROL) {
6827 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6828 tx_flags |= tx_ring->dcb_tc <<
6829 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6830 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6831 struct vlan_ethhdr *vhdr;
6832 if (skb_header_cloned(skb) &&
6833 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6834 goto out_drop;
6835 vhdr = (struct vlan_ethhdr *)skb->data;
6836 vhdr->h_vlan_TCI = htons(tx_flags >>
6837 IXGBE_TX_FLAGS_VLAN_SHIFT);
6838 } else {
6839 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6840 }
6841 }
Alexander Duycka535c302011-05-27 05:31:52 +00006842
Alexander Duycka535c302011-05-27 05:31:52 +00006843 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006844 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00006845
Yi Zoueacd73f2009-05-13 13:11:06 +00006846#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006847 /* setup tx offload for FCoE */
6848 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6849 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006850 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6851 if (tso < 0)
6852 goto out_drop;
6853 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00006854 tx_flags |= IXGBE_TX_FLAGS_FSO |
6855 IXGBE_TX_FLAGS_FCOE;
6856 else
6857 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07006858
Alexander Duyck66f32a82011-06-29 05:43:22 +00006859 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006860 }
Auke Kok9a799d72007-09-15 14:07:45 -07006861
Alexander Duyck66f32a82011-06-29 05:43:22 +00006862#endif /* IXGBE_FCOE */
6863 /* setup IPv4/IPv6 offloads */
6864 if (protocol == __constant_htons(ETH_P_IP))
6865 tx_flags |= IXGBE_TX_FLAGS_IPV4;
6866
6867 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6868 if (tso < 0)
6869 goto out_drop;
6870 else if (tso)
6871 tx_flags |= IXGBE_TX_FLAGS_TSO;
6872 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6873 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6874
6875 /* add the ATR filter if ATR is on */
6876 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6877 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6878
6879#ifdef IXGBE_FCOE
6880xmit_fcoe:
6881#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006882 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
6883
6884 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
6885
Auke Kok9a799d72007-09-15 14:07:45 -07006886 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006887
6888out_drop:
6889 dev_kfree_skb_any(skb);
6890 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006891}
6892
Alexander Duyck84418e32010-08-19 13:40:54 +00006893static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6894{
6895 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6896 struct ixgbe_ring *tx_ring;
6897
6898 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006899 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006900}
6901
Auke Kok9a799d72007-09-15 14:07:45 -07006902/**
Auke Kok9a799d72007-09-15 14:07:45 -07006903 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6904 * @netdev: network interface device structure
6905 * @p: pointer to an address structure
6906 *
6907 * Returns 0 on success, negative on failure
6908 **/
6909static int ixgbe_set_mac(struct net_device *netdev, void *p)
6910{
6911 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006912 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006913 struct sockaddr *addr = p;
6914
6915 if (!is_valid_ether_addr(addr->sa_data))
6916 return -EADDRNOTAVAIL;
6917
6918 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006919 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006920
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006921 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6922 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006923
6924 return 0;
6925}
6926
Ben Hutchings6b73e102009-04-29 08:08:58 +00006927static int
6928ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6929{
6930 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6931 struct ixgbe_hw *hw = &adapter->hw;
6932 u16 value;
6933 int rc;
6934
6935 if (prtad != hw->phy.mdio.prtad)
6936 return -EINVAL;
6937 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6938 if (!rc)
6939 rc = value;
6940 return rc;
6941}
6942
6943static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6944 u16 addr, u16 value)
6945{
6946 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6947 struct ixgbe_hw *hw = &adapter->hw;
6948
6949 if (prtad != hw->phy.mdio.prtad)
6950 return -EINVAL;
6951 return hw->phy.ops.write_reg(hw, addr, devad, value);
6952}
6953
6954static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6955{
6956 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6957
6958 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6959}
6960
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006961/**
6962 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006963 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006964 * @netdev: network interface device structure
6965 *
6966 * Returns non-zero on failure
6967 **/
6968static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6969{
6970 int err = 0;
6971 struct ixgbe_adapter *adapter = netdev_priv(dev);
6972 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6973
6974 if (is_valid_ether_addr(mac->san_addr)) {
6975 rtnl_lock();
6976 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6977 rtnl_unlock();
6978 }
6979 return err;
6980}
6981
6982/**
6983 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006984 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006985 * @netdev: network interface device structure
6986 *
6987 * Returns non-zero on failure
6988 **/
6989static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6990{
6991 int err = 0;
6992 struct ixgbe_adapter *adapter = netdev_priv(dev);
6993 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6994
6995 if (is_valid_ether_addr(mac->san_addr)) {
6996 rtnl_lock();
6997 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6998 rtnl_unlock();
6999 }
7000 return err;
7001}
7002
Auke Kok9a799d72007-09-15 14:07:45 -07007003#ifdef CONFIG_NET_POLL_CONTROLLER
7004/*
7005 * Polling 'interrupt' - used by things like netconsole to send skbs
7006 * without having to re-enable interrupts. It's not called while
7007 * the interrupt routine is executing.
7008 */
7009static void ixgbe_netpoll(struct net_device *netdev)
7010{
7011 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007012 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007013
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007014 /* if interface is down do nothing */
7015 if (test_bit(__IXGBE_DOWN, &adapter->state))
7016 return;
7017
Auke Kok9a799d72007-09-15 14:07:45 -07007018 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007019 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7020 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7021 for (i = 0; i < num_q_vectors; i++) {
7022 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7023 ixgbe_msix_clean_many(0, q_vector);
7024 }
7025 } else {
7026 ixgbe_intr(adapter->pdev->irq, netdev);
7027 }
Auke Kok9a799d72007-09-15 14:07:45 -07007028 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007029}
7030#endif
7031
Eric Dumazetde1036b2010-10-20 23:00:04 +00007032static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7033 struct rtnl_link_stats64 *stats)
7034{
7035 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7036 int i;
7037
Eric Dumazet1a515022010-11-16 19:26:42 -08007038 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007039 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007040 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007041 u64 bytes, packets;
7042 unsigned int start;
7043
Eric Dumazet1a515022010-11-16 19:26:42 -08007044 if (ring) {
7045 do {
7046 start = u64_stats_fetch_begin_bh(&ring->syncp);
7047 packets = ring->stats.packets;
7048 bytes = ring->stats.bytes;
7049 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7050 stats->rx_packets += packets;
7051 stats->rx_bytes += bytes;
7052 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007053 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007054
7055 for (i = 0; i < adapter->num_tx_queues; i++) {
7056 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7057 u64 bytes, packets;
7058 unsigned int start;
7059
7060 if (ring) {
7061 do {
7062 start = u64_stats_fetch_begin_bh(&ring->syncp);
7063 packets = ring->stats.packets;
7064 bytes = ring->stats.bytes;
7065 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7066 stats->tx_packets += packets;
7067 stats->tx_bytes += bytes;
7068 }
7069 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007070 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007071 /* following stats updated by ixgbe_watchdog_task() */
7072 stats->multicast = netdev->stats.multicast;
7073 stats->rx_errors = netdev->stats.rx_errors;
7074 stats->rx_length_errors = netdev->stats.rx_length_errors;
7075 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7076 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7077 return stats;
7078}
7079
John Fastabend8b1c0b22011-05-03 02:26:48 +00007080/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7081 * #adapter: pointer to ixgbe_adapter
7082 * @tc: number of traffic classes currently enabled
7083 *
7084 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7085 * 802.1Q priority maps to a packet buffer that exists.
7086 */
7087static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7088{
7089 struct ixgbe_hw *hw = &adapter->hw;
7090 u32 reg, rsave;
7091 int i;
7092
7093 /* 82598 have a static priority to TC mapping that can not
7094 * be changed so no validation is needed.
7095 */
7096 if (hw->mac.type == ixgbe_mac_82598EB)
7097 return;
7098
7099 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7100 rsave = reg;
7101
7102 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7103 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7104
7105 /* If up2tc is out of bounds default to zero */
7106 if (up2tc > tc)
7107 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7108 }
7109
7110 if (reg != rsave)
7111 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7112
7113 return;
7114}
7115
7116
7117/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7118 * classes.
7119 *
7120 * @netdev: net device to configure
7121 * @tc: number of traffic classes to enable
7122 */
7123int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7124{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007125 struct ixgbe_adapter *adapter = netdev_priv(dev);
7126 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007127
7128 /* If DCB is anabled do not remove traffic classes, multiple
7129 * traffic classes are required to implement DCB
7130 */
7131 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7132 return 0;
7133
7134 /* Hardware supports up to 8 traffic classes */
7135 if (tc > MAX_TRAFFIC_CLASS ||
7136 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7137 return -EINVAL;
7138
7139 /* Hardware has to reinitialize queues and interrupts to
7140 * match packet buffer alignment. Unfortunantly, the
7141 * hardware is not flexible enough to do this dynamically.
7142 */
7143 if (netif_running(dev))
7144 ixgbe_close(dev);
7145 ixgbe_clear_interrupt_scheme(adapter);
7146
7147 if (tc)
7148 netdev_set_num_tc(dev, tc);
7149 else
7150 netdev_reset_tc(dev);
7151
John Fastabend8b1c0b22011-05-03 02:26:48 +00007152 ixgbe_init_interrupt_scheme(adapter);
7153 ixgbe_validate_rtr(adapter, tc);
7154 if (netif_running(dev))
7155 ixgbe_open(dev);
7156
7157 return 0;
7158}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007159
Don Skidmore082757a2011-07-21 05:55:00 +00007160void ixgbe_do_reset(struct net_device *netdev)
7161{
7162 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7163
7164 if (netif_running(netdev))
7165 ixgbe_reinit_locked(adapter);
7166 else
7167 ixgbe_reset(adapter);
7168}
7169
7170static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7171{
7172 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7173
7174#ifdef CONFIG_DCB
7175 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7176 data &= ~NETIF_F_HW_VLAN_RX;
7177#endif
7178
7179 /* return error if RXHASH is being enabled when RSS is not supported */
7180 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7181 data &= ~NETIF_F_RXHASH;
7182
7183 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7184 if (!(data & NETIF_F_RXCSUM))
7185 data &= ~NETIF_F_LRO;
7186
7187 /* Turn off LRO if not RSC capable or invalid ITR settings */
7188 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7189 data &= ~NETIF_F_LRO;
7190 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7191 (adapter->rx_itr_setting != 1 &&
7192 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7193 data &= ~NETIF_F_LRO;
7194 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7195 }
7196
7197 return data;
7198}
7199
7200static int ixgbe_set_features(struct net_device *netdev, u32 data)
7201{
7202 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7203 bool need_reset = false;
7204
7205 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7206 if (!(data & NETIF_F_RXCSUM))
7207 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7208 else
7209 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7210
7211 /* Make sure RSC matches LRO, reset if change */
7212 if (!!(data & NETIF_F_LRO) !=
7213 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7214 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7215 switch (adapter->hw.mac.type) {
7216 case ixgbe_mac_X540:
7217 case ixgbe_mac_82599EB:
7218 need_reset = true;
7219 break;
7220 default:
7221 break;
7222 }
7223 }
7224
7225 /*
7226 * Check if Flow Director n-tuple support was enabled or disabled. If
7227 * the state changed, we need to reset.
7228 */
7229 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7230 /* turn off ATR, enable perfect filters and reset */
7231 if (data & NETIF_F_NTUPLE) {
7232 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7233 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7234 need_reset = true;
7235 }
7236 } else if (!(data & NETIF_F_NTUPLE)) {
7237 /* turn off Flow Director, set ATR and reset */
7238 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7239 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7240 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7241 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7242 need_reset = true;
7243 }
7244
7245 if (need_reset)
7246 ixgbe_do_reset(netdev);
7247
7248 return 0;
7249
7250}
7251
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007252static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007253 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007254 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007255 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007256 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007257 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007258 .ndo_validate_addr = eth_validate_addr,
7259 .ndo_set_mac_address = ixgbe_set_mac,
7260 .ndo_change_mtu = ixgbe_change_mtu,
7261 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007262 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7263 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007264 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007265 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7266 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7267 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7268 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007269 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007270 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007271#ifdef CONFIG_NET_POLL_CONTROLLER
7272 .ndo_poll_controller = ixgbe_netpoll,
7273#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007274#ifdef IXGBE_FCOE
7275 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007276 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007277 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007278 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7279 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007280 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007281#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007282 .ndo_set_features = ixgbe_set_features,
7283 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007284};
7285
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007286static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7287 const struct ixgbe_info *ii)
7288{
7289#ifdef CONFIG_PCI_IOV
7290 struct ixgbe_hw *hw = &adapter->hw;
7291 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007292 int num_vf_macvlans, i;
7293 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007294
Greg Rose3377eba792010-12-07 08:16:45 +00007295 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007296 return;
7297
7298 /* The 82599 supports up to 64 VFs per physical function
7299 * but this implementation limits allocation to 63 so that
7300 * basic networking resources are still available to the
7301 * physical function
7302 */
7303 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7304 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7305 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7306 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007307 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007308 goto err_novfs;
7309 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007310
7311 num_vf_macvlans = hw->mac.num_rar_entries -
7312 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7313
7314 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7315 sizeof(struct vf_macvlans),
7316 GFP_KERNEL);
7317 if (mv_list) {
7318 /* Initialize list of VF macvlans */
7319 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7320 for (i = 0; i < num_vf_macvlans; i++) {
7321 mv_list->vf = -1;
7322 mv_list->free = true;
7323 mv_list->rar_entry = hw->mac.num_rar_entries -
7324 (i + adapter->num_vfs + 1);
7325 list_add(&mv_list->l, &adapter->vf_mvs.l);
7326 mv_list++;
7327 }
7328 }
7329
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007330 /* If call to enable VFs succeeded then allocate memory
7331 * for per VF control structures.
7332 */
7333 adapter->vfinfo =
7334 kcalloc(adapter->num_vfs,
7335 sizeof(struct vf_data_storage), GFP_KERNEL);
7336 if (adapter->vfinfo) {
7337 /* Now that we're sure SR-IOV is enabled
7338 * and memory allocated set up the mailbox parameters
7339 */
7340 ixgbe_init_mbx_params_pf(hw);
7341 memcpy(&hw->mbx.ops, ii->mbx_ops,
7342 sizeof(hw->mbx.ops));
7343
7344 /* Disable RSC when in SR-IOV mode */
7345 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7346 IXGBE_FLAG2_RSC_ENABLED);
7347 return;
7348 }
7349
7350 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007351 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7352 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007353 pci_disable_sriov(adapter->pdev);
7354
7355err_novfs:
7356 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7357 adapter->num_vfs = 0;
7358#endif /* CONFIG_PCI_IOV */
7359}
7360
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007361/**
Auke Kok9a799d72007-09-15 14:07:45 -07007362 * ixgbe_probe - Device Initialization Routine
7363 * @pdev: PCI device information struct
7364 * @ent: entry in ixgbe_pci_tbl
7365 *
7366 * Returns 0 on success, negative on failure
7367 *
7368 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7369 * The OS initialization, configuring of the adapter private structure,
7370 * and a hardware reset occur.
7371 **/
7372static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007373 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007374{
7375 struct net_device *netdev;
7376 struct ixgbe_adapter *adapter = NULL;
7377 struct ixgbe_hw *hw;
7378 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007379 static int cards_found;
7380 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007381 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007382 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007383#ifdef IXGBE_FCOE
7384 u16 device_caps;
7385#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007386 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007387
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007388 /* Catch broken hardware that put the wrong VF device ID in
7389 * the PCIe SR-IOV capability.
7390 */
7391 if (pdev->is_virtfn) {
7392 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7393 pci_name(pdev), pdev->vendor, pdev->device);
7394 return -EINVAL;
7395 }
7396
gouji-new9ce77662009-05-06 10:44:45 +00007397 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007398 if (err)
7399 return err;
7400
Nick Nunley1b507732010-04-27 13:10:27 +00007401 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7402 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007403 pci_using_dac = 1;
7404 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007405 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007406 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007407 err = dma_set_coherent_mask(&pdev->dev,
7408 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007409 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007410 dev_err(&pdev->dev,
7411 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007412 goto err_dma;
7413 }
7414 }
7415 pci_using_dac = 0;
7416 }
7417
gouji-new9ce77662009-05-06 10:44:45 +00007418 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007419 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007420 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007421 dev_err(&pdev->dev,
7422 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007423 goto err_pci_reg;
7424 }
7425
Frans Pop19d5afd2009-10-02 10:04:12 -07007426 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007427
Auke Kok9a799d72007-09-15 14:07:45 -07007428 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007429 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007430
John Fastabende901acd2011-04-26 07:26:08 +00007431#ifdef CONFIG_IXGBE_DCB
7432 indices *= MAX_TRAFFIC_CLASS;
7433#endif
7434
John Fastabendc85a2612010-02-25 23:15:21 +00007435 if (ii->mac == ixgbe_mac_82598EB)
7436 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7437 else
7438 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7439
John Fastabende901acd2011-04-26 07:26:08 +00007440#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007441 indices += min_t(unsigned int, num_possible_cpus(),
7442 IXGBE_MAX_FCOE_INDICES);
7443#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007444 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007445 if (!netdev) {
7446 err = -ENOMEM;
7447 goto err_alloc_etherdev;
7448 }
7449
Auke Kok9a799d72007-09-15 14:07:45 -07007450 SET_NETDEV_DEV(netdev, &pdev->dev);
7451
Auke Kok9a799d72007-09-15 14:07:45 -07007452 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007453 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007454
7455 adapter->netdev = netdev;
7456 adapter->pdev = pdev;
7457 hw = &adapter->hw;
7458 hw->back = adapter;
7459 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7460
Jeff Kirsher05857982008-09-11 19:57:00 -07007461 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007462 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007463 if (!hw->hw_addr) {
7464 err = -EIO;
7465 goto err_ioremap;
7466 }
7467
7468 for (i = 1; i <= 5; i++) {
7469 if (pci_resource_len(pdev, i) == 0)
7470 continue;
7471 }
7472
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007473 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007474 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007475 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007476 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007477
Auke Kok9a799d72007-09-15 14:07:45 -07007478 adapter->bd_number = cards_found;
7479
Auke Kok9a799d72007-09-15 14:07:45 -07007480 /* Setup hw api */
7481 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007482 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007483
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007484 /* EEPROM */
7485 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7486 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7487 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7488 if (!(eec & (1 << 8)))
7489 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7490
7491 /* PHY */
7492 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007493 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007494 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7495 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7496 hw->phy.mdio.mmds = 0;
7497 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7498 hw->phy.mdio.dev = netdev;
7499 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7500 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007501
Don Skidmore8ca783a2009-05-26 20:40:47 -07007502 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007503
7504 /* setup the private structure */
7505 err = ixgbe_sw_init(adapter);
7506 if (err)
7507 goto err_sw_init;
7508
Don Skidmoree86bff02010-02-11 04:14:08 +00007509 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007510 switch (adapter->hw.mac.type) {
7511 case ixgbe_mac_82599EB:
7512 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007513 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007514 break;
7515 default:
7516 break;
7517 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007518
Don Skidmorebf069c92009-05-07 10:39:54 +00007519 /*
7520 * If there is a fan on this device and it has failed log the
7521 * failure.
7522 */
7523 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7524 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7525 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007526 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007527 }
7528
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007529 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007530 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007531 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007532 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007533 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7534 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007535 err = 0;
7536 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007537 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007538 "module type was detected.\n");
7539 e_dev_err("Reload the driver after installing a supported "
7540 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007541 goto err_sw_init;
7542 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007543 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007544 goto err_sw_init;
7545 }
7546
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007547 ixgbe_probe_vf(adapter, ii);
7548
Emil Tantilov396e7992010-07-01 20:05:12 +00007549 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007550 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007551 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007552 NETIF_F_HW_VLAN_TX |
7553 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007554 NETIF_F_HW_VLAN_FILTER |
7555 NETIF_F_TSO |
7556 NETIF_F_TSO6 |
7557 NETIF_F_GRO |
7558 NETIF_F_RXHASH |
7559 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007560
Don Skidmore082757a2011-07-21 05:55:00 +00007561 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007562
Don Skidmore58be7662011-04-12 09:42:11 +00007563 switch (adapter->hw.mac.type) {
7564 case ixgbe_mac_82599EB:
7565 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007566 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007567 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7568 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007569 break;
7570 default:
7571 break;
7572 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007573
Jeff Kirsherad31c402008-06-05 04:05:30 -07007574 netdev->vlan_features |= NETIF_F_TSO;
7575 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007576 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007577 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007578 netdev->vlan_features |= NETIF_F_SG;
7579
Jiri Pirko01789342011-08-16 06:29:00 +00007580 netdev->priv_flags |= IFF_UNICAST_FLT;
7581
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007582 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7583 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7584 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007585
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007586#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007587 netdev->dcbnl_ops = &dcbnl_ops;
7588#endif
7589
Yi Zoueacd73f2009-05-13 13:11:06 +00007590#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007591 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007592 if (hw->mac.ops.get_device_caps) {
7593 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007594 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7595 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007596 }
7597 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007598 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7599 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7600 netdev->vlan_features |= NETIF_F_FSO;
7601 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7602 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007603#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007604 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007605 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007606 netdev->vlan_features |= NETIF_F_HIGHDMA;
7607 }
Auke Kok9a799d72007-09-15 14:07:45 -07007608
Don Skidmore082757a2011-07-21 05:55:00 +00007609 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7610 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007611 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007612 netdev->features |= NETIF_F_LRO;
7613
Auke Kok9a799d72007-09-15 14:07:45 -07007614 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007615 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007616 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007617 err = -EIO;
7618 goto err_eeprom;
7619 }
7620
7621 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7622 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7623
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007624 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007625 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007626 err = -EIO;
7627 goto err_eeprom;
7628 }
7629
Don Skidmorec6ecf392010-12-03 03:31:51 +00007630 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7631 if (hw->mac.ops.disable_tx_laser &&
7632 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007633 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007634 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007635 hw->mac.ops.disable_tx_laser(hw);
7636
Alexander Duyck70864002011-04-27 09:13:56 +00007637 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7638 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007639
Alexander Duyck70864002011-04-27 09:13:56 +00007640 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7641 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007642
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007643 err = ixgbe_init_interrupt_scheme(adapter);
7644 if (err)
7645 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007646
Don Skidmore082757a2011-07-21 05:55:00 +00007647 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7648 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007649 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007650 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007651
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007652 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007653 case IXGBE_DEV_ID_82599_SFP:
7654 /* Only this subdevice supports WOL */
7655 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007656 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007657 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007658 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7659 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007660 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007661 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007662 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007663 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007664 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007665 break;
7666 default:
7667 adapter->wol = 0;
7668 break;
7669 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007670 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7671
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007672 /* pick up the PCI bus settings for reporting later */
7673 hw->mac.ops.get_bus_info(hw);
7674
Auke Kok9a799d72007-09-15 14:07:45 -07007675 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007676 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007677 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7678 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007679 "Unknown"),
7680 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7681 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7682 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7683 "Unknown"),
7684 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007685
7686 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7687 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007688 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007689 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007690 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007691 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007692 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007693 else
Don Skidmore289700db2010-12-03 03:32:58 +00007694 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7695 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007696
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007697 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007698 e_dev_warn("PCI-Express bandwidth available for this card is "
7699 "not sufficient for optimal performance.\n");
7700 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7701 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007702 }
7703
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007704 /* save off EEPROM version number */
7705 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7706
Auke Kok9a799d72007-09-15 14:07:45 -07007707 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007708 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007709
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007710 if (err == IXGBE_ERR_EEPROM_VERSION) {
7711 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007712 e_dev_warn("This device is a pre-production adapter/LOM. "
7713 "Please be aware there may be issues associated "
7714 "with your hardware. If you are experiencing "
7715 "problems please contact your Intel or hardware "
7716 "representative who provided you with this "
7717 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007718 }
Auke Kok9a799d72007-09-15 14:07:45 -07007719 strcpy(netdev->name, "eth%d");
7720 err = register_netdev(netdev);
7721 if (err)
7722 goto err_register;
7723
Jesse Brandeburg54386462009-04-17 20:44:27 +00007724 /* carrier off reporting is important to ethtool even BEFORE open */
7725 netif_carrier_off(netdev);
7726
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007727#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007728 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007729 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007730 ixgbe_setup_dca(adapter);
7731 }
7732#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007733 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007734 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007735 for (i = 0; i < adapter->num_vfs; i++)
7736 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7737 }
7738
Emil Tantilov9612de92011-05-07 07:40:20 +00007739 /* Inform firmware of driver version */
7740 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007741 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7742 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007743
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007744 /* add san mac addr to netdev */
7745 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007746
Emil Tantilov849c4542010-06-03 16:53:41 +00007747 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007748 cards_found++;
7749 return 0;
7750
7751err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007752 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007753 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007754err_sw_init:
7755err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007756 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7757 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007758 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007759 iounmap(hw->hw_addr);
7760err_ioremap:
7761 free_netdev(netdev);
7762err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007763 pci_release_selected_regions(pdev,
7764 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007765err_pci_reg:
7766err_dma:
7767 pci_disable_device(pdev);
7768 return err;
7769}
7770
7771/**
7772 * ixgbe_remove - Device Removal Routine
7773 * @pdev: PCI device information struct
7774 *
7775 * ixgbe_remove is called by the PCI subsystem to alert the driver
7776 * that it should release a PCI device. The could be caused by a
7777 * Hot-Plug event, or because the driver is going to be removed from
7778 * memory.
7779 **/
7780static void __devexit ixgbe_remove(struct pci_dev *pdev)
7781{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007782 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7783 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007784
7785 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007786 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007787
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007788#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007789 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7790 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7791 dca_remove_requester(&pdev->dev);
7792 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7793 }
7794
7795#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007796#ifdef IXGBE_FCOE
7797 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7798 ixgbe_cleanup_fcoe(adapter);
7799
7800#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007801
7802 /* remove the added san mac */
7803 ixgbe_del_sanmac_netdev(netdev);
7804
Donald Skidmorec4900be2008-11-20 21:11:42 -08007805 if (netdev->reg_state == NETREG_REGISTERED)
7806 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007807
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007808 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7809 ixgbe_disable_sriov(adapter);
7810
Alexander Duyck7a921c92009-05-06 10:43:28 +00007811 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007812
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007813 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007814
7815 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007816 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007817 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007818
Emil Tantilov849c4542010-06-03 16:53:41 +00007819 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007820
Auke Kok9a799d72007-09-15 14:07:45 -07007821 free_netdev(netdev);
7822
Frans Pop19d5afd2009-10-02 10:04:12 -07007823 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007824
Auke Kok9a799d72007-09-15 14:07:45 -07007825 pci_disable_device(pdev);
7826}
7827
7828/**
7829 * ixgbe_io_error_detected - called when PCI error is detected
7830 * @pdev: Pointer to PCI device
7831 * @state: The current pci connection state
7832 *
7833 * This function is called after a PCI bus error affecting
7834 * this device has been detected.
7835 */
7836static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007837 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007838{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007839 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7840 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007841
7842 netif_device_detach(netdev);
7843
Breno Leitao3044b8d2009-05-06 10:44:26 +00007844 if (state == pci_channel_io_perm_failure)
7845 return PCI_ERS_RESULT_DISCONNECT;
7846
Auke Kok9a799d72007-09-15 14:07:45 -07007847 if (netif_running(netdev))
7848 ixgbe_down(adapter);
7849 pci_disable_device(pdev);
7850
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007851 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007852 return PCI_ERS_RESULT_NEED_RESET;
7853}
7854
7855/**
7856 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7857 * @pdev: Pointer to PCI device
7858 *
7859 * Restart the card from scratch, as if from a cold-boot.
7860 */
7861static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7862{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007863 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007864 pci_ers_result_t result;
7865 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007866
gouji-new9ce77662009-05-06 10:44:45 +00007867 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007868 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007869 result = PCI_ERS_RESULT_DISCONNECT;
7870 } else {
7871 pci_set_master(pdev);
7872 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007873 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007874
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007875 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007876
7877 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007878 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007879 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007880 }
Auke Kok9a799d72007-09-15 14:07:45 -07007881
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007882 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7883 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007884 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7885 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007886 /* non-fatal, continue */
7887 }
Auke Kok9a799d72007-09-15 14:07:45 -07007888
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007889 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007890}
7891
7892/**
7893 * ixgbe_io_resume - called when traffic can start flowing again.
7894 * @pdev: Pointer to PCI device
7895 *
7896 * This callback is called when the error recovery driver tells us that
7897 * its OK to resume normal operation.
7898 */
7899static void ixgbe_io_resume(struct pci_dev *pdev)
7900{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007901 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7902 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007903
7904 if (netif_running(netdev)) {
7905 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007906 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007907 return;
7908 }
7909 }
7910
7911 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007912}
7913
7914static struct pci_error_handlers ixgbe_err_handler = {
7915 .error_detected = ixgbe_io_error_detected,
7916 .slot_reset = ixgbe_io_slot_reset,
7917 .resume = ixgbe_io_resume,
7918};
7919
7920static struct pci_driver ixgbe_driver = {
7921 .name = ixgbe_driver_name,
7922 .id_table = ixgbe_pci_tbl,
7923 .probe = ixgbe_probe,
7924 .remove = __devexit_p(ixgbe_remove),
7925#ifdef CONFIG_PM
7926 .suspend = ixgbe_suspend,
7927 .resume = ixgbe_resume,
7928#endif
7929 .shutdown = ixgbe_shutdown,
7930 .err_handler = &ixgbe_err_handler
7931};
7932
7933/**
7934 * ixgbe_init_module - Driver Registration Routine
7935 *
7936 * ixgbe_init_module is the first routine called when the driver is
7937 * loaded. All it does is register with the PCI subsystem.
7938 **/
7939static int __init ixgbe_init_module(void)
7940{
7941 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007942 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007943 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007944
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007945#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007946 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007947#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007948
Auke Kok9a799d72007-09-15 14:07:45 -07007949 ret = pci_register_driver(&ixgbe_driver);
7950 return ret;
7951}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007952
Auke Kok9a799d72007-09-15 14:07:45 -07007953module_init(ixgbe_init_module);
7954
7955/**
7956 * ixgbe_exit_module - Driver Exit Cleanup Routine
7957 *
7958 * ixgbe_exit_module is called just before the driver is removed
7959 * from memory.
7960 **/
7961static void __exit ixgbe_exit_module(void)
7962{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007963#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007964 dca_unregister_notify(&dca_notifier);
7965#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007966 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007967 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007968}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007969
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007970#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007971static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007972 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007973{
7974 int ret_val;
7975
7976 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007977 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007978
7979 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7980}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007981
Alexander Duyckb4533682009-03-31 21:32:42 +00007982#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007983
Auke Kok9a799d72007-09-15 14:07:45 -07007984module_exit(ixgbe_exit_module);
7985
7986/* ixgbe_main.c */