blob: e5a4eb62b27ce269fe241d5a6b68ef5d0e605e6a [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 Duyck30065e62011-07-15 03:05:14 +0000807 u16 budget = q_vector->tx.work_limit;
Alexander Duyckd3d00232011-07-15 02:31:25 +0000808 u16 i = tx_ring->next_to_clean;
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 Duyck30065e62011-07-15 03:05:14 +0000813 for (; budget; budget--) {
Alexander Duyckd3d00232011-07-15 02:31:25 +0000814 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 */
Alexander Duyck30065e62011-07-15 03:05:14 +0000894 return budget;
Alexander Duyckb9537992010-11-16 19:26:58 -0800895 }
Auke Kok9a799d72007-09-15 14:07:45 -0700896
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800897#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyck30065e62011-07-15 03:05:14 +0000898 if (unlikely(total_packets && 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 Duyck30065e62011-07-15 03:05:14 +0000911 return budget;
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);
David S. Miller823dcd22011-08-20 10:39:12 -07001483 if (!ddp_bytes) {
1484 dev_kfree_skb_any(skb);
Yi Zou332d4a72009-05-13 13:11:53 +00001485 goto next_desc;
David S. Miller823dcd22011-08-20 10:39:12 -07001486 }
Yi Zou3d8fd382009-06-08 14:38:44 +00001487 }
Yi Zou332d4a72009-05-13 13:11:53 +00001488#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001489 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001490
1491next_desc:
1492 rx_desc->wb.upper.status_error = 0;
1493
Alexander Duyckc267fc12010-11-16 19:27:00 -08001494 (*work_done)++;
1495 if (*work_done >= work_to_do)
1496 break;
1497
Auke Kok9a799d72007-09-15 14:07:45 -07001498 /* return some buffers to hardware, one at a time is too slow */
1499 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001500 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001501 cleaned_count = 0;
1502 }
1503
1504 /* use prefetched values */
1505 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001506 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001507 }
1508
Auke Kok9a799d72007-09-15 14:07:45 -07001509 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001510 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001511
1512 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001513 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001514
Yi Zou3d8fd382009-06-08 14:38:44 +00001515#ifdef IXGBE_FCOE
1516 /* include DDPed FCoE data */
1517 if (ddp_bytes > 0) {
1518 unsigned int mss;
1519
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001520 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001521 sizeof(struct fc_frame_header) -
1522 sizeof(struct fcoe_crc_eof);
1523 if (mss > 512)
1524 mss &= ~511;
1525 total_rx_bytes += ddp_bytes;
1526 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1527 }
1528#endif /* IXGBE_FCOE */
1529
Alexander Duyckc267fc12010-11-16 19:27:00 -08001530 u64_stats_update_begin(&rx_ring->syncp);
1531 rx_ring->stats.packets += total_rx_packets;
1532 rx_ring->stats.bytes += total_rx_bytes;
1533 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001534 q_vector->rx.total_packets += total_rx_packets;
1535 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001536}
1537
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001538static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001539/**
1540 * ixgbe_configure_msix - Configure MSI-X hardware
1541 * @adapter: board private structure
1542 *
1543 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1544 * interrupts.
1545 **/
1546static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1547{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001549 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001550 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001551
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001552 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1553
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001554 /*
1555 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556 * corresponding register.
1557 */
1558 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001559 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001560 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001561 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001562 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001563
Alexander Duyck08c88332011-06-11 01:45:03 +00001564 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001565 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1566 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001567 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001568 adapter->num_rx_queues,
1569 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001570 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001571 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001572 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001573
Alexander Duyck08c88332011-06-11 01:45:03 +00001574 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001575 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1576 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001577 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001578 adapter->num_tx_queues,
1579 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001580 }
1581
Alexander Duyck08c88332011-06-11 01:45:03 +00001582 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001583 /* tx only */
1584 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001585 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001586 /* rx or mixed */
1587 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001588
Alexander Duyckfe49f042009-06-04 16:00:09 +00001589 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001590 /* If ATR is enabled, set interrupt affinity */
1591 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001592 /*
1593 * Allocate the affinity_hint cpumask, assign the mask
1594 * for this vector, and set our affinity_hint for
1595 * this irq.
1596 */
1597 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1598 GFP_KERNEL))
1599 return;
1600 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1601 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1602 q_vector->affinity_mask);
1603 }
Auke Kok9a799d72007-09-15 14:07:45 -07001604 }
1605
Alexander Duyckbd508172010-11-16 19:27:03 -08001606 switch (adapter->hw.mac.type) {
1607 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001608 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001609 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001610 break;
1611 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001612 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001613 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001614 break;
1615
1616 default:
1617 break;
1618 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001619 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001620
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001621 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001622 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001623 if (adapter->num_vfs)
1624 mask &= ~(IXGBE_EIMS_OTHER |
1625 IXGBE_EIMS_MAILBOX |
1626 IXGBE_EIMS_LSC);
1627 else
1628 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001629 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001630}
1631
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001632enum latency_range {
1633 lowest_latency = 0,
1634 low_latency = 1,
1635 bulk_latency = 2,
1636 latency_invalid = 255
1637};
1638
1639/**
1640 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001641 * @q_vector: structure containing interrupt and ring information
1642 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001643 *
1644 * Stores a new ITR value based on packets and byte
1645 * counts during the last interrupt. The advantage of per interrupt
1646 * computation is faster updates and more accurate ITR for the current
1647 * traffic pattern. Constants in this function were computed
1648 * based on theoretical maximum wire speed and thresholds were set based
1649 * on testing data as well as attempting to minimize response time
1650 * while increasing bulk throughput.
1651 * this functionality is controlled by the InterruptThrottleRate module
1652 * parameter (see ixgbe_param.c)
1653 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001654static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1655 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001656{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001657 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001658 struct ixgbe_adapter *adapter = q_vector->adapter;
1659 int bytes = ring_container->total_bytes;
1660 int packets = ring_container->total_packets;
1661 u32 timepassed_us;
1662 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001663
1664 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001665 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001666
1667 /* simple throttlerate management
1668 * 0-20MB/s lowest (100000 ints/s)
1669 * 20-100MB/s low (20000 ints/s)
1670 * 100-1249MB/s bulk (8000 ints/s)
1671 */
1672 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001673 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001674 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1675
1676 switch (itr_setting) {
1677 case lowest_latency:
1678 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001679 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001680 break;
1681 case low_latency:
1682 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001683 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001684 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001685 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001686 break;
1687 case bulk_latency:
1688 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001689 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001690 break;
1691 }
1692
Alexander Duyckbd198052011-06-11 01:45:08 +00001693 /* clear work counters since we have the values we need */
1694 ring_container->total_bytes = 0;
1695 ring_container->total_packets = 0;
1696
1697 /* write updated itr to ring container */
1698 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001699}
1700
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001701/**
1702 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001703 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001704 *
1705 * This function is made to be called by ethtool and by the driver
1706 * when it needs to update EITR registers at runtime. Hardware
1707 * specific quirks/differences are taken care of here.
1708 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001709void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001710{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001711 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001712 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001713 int v_idx = q_vector->v_idx;
1714 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1715
Alexander Duyckbd508172010-11-16 19:27:03 -08001716 switch (adapter->hw.mac.type) {
1717 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001718 /* must write high and low 16 bits to reset counter */
1719 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001720 break;
1721 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001722 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001723 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001724 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001725 * max interrupt rate, but there is an errata where it can
1726 * not be zero with RSC
1727 */
1728 if (itr_reg == 8 &&
1729 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1730 itr_reg = 0;
1731
1732 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001733 * set the WDIS bit to not clear the timer bits and cause an
1734 * immediate assertion of the interrupt
1735 */
1736 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001737 break;
1738 default:
1739 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001740 }
1741 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1742}
1743
Alexander Duyckbd198052011-06-11 01:45:08 +00001744static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001745{
Alexander Duyckbd198052011-06-11 01:45:08 +00001746 u32 new_itr = q_vector->eitr;
1747 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001748
Alexander Duyckbd198052011-06-11 01:45:08 +00001749 ixgbe_update_itr(q_vector, &q_vector->tx);
1750 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001751
Alexander Duyck08c88332011-06-11 01:45:03 +00001752 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001753
1754 switch (current_itr) {
1755 /* counts and packets in update_itr are dependent on these numbers */
1756 case lowest_latency:
1757 new_itr = 100000;
1758 break;
1759 case low_latency:
1760 new_itr = 20000; /* aka hwitr = ~200 */
1761 break;
1762 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001763 new_itr = 8000;
1764 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001765 default:
1766 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001767 }
1768
1769 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001770 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001771 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001772
Alexander Duyckbd198052011-06-11 01:45:08 +00001773 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001774 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001775
1776 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001777 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001778}
1779
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001780/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001781 * ixgbe_check_overtemp_subtask - check for over tempurature
1782 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001783 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001784static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001785{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001786 struct ixgbe_hw *hw = &adapter->hw;
1787 u32 eicr = adapter->interrupt_event;
1788
Alexander Duyckf0f97782011-04-22 04:08:09 +00001789 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001790 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001791
Alexander Duyckf0f97782011-04-22 04:08:09 +00001792 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1793 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1794 return;
1795
1796 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1797
Joe Perches7ca647b2010-09-07 21:35:40 +00001798 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001799 case IXGBE_DEV_ID_82599_T3_LOM:
1800 /*
1801 * Since the warning interrupt is for both ports
1802 * we don't have to check if:
1803 * - This interrupt wasn't for our port.
1804 * - We may have missed the interrupt so always have to
1805 * check if we got a LSC
1806 */
1807 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1808 !(eicr & IXGBE_EICR_LSC))
1809 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001810
Alexander Duyckf0f97782011-04-22 04:08:09 +00001811 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1812 u32 autoneg;
1813 bool link_up = false;
1814
Joe Perches7ca647b2010-09-07 21:35:40 +00001815 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1816
Alexander Duyckf0f97782011-04-22 04:08:09 +00001817 if (link_up)
1818 return;
1819 }
1820
1821 /* Check if this is not due to overtemp */
1822 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1823 return;
1824
1825 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001826 default:
1827 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1828 return;
1829 break;
1830 }
1831 e_crit(drv,
1832 "Network adapter has been stopped because it has over heated. "
1833 "Restart the computer. If the problem persists, "
1834 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001835
1836 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001837}
1838
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001839static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1840{
1841 struct ixgbe_hw *hw = &adapter->hw;
1842
1843 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1844 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001845 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001846 /* write to clear the interrupt */
1847 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1848 }
1849}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001850
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001851static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1852{
1853 struct ixgbe_hw *hw = &adapter->hw;
1854
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001855 if (eicr & IXGBE_EICR_GPI_SDP2) {
1856 /* Clear the interrupt */
1857 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001858 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1859 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1860 ixgbe_service_event_schedule(adapter);
1861 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001862 }
1863
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001864 if (eicr & IXGBE_EICR_GPI_SDP1) {
1865 /* Clear the interrupt */
1866 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001867 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1868 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1869 ixgbe_service_event_schedule(adapter);
1870 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001871 }
1872}
1873
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001874static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1875{
1876 struct ixgbe_hw *hw = &adapter->hw;
1877
1878 adapter->lsc_int++;
1879 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1880 adapter->link_check_timeout = jiffies;
1881 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1882 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001883 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001884 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001885 }
1886}
1887
Auke Kok9a799d72007-09-15 14:07:45 -07001888static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1889{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001890 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001891 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001892 u32 eicr;
1893
1894 /*
1895 * Workaround for Silicon errata. Use clear-by-write instead
1896 * of clear-by-read. Reading with EICS will return the
1897 * interrupt causes without clearing, which later be done
1898 * with the write to EICR.
1899 */
1900 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1901 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001902
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001903 if (eicr & IXGBE_EICR_LSC)
1904 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001905
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001906 if (eicr & IXGBE_EICR_MAILBOX)
1907 ixgbe_msg_task(adapter);
1908
Alexander Duyckbd508172010-11-16 19:27:03 -08001909 switch (hw->mac.type) {
1910 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001911 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001912 /* Handle Flow Director Full threshold interrupt */
1913 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001914 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001915 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001916 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001917 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001918 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001919 &ring->state))
1920 reinit_count++;
1921 }
1922 if (reinit_count) {
1923 /* no more flow director interrupts until after init */
1924 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1925 eicr &= ~IXGBE_EICR_FLOW_DIR;
1926 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1927 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001928 }
1929 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001930 ixgbe_check_sfp_event(adapter, eicr);
1931 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1932 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1933 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1934 adapter->interrupt_event = eicr;
1935 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1936 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001937 }
1938 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001939 break;
1940 default:
1941 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001942 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001943
1944 ixgbe_check_fan_failure(adapter, eicr);
1945
Alexander Duyck70864002011-04-27 09:13:56 +00001946 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001947 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001948 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1949 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001950
1951 return IRQ_HANDLED;
1952}
1953
Alexander Duyckfe49f042009-06-04 16:00:09 +00001954static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1955 u64 qmask)
1956{
1957 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001958 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001959
Alexander Duyckbd508172010-11-16 19:27:03 -08001960 switch (hw->mac.type) {
1961 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001962 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001963 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1964 break;
1965 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001966 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001967 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001968 if (mask)
1969 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001970 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001971 if (mask)
1972 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1973 break;
1974 default:
1975 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001976 }
1977 /* skip the flush */
1978}
1979
1980static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001981 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001982{
1983 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001984 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001985
Alexander Duyckbd508172010-11-16 19:27:03 -08001986 switch (hw->mac.type) {
1987 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001988 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001989 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1990 break;
1991 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001992 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001993 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001994 if (mask)
1995 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001996 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001997 if (mask)
1998 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1999 break;
2000 default:
2001 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002002 }
2003 /* skip the flush */
2004}
2005
Auke Kok9a799d72007-09-15 14:07:45 -07002006static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2007{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002008 struct ixgbe_q_vector *q_vector = data;
2009 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002010 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002011 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002012
Alexander Duyck08c88332011-06-11 01:45:03 +00002013 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002014 return IRQ_HANDLED;
2015
Alexander Duyck08c88332011-06-11 01:45:03 +00002016 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2017 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002018 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002019 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002020 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002021 }
2022
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002023 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002024 napi_schedule(&q_vector->napi);
2025
Auke Kok9a799d72007-09-15 14:07:45 -07002026 return IRQ_HANDLED;
2027}
2028
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002029/**
2030 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2031 * @irq: unused
2032 * @data: pointer to our q_vector struct for this interrupt vector
2033 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002034static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2035{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002036 struct ixgbe_q_vector *q_vector = data;
2037 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002038 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002039 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002040 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002041
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002042#ifdef CONFIG_IXGBE_DCA
2043 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2044 ixgbe_update_dca(q_vector);
2045#endif
2046
Alexander Duyck08c88332011-06-11 01:45:03 +00002047 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2048 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002049 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002050 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002051 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002052 }
2053
Alexander Duyck08c88332011-06-11 01:45:03 +00002054 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002055 return IRQ_HANDLED;
2056
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002057 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002058 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002059
Auke Kok9a799d72007-09-15 14:07:45 -07002060 return IRQ_HANDLED;
2061}
2062
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2064{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002065 struct ixgbe_q_vector *q_vector = data;
2066 struct ixgbe_adapter *adapter = q_vector->adapter;
2067 struct ixgbe_ring *ring;
2068 int r_idx;
2069 int i;
2070
Alexander Duyck08c88332011-06-11 01:45:03 +00002071 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002072 return IRQ_HANDLED;
2073
Alexander Duyck08c88332011-06-11 01:45:03 +00002074 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2075 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002076 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002077 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002078 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002079 }
2080
Alexander Duyck08c88332011-06-11 01:45:03 +00002081 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2082 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002083 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002084 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002085 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002086 }
2087
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002088 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002089 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002090
2091 return IRQ_HANDLED;
2092}
2093
2094/**
2095 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2096 * @napi: napi struct with our devices info in it
2097 * @budget: amount of work driver is allowed to do this pass, in packets
2098 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002099 * This function is optimized for cleaning one queue only on a single
2100 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002101 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002102static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2103{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002104 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002105 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002106 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002107 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002108 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002109 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002110
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002111#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002112 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002113 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002114#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002115
Alexander Duyck08c88332011-06-11 01:45:03 +00002116 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002117 rx_ring = adapter->rx_ring[r_idx];
2118
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002119 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002121 /* If all Rx work done, exit the polling mode */
2122 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002123 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002124 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002125 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002126 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002127 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002128 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002129 }
2130
2131 return work_done;
2132}
2133
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002134/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002135 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002136 * @napi: napi struct with our devices info in it
2137 * @budget: amount of work driver is allowed to do this pass, in packets
2138 *
2139 * This function will clean more than one rx queue associated with a
2140 * q_vector.
2141 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002142static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002143{
2144 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002145 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002146 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002147 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002148 int work_done = 0, i;
2149 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002150 bool tx_clean_complete = true;
2151
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002152#ifdef CONFIG_IXGBE_DCA
2153 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2154 ixgbe_update_dca(q_vector);
2155#endif
2156
Alexander Duyck08c88332011-06-11 01:45:03 +00002157 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2158 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002159 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002160 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002161 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002162 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002163 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002164
2165 /* attempt to distribute budget to each queue fairly, but don't allow
2166 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002167 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002168 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002169 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2170 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002171 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002172 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002173 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002174 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002175 }
2176
Alexander Duyck08c88332011-06-11 01:45:03 +00002177 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002178 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002179 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002180 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002181 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002182 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002183 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002184 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002185 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002186 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002187 return 0;
2188 }
2189
2190 return work_done;
2191}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002192
2193/**
2194 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2195 * @napi: napi struct with our devices info in it
2196 * @budget: amount of work driver is allowed to do this pass, in packets
2197 *
2198 * This function is optimized for cleaning one queue only on a single
2199 * q_vector!!!
2200 **/
2201static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2202{
2203 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002204 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002205 struct ixgbe_adapter *adapter = q_vector->adapter;
2206 struct ixgbe_ring *tx_ring = NULL;
2207 int work_done = 0;
2208 long r_idx;
2209
Alexander Duyck91281fd2009-06-04 16:00:27 +00002210#ifdef CONFIG_IXGBE_DCA
2211 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002212 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002213#endif
2214
Alexander Duyck08c88332011-06-11 01:45:03 +00002215 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002216 tx_ring = adapter->tx_ring[r_idx];
2217
Alexander Duyck91281fd2009-06-04 16:00:27 +00002218 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2219 work_done = budget;
2220
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002221 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002222 if (work_done < budget) {
2223 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002224 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002225 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002226 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002227 ixgbe_irq_enable_queues(adapter,
2228 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002229 }
2230
2231 return work_done;
2232}
2233
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002234static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002235 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002236{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002237 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002238 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002239
Alexander Duyck08c88332011-06-11 01:45:03 +00002240 set_bit(r_idx, q_vector->rx.idx);
2241 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002242 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002243}
Auke Kok9a799d72007-09-15 14:07:45 -07002244
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002246 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002248 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002249 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002250
Alexander Duyck08c88332011-06-11 01:45:03 +00002251 set_bit(t_idx, q_vector->tx.idx);
2252 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002253 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002254 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002255}
Auke Kok9a799d72007-09-15 14:07:45 -07002256
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002257/**
2258 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2259 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002260 *
2261 * This function maps descriptor rings to the queue-specific vectors
2262 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2263 * one vector per ring/queue, but on a constrained vector budget, we
2264 * group the rings as "efficiently" as possible. You would add new
2265 * mapping configurations in here.
2266 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002267static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002268{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002269 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002270 int v_start = 0;
2271 int rxr_idx = 0, txr_idx = 0;
2272 int rxr_remaining = adapter->num_rx_queues;
2273 int txr_remaining = adapter->num_tx_queues;
2274 int i, j;
2275 int rqpv, tqpv;
2276 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002277
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002278 /* No mapping required if MSI-X is disabled. */
2279 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002280 goto out;
2281
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002282 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2283
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002284 /*
2285 * The ideal configuration...
2286 * We have enough vectors to map one per queue.
2287 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002288 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2290 map_vector_to_rxq(adapter, v_start, rxr_idx);
2291
2292 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2293 map_vector_to_txq(adapter, v_start, txr_idx);
2294
2295 goto out;
2296 }
2297
2298 /*
2299 * If we don't have enough vectors for a 1-to-1
2300 * mapping, we'll have to group them so there are
2301 * multiple queues per vector.
2302 */
2303 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002304 for (i = v_start; i < q_vectors; i++) {
2305 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002306 for (j = 0; j < rqpv; j++) {
2307 map_vector_to_rxq(adapter, i, rxr_idx);
2308 rxr_idx++;
2309 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002310 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002311 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312 for (j = 0; j < tqpv; j++) {
2313 map_vector_to_txq(adapter, i, txr_idx);
2314 txr_idx++;
2315 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002316 }
Auke Kok9a799d72007-09-15 14:07:45 -07002317 }
Auke Kok9a799d72007-09-15 14:07:45 -07002318out:
Auke Kok9a799d72007-09-15 14:07:45 -07002319 return err;
2320}
2321
2322/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2324 * @adapter: board private structure
2325 *
2326 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2327 * interrupts from the kernel.
2328 **/
2329static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2330{
2331 struct net_device *netdev = adapter->netdev;
2332 irqreturn_t (*handler)(int, void *);
2333 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002334 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002335
2336 /* Decrement for Other and TCP Timer vectors */
2337 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2338
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002339 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002340 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002341 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342
Alexander Duyck08c88332011-06-11 01:45:03 +00002343#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002344 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002345 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2346 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002347 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002349 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2350 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002351
Joe Perchese8e9f692010-09-07 21:34:53 +00002352 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002353 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2354 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002355 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002356 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2357 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002358 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002359 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2360 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002361 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002362 } else {
2363 /* skip this unused q_vector */
2364 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002365 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002366 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002367 handler, 0, q_vector->name,
2368 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002370 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002371 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002372 goto free_queue_irqs;
2373 }
2374 }
2375
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002376 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002377 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002378 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002379 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002380 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002381 goto free_queue_irqs;
2382 }
2383
2384 return 0;
2385
2386free_queue_irqs:
2387 for (i = vector - 1; i >= 0; i--)
2388 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002389 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002390 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2391 pci_disable_msix(adapter->pdev);
2392 kfree(adapter->msix_entries);
2393 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002394 return err;
2395}
2396
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002397/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002398 * ixgbe_irq_enable - Enable default interrupt generation settings
2399 * @adapter: board private structure
2400 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002401static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2402 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002403{
2404 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002405
2406 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002407 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2408 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002409 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2410 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002411 switch (adapter->hw.mac.type) {
2412 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002413 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002414 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002415 mask |= IXGBE_EIMS_GPI_SDP1;
2416 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002417 if (adapter->num_vfs)
2418 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002419 break;
2420 default:
2421 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002422 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002423 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002424 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002425
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002426 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002427 if (queues)
2428 ixgbe_irq_enable_queues(adapter, ~0);
2429 if (flush)
2430 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002431
2432 if (adapter->num_vfs > 32) {
2433 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2434 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2435 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002436}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002437
2438/**
2439 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002440 * @irq: interrupt number
2441 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002442 **/
2443static irqreturn_t ixgbe_intr(int irq, void *data)
2444{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002445 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002446 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002447 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002448 u32 eicr;
2449
Don Skidmore54037502009-02-21 15:42:56 -08002450 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002451 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002452 * before the read of EICR.
2453 */
2454 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002456 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2457 * therefore no explict interrupt disable is necessary */
2458 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002459 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002460 /*
2461 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002462 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002463 * have disabled interrupts due to EIAM
2464 * finish the workaround of silicon errata on 82598. Unmask
2465 * the interrupt that we masked before the EICR read.
2466 */
2467 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2468 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002469 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002470 }
Auke Kok9a799d72007-09-15 14:07:45 -07002471
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002472 if (eicr & IXGBE_EICR_LSC)
2473 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002474
Alexander Duyckbd508172010-11-16 19:27:03 -08002475 switch (hw->mac.type) {
2476 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002477 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002478 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2479 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002480 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2481 adapter->interrupt_event = eicr;
2482 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2483 ixgbe_service_event_schedule(adapter);
2484 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002485 }
2486 break;
2487 default:
2488 break;
2489 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002490
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002491 ixgbe_check_fan_failure(adapter, eicr);
2492
Alexander Duyck7a921c92009-05-06 10:43:28 +00002493 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002494 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002495 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002496 }
2497
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002498 /*
2499 * re-enable link(maybe) and non-queue interrupts, no flush.
2500 * ixgbe_poll will re-enable the queue interrupts
2501 */
2502
2503 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2504 ixgbe_irq_enable(adapter, false, false);
2505
Auke Kok9a799d72007-09-15 14:07:45 -07002506 return IRQ_HANDLED;
2507}
2508
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002509static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2510{
2511 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2512
2513 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002514 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002515 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2516 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2517 q_vector->rx.count = 0;
2518 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002519 }
2520}
2521
Auke Kok9a799d72007-09-15 14:07:45 -07002522/**
2523 * ixgbe_request_irq - initialize interrupts
2524 * @adapter: board private structure
2525 *
2526 * Attempts to configure interrupts using the best available
2527 * capabilities of the hardware and kernel.
2528 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002530{
2531 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002532 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002533
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002534 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2535 err = ixgbe_request_msix_irqs(adapter);
2536 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002537 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002538 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002539 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002540 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002541 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002542 }
2543
Auke Kok9a799d72007-09-15 14:07:45 -07002544 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002545 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002546
Auke Kok9a799d72007-09-15 14:07:45 -07002547 return err;
2548}
2549
2550static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2551{
Auke Kok9a799d72007-09-15 14:07:45 -07002552 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002553 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002554
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002555 q_vectors = adapter->num_msix_vectors;
2556
2557 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002558 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002560 i--;
2561 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002562 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002563 if (!adapter->q_vector[i]->rx.count &&
2564 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002565 continue;
2566
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002567 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002568 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002569 }
2570
2571 ixgbe_reset_q_vectors(adapter);
2572 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002573 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002574 }
2575}
2576
2577/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002578 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2579 * @adapter: board private structure
2580 **/
2581static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2582{
Alexander Duyckbd508172010-11-16 19:27:03 -08002583 switch (adapter->hw.mac.type) {
2584 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002586 break;
2587 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002588 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002589 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2590 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002591 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002592 if (adapter->num_vfs > 32)
2593 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002594 break;
2595 default:
2596 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002597 }
2598 IXGBE_WRITE_FLUSH(&adapter->hw);
2599 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2600 int i;
2601 for (i = 0; i < adapter->num_msix_vectors; i++)
2602 synchronize_irq(adapter->msix_entries[i].vector);
2603 } else {
2604 synchronize_irq(adapter->pdev->irq);
2605 }
2606}
2607
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002608/**
Auke Kok9a799d72007-09-15 14:07:45 -07002609 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2610 *
2611 **/
2612static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2613{
Auke Kok9a799d72007-09-15 14:07:45 -07002614 struct ixgbe_hw *hw = &adapter->hw;
2615
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002617 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002618
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002619 ixgbe_set_ivar(adapter, 0, 0, 0);
2620 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002621
2622 map_vector_to_rxq(adapter, 0, 0);
2623 map_vector_to_txq(adapter, 0, 0);
2624
Emil Tantilov396e7992010-07-01 20:05:12 +00002625 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002626}
2627
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002628/**
2629 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2630 * @adapter: board private structure
2631 * @ring: structure containing ring specific data
2632 *
2633 * Configure the Tx descriptor ring after a reset.
2634 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002635void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2636 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002637{
2638 struct ixgbe_hw *hw = &adapter->hw;
2639 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002640 int wait_loop = 10;
2641 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002642 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002643
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002644 /* disable queue to avoid issues while updating state */
2645 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2646 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2647 txdctl & ~IXGBE_TXDCTL_ENABLE);
2648 IXGBE_WRITE_FLUSH(hw);
2649
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002650 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002651 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002652 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2653 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2654 ring->count * sizeof(union ixgbe_adv_tx_desc));
2655 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2656 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002657 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002658
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002659 /* configure fetching thresholds */
2660 if (adapter->rx_itr_setting == 0) {
2661 /* cannot set wthresh when itr==0 */
2662 txdctl &= ~0x007F0000;
2663 } else {
2664 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2665 txdctl |= (8 << 16);
2666 }
2667 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2668 /* PThresh workaround for Tx hang with DFP enabled. */
2669 txdctl |= 32;
2670 }
2671
2672 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002673 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2674 adapter->atr_sample_rate) {
2675 ring->atr_sample_rate = adapter->atr_sample_rate;
2676 ring->atr_count = 0;
2677 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2678 } else {
2679 ring->atr_sample_rate = 0;
2680 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002681
John Fastabendc84d3242010-11-16 19:27:12 -08002682 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2683
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002684 /* enable queue */
2685 txdctl |= IXGBE_TXDCTL_ENABLE;
2686 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2687
2688 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2689 if (hw->mac.type == ixgbe_mac_82598EB &&
2690 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2691 return;
2692
2693 /* poll to verify queue is enabled */
2694 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002695 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002696 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2697 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2698 if (!wait_loop)
2699 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002700}
2701
Alexander Duyck120ff942010-08-19 13:34:50 +00002702static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2703{
2704 struct ixgbe_hw *hw = &adapter->hw;
2705 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002706 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002707 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002708
2709 if (hw->mac.type == ixgbe_mac_82598EB)
2710 return;
2711
2712 /* disable the arbiter while setting MTQC */
2713 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2714 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2715 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2716
2717 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002718 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002719 case (IXGBE_FLAG_SRIOV_ENABLED):
2720 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2721 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2722 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002723 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002724 if (!tcs)
2725 reg = IXGBE_MTQC_64Q_1PB;
2726 else if (tcs <= 4)
2727 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2728 else
2729 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2730
2731 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2732
2733 /* Enable Security TX Buffer IFG for multiple pb */
2734 if (tcs) {
2735 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2736 reg |= IXGBE_SECTX_DCB;
2737 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2738 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002739 break;
2740 }
2741
2742 /* re-enable the arbiter */
2743 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2744 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2745}
2746
Auke Kok9a799d72007-09-15 14:07:45 -07002747/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002748 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002749 * @adapter: board private structure
2750 *
2751 * Configure the Tx unit of the MAC after a reset.
2752 **/
2753static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2754{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002755 struct ixgbe_hw *hw = &adapter->hw;
2756 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002757 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002758
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002759 ixgbe_setup_mtqc(adapter);
2760
2761 if (hw->mac.type != ixgbe_mac_82598EB) {
2762 /* DMATXCTL.EN must be before Tx queues are enabled */
2763 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2764 dmatxctl |= IXGBE_DMATXCTL_TE;
2765 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2766 }
2767
Auke Kok9a799d72007-09-15 14:07:45 -07002768 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002769 for (i = 0; i < adapter->num_tx_queues; i++)
2770 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002771}
2772
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002773#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002774
Yi Zoua6616b42009-08-06 13:05:23 +00002775static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002776 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002777{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002778 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002779 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002780
Alexander Duyckbd508172010-11-16 19:27:03 -08002781 switch (adapter->hw.mac.type) {
2782 case ixgbe_mac_82598EB: {
2783 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2784 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002785 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002786 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002787 break;
2788 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002789 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002790 default:
2791 break;
2792 }
2793
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002794 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002795
2796 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2797 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002798 if (adapter->num_vfs)
2799 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002800
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002801 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2802 IXGBE_SRRCTL_BSIZEHDR_MASK;
2803
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002804 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002805#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2806 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2807#else
2808 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2809#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002810 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002811 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002812 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2813 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002814 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002815 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002816
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002817 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002818}
2819
Alexander Duyck05abb122010-08-19 13:35:41 +00002820static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002821{
Alexander Duyck05abb122010-08-19 13:35:41 +00002822 struct ixgbe_hw *hw = &adapter->hw;
2823 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002824 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2825 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002826 u32 mrqc = 0, reta = 0;
2827 u32 rxcsum;
2828 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002829 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002830 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2831
2832 if (tcs)
2833 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002834
Alexander Duyck05abb122010-08-19 13:35:41 +00002835 /* Fill out hash function seeds */
2836 for (i = 0; i < 10; i++)
2837 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002838
Alexander Duyck05abb122010-08-19 13:35:41 +00002839 /* Fill out redirection table */
2840 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002841 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002842 j = 0;
2843 /* reta = 4-byte sliding window of
2844 * 0x00..(indices-1)(indices-1)00..etc. */
2845 reta = (reta << 8) | (j * 0x11);
2846 if ((i & 3) == 3)
2847 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2848 }
2849
2850 /* Disable indicating checksum in descriptor, enables RSS hash */
2851 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2852 rxcsum |= IXGBE_RXCSUM_PCSD;
2853 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2854
John Fastabend8b1c0b22011-05-03 02:26:48 +00002855 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2856 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002857 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002858 } else {
2859 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2860 | IXGBE_FLAG_SRIOV_ENABLED);
2861
2862 switch (mask) {
2863 case (IXGBE_FLAG_RSS_ENABLED):
2864 if (!tcs)
2865 mrqc = IXGBE_MRQC_RSSEN;
2866 else if (tcs <= 4)
2867 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2868 else
2869 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2870 break;
2871 case (IXGBE_FLAG_SRIOV_ENABLED):
2872 mrqc = IXGBE_MRQC_VMDQEN;
2873 break;
2874 default:
2875 break;
2876 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002877 }
2878
Alexander Duyck05abb122010-08-19 13:35:41 +00002879 /* Perform hash on these packet types */
2880 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2881 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2882 | IXGBE_MRQC_RSS_FIELD_IPV6
2883 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2884
2885 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002886}
2887
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002888/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002889 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2890 * @adapter: address of board private structure
2891 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002892 **/
Don Skidmore082757a2011-07-21 05:55:00 +00002893static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002894 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002895{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002896 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002897 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002898 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002899 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002900
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002901 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002902 return;
2903
2904 rx_buf_len = ring->rx_buf_len;
2905 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002906 rscctrl |= IXGBE_RSCCTL_RSCEN;
2907 /*
2908 * we must limit the number of descriptors so that the
2909 * total size of max desc * buf_len is not greater
2910 * than 65535
2911 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002912 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002913#if (MAX_SKB_FRAGS > 16)
2914 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2915#elif (MAX_SKB_FRAGS > 8)
2916 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2917#elif (MAX_SKB_FRAGS > 4)
2918 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2919#else
2920 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2921#endif
2922 } else {
2923 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2924 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2925 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2926 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2927 else
2928 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2929 }
Alexander Duyck73670962010-08-19 13:38:34 +00002930 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002931}
2932
Alexander Duyck9e10e042010-08-19 13:40:06 +00002933/**
2934 * ixgbe_set_uta - Set unicast filter table address
2935 * @adapter: board private structure
2936 *
2937 * The unicast table address is a register array of 32-bit registers.
2938 * The table is meant to be used in a way similar to how the MTA is used
2939 * however due to certain limitations in the hardware it is necessary to
2940 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2941 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2942 **/
2943static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2944{
2945 struct ixgbe_hw *hw = &adapter->hw;
2946 int i;
2947
2948 /* The UTA table only exists on 82599 hardware and newer */
2949 if (hw->mac.type < ixgbe_mac_82599EB)
2950 return;
2951
2952 /* we only need to do this if VMDq is enabled */
2953 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2954 return;
2955
2956 for (i = 0; i < 128; i++)
2957 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2958}
2959
2960#define IXGBE_MAX_RX_DESC_POLL 10
2961static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2962 struct ixgbe_ring *ring)
2963{
2964 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002965 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2966 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002967 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002968
2969 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2970 if (hw->mac.type == ixgbe_mac_82598EB &&
2971 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2972 return;
2973
2974 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002975 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002976 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2977 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2978
2979 if (!wait_loop) {
2980 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2981 "the polling period\n", reg_idx);
2982 }
2983}
2984
Yi Zou2d39d572011-01-06 14:29:56 +00002985void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2986 struct ixgbe_ring *ring)
2987{
2988 struct ixgbe_hw *hw = &adapter->hw;
2989 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2990 u32 rxdctl;
2991 u8 reg_idx = ring->reg_idx;
2992
2993 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2994 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2995
2996 /* write value back with RXDCTL.ENABLE bit cleared */
2997 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2998
2999 if (hw->mac.type == ixgbe_mac_82598EB &&
3000 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3001 return;
3002
3003 /* the hardware may take up to 100us to really disable the rx queue */
3004 do {
3005 udelay(10);
3006 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3007 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3008
3009 if (!wait_loop) {
3010 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3011 "the polling period\n", reg_idx);
3012 }
3013}
3014
Alexander Duyck84418e32010-08-19 13:40:54 +00003015void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3016 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003017{
3018 struct ixgbe_hw *hw = &adapter->hw;
3019 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003020 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003021 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003022
Alexander Duyck9e10e042010-08-19 13:40:06 +00003023 /* disable queue to avoid issues while updating state */
3024 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003025 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003026
Alexander Duyckacd37172010-08-19 13:36:05 +00003027 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3028 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3029 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3030 ring->count * sizeof(union ixgbe_adv_rx_desc));
3031 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3032 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003033 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003034
3035 ixgbe_configure_srrctl(adapter, ring);
3036 ixgbe_configure_rscctl(adapter, ring);
3037
Greg Rosee9f98072011-01-26 01:06:07 +00003038 /* If operating in IOV mode set RLPML for X540 */
3039 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3040 hw->mac.type == ixgbe_mac_X540) {
3041 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3042 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3043 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3044 }
3045
Alexander Duyck9e10e042010-08-19 13:40:06 +00003046 if (hw->mac.type == ixgbe_mac_82598EB) {
3047 /*
3048 * enable cache line friendly hardware writes:
3049 * PTHRESH=32 descriptors (half the internal cache),
3050 * this also removes ugly rx_no_buffer_count increment
3051 * HTHRESH=4 descriptors (to minimize latency on fetch)
3052 * WTHRESH=8 burst writeback up to two cache lines
3053 */
3054 rxdctl &= ~0x3FFFFF;
3055 rxdctl |= 0x080420;
3056 }
3057
3058 /* enable receive descriptor ring */
3059 rxdctl |= IXGBE_RXDCTL_ENABLE;
3060 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3061
3062 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003063 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003064}
3065
Alexander Duyck48654522010-08-19 13:36:27 +00003066static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3067{
3068 struct ixgbe_hw *hw = &adapter->hw;
3069 int p;
3070
3071 /* PSRTYPE must be initialized in non 82598 adapters */
3072 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003073 IXGBE_PSRTYPE_UDPHDR |
3074 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003075 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003076 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003077
3078 if (hw->mac.type == ixgbe_mac_82598EB)
3079 return;
3080
3081 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3082 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3083
3084 for (p = 0; p < adapter->num_rx_pools; p++)
3085 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3086 psrtype);
3087}
3088
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003089static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3090{
3091 struct ixgbe_hw *hw = &adapter->hw;
3092 u32 gcr_ext;
3093 u32 vt_reg_bits;
3094 u32 reg_offset, vf_shift;
3095 u32 vmdctl;
3096
3097 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3098 return;
3099
3100 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3101 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3102 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3103 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3104
3105 vf_shift = adapter->num_vfs % 32;
3106 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3107
3108 /* Enable only the PF's pool for Tx/Rx */
3109 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3110 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3111 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3112 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3113 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3114
3115 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3116 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3117
3118 /*
3119 * Set up VF register offsets for selected VT Mode,
3120 * i.e. 32 or 64 VFs for SR-IOV
3121 */
3122 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3123 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3124 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3125 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3126
3127 /* enable Tx loopback for VF/PF communication */
3128 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003129 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003130 hw->mac.ops.set_mac_anti_spoofing(hw,
3131 (adapter->antispoofing_enabled =
3132 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003133 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003134}
3135
Alexander Duyck477de6e2010-08-19 13:38:11 +00003136static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003137{
Auke Kok9a799d72007-09-15 14:07:45 -07003138 struct ixgbe_hw *hw = &adapter->hw;
3139 struct net_device *netdev = adapter->netdev;
3140 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003141 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003142 struct ixgbe_ring *rx_ring;
3143 int i;
3144 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003145
Auke Kok9a799d72007-09-15 14:07:45 -07003146 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003147 /* On by default */
3148 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3149
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003150 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003151 if (adapter->num_vfs)
3152 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3153
3154 /* Disable packet split due to 82599 erratum #45 */
3155 if (hw->mac.type == ixgbe_mac_82599EB)
3156 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003157
3158 /* Set the RX buffer length according to the mode */
3159 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003160 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003161 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003162 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003163 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003164 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003165 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003166 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3167 }
3168
3169#ifdef IXGBE_FCOE
3170 /* adjust max frame to be able to do baby jumbo for FCoE */
3171 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3172 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3173 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3174
3175#endif /* IXGBE_FCOE */
3176 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3177 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3178 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3179 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3180
3181 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003182 }
3183
Auke Kok9a799d72007-09-15 14:07:45 -07003184 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003185 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3186 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003187 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3188
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003189 /*
3190 * Setup the HW Rx Head and Tail Descriptor Pointers and
3191 * the Base and Length of the Rx Descriptor Ring
3192 */
Auke Kok9a799d72007-09-15 14:07:45 -07003193 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003194 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003195 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003196
Yi Zou6e455b892009-08-06 13:05:44 +00003197 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003198 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003199 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003200 clear_ring_ps_enabled(rx_ring);
3201
3202 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3203 set_ring_rsc_enabled(rx_ring);
3204 else
3205 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003206
Yi Zou63f39bd2009-05-17 12:34:35 +00003207#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003208 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003209 struct ixgbe_ring_feature *f;
3210 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003211 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003212 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003213 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3214 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003215 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003216 } else if (!ring_is_rsc_enabled(rx_ring) &&
3217 !ring_is_ps_enabled(rx_ring)) {
3218 rx_ring->rx_buf_len =
3219 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003220 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003221 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003222#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003223 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003224}
3225
Alexander Duyck73670962010-08-19 13:38:34 +00003226static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3227{
3228 struct ixgbe_hw *hw = &adapter->hw;
3229 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3230
3231 switch (hw->mac.type) {
3232 case ixgbe_mac_82598EB:
3233 /*
3234 * For VMDq support of different descriptor types or
3235 * buffer sizes through the use of multiple SRRCTL
3236 * registers, RDRXCTL.MVMEN must be set to 1
3237 *
3238 * also, the manual doesn't mention it clearly but DCA hints
3239 * will only use queue 0's tags unless this bit is set. Side
3240 * effects of setting this bit are only that SRRCTL must be
3241 * fully programmed [0..15]
3242 */
3243 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3244 break;
3245 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003246 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003247 /* Disable RSC for ACK packets */
3248 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3249 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3250 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3251 /* hardware requires some bits to be set by default */
3252 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3253 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3254 break;
3255 default:
3256 /* We should do nothing since we don't know this hardware */
3257 return;
3258 }
3259
3260 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3261}
3262
Alexander Duyck477de6e2010-08-19 13:38:11 +00003263/**
3264 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3265 * @adapter: board private structure
3266 *
3267 * Configure the Rx unit of the MAC after a reset.
3268 **/
3269static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3270{
3271 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003272 int i;
3273 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003274
3275 /* disable receives while setting up the descriptors */
3276 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3277 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3278
3279 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003280 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003281
Alexander Duyck9e10e042010-08-19 13:40:06 +00003282 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003283 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003284
Alexander Duyck9e10e042010-08-19 13:40:06 +00003285 ixgbe_set_uta(adapter);
3286
Alexander Duyck477de6e2010-08-19 13:38:11 +00003287 /* set_rx_buffer_len must be called before ring initialization */
3288 ixgbe_set_rx_buffer_len(adapter);
3289
3290 /*
3291 * Setup the HW Rx Head and Tail Descriptor Pointers and
3292 * the Base and Length of the Rx Descriptor Ring
3293 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003294 for (i = 0; i < adapter->num_rx_queues; i++)
3295 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003296
Alexander Duyck9e10e042010-08-19 13:40:06 +00003297 /* disable drop enable for 82598 parts */
3298 if (hw->mac.type == ixgbe_mac_82598EB)
3299 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3300
3301 /* enable all receives */
3302 rxctrl |= IXGBE_RXCTRL_RXEN;
3303 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003304}
3305
Auke Kok9a799d72007-09-15 14:07:45 -07003306static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3307{
3308 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003309 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003310 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003311
3312 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003313 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003314 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003315}
3316
3317static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3318{
3319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003320 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003321 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003322
Auke Kok9a799d72007-09-15 14:07:45 -07003323 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003324 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003325 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003326}
3327
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003328/**
3329 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3330 * @adapter: driver data
3331 */
3332static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3333{
3334 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003335 u32 vlnctrl;
3336
3337 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3338 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3339 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3340}
3341
3342/**
3343 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3344 * @adapter: driver data
3345 */
3346static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3347{
3348 struct ixgbe_hw *hw = &adapter->hw;
3349 u32 vlnctrl;
3350
3351 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3352 vlnctrl |= IXGBE_VLNCTRL_VFE;
3353 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3354 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3355}
3356
3357/**
3358 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3359 * @adapter: driver data
3360 */
3361static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3362{
3363 struct ixgbe_hw *hw = &adapter->hw;
3364 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003365 int i, j;
3366
3367 switch (hw->mac.type) {
3368 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003369 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3370 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003371 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3372 break;
3373 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003374 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003375 for (i = 0; i < adapter->num_rx_queues; i++) {
3376 j = adapter->rx_ring[i]->reg_idx;
3377 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3378 vlnctrl &= ~IXGBE_RXDCTL_VME;
3379 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3380 }
3381 break;
3382 default:
3383 break;
3384 }
3385}
3386
3387/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003388 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003389 * @adapter: driver data
3390 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003391static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003392{
3393 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003394 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003395 int i, j;
3396
3397 switch (hw->mac.type) {
3398 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003399 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3400 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003401 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3402 break;
3403 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003404 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003405 for (i = 0; i < adapter->num_rx_queues; i++) {
3406 j = adapter->rx_ring[i]->reg_idx;
3407 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3408 vlnctrl |= IXGBE_RXDCTL_VME;
3409 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3410 }
3411 break;
3412 default:
3413 break;
3414 }
3415}
3416
Auke Kok9a799d72007-09-15 14:07:45 -07003417static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3418{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003419 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003420
Jesse Grossf62bbb52010-10-20 13:56:10 +00003421 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3422
3423 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3424 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003425}
3426
3427/**
Alexander Duyck28500622010-06-15 09:25:48 +00003428 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3429 * @netdev: network interface device structure
3430 *
3431 * Writes unicast address list to the RAR table.
3432 * Returns: -ENOMEM on failure/insufficient address space
3433 * 0 on no addresses written
3434 * X on writing X addresses to the RAR table
3435 **/
3436static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3437{
3438 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3439 struct ixgbe_hw *hw = &adapter->hw;
3440 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003441 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003442 int count = 0;
3443
3444 /* return ENOMEM indicating insufficient memory for addresses */
3445 if (netdev_uc_count(netdev) > rar_entries)
3446 return -ENOMEM;
3447
3448 if (!netdev_uc_empty(netdev) && rar_entries) {
3449 struct netdev_hw_addr *ha;
3450 /* return error if we do not support writing to RAR table */
3451 if (!hw->mac.ops.set_rar)
3452 return -ENOMEM;
3453
3454 netdev_for_each_uc_addr(ha, netdev) {
3455 if (!rar_entries)
3456 break;
3457 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3458 vfn, IXGBE_RAH_AV);
3459 count++;
3460 }
3461 }
3462 /* write the addresses in reverse order to avoid write combining */
3463 for (; rar_entries > 0 ; rar_entries--)
3464 hw->mac.ops.clear_rar(hw, rar_entries);
3465
3466 return count;
3467}
3468
3469/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003470 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003471 * @netdev: network interface device structure
3472 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003473 * The set_rx_method entry point is called whenever the unicast/multicast
3474 * address list or the network interface flags are updated. This routine is
3475 * responsible for configuring the hardware for proper unicast, multicast and
3476 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003477 **/
Greg Rose7f870472010-01-09 02:25:29 +00003478void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003479{
3480 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3481 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003482 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3483 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003484
3485 /* Check for Promiscuous and All Multicast modes */
3486
3487 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3488
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003489 /* set all bits that we expect to always be set */
3490 fctrl |= IXGBE_FCTRL_BAM;
3491 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3492 fctrl |= IXGBE_FCTRL_PMCF;
3493
Alexander Duyck28500622010-06-15 09:25:48 +00003494 /* clear the bits we are changing the status of */
3495 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3496
Auke Kok9a799d72007-09-15 14:07:45 -07003497 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003498 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003499 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003500 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003501 /* don't hardware filter vlans in promisc mode */
3502 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003503 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003504 if (netdev->flags & IFF_ALLMULTI) {
3505 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003506 vmolr |= IXGBE_VMOLR_MPE;
3507 } else {
3508 /*
3509 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003510 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003511 * that we can at least receive multicast traffic
3512 */
3513 hw->mac.ops.update_mc_addr_list(hw, netdev);
3514 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003515 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003516 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003517 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003518 /*
3519 * Write addresses to available RAR registers, if there is not
3520 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003521 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003522 */
3523 count = ixgbe_write_uc_addr_list(netdev);
3524 if (count < 0) {
3525 fctrl |= IXGBE_FCTRL_UPE;
3526 vmolr |= IXGBE_VMOLR_ROPE;
3527 }
3528 }
3529
3530 if (adapter->num_vfs) {
3531 ixgbe_restore_vf_multicasts(adapter);
3532 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3533 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3534 IXGBE_VMOLR_ROPE);
3535 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003536 }
3537
3538 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003539
3540 if (netdev->features & NETIF_F_HW_VLAN_RX)
3541 ixgbe_vlan_strip_enable(adapter);
3542 else
3543 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003544}
3545
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003546static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3547{
3548 int q_idx;
3549 struct ixgbe_q_vector *q_vector;
3550 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3551
3552 /* legacy and MSI only use one vector */
3553 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3554 q_vectors = 1;
3555
3556 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003557 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003558 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003559 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003560 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003561 if (!q_vector->rx.count || !q_vector->tx.count) {
3562 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003563 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003564 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003565 napi->poll = &ixgbe_clean_rxonly;
3566 }
3567 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003568
3569 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003570 }
3571}
3572
3573static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3574{
3575 int q_idx;
3576 struct ixgbe_q_vector *q_vector;
3577 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3578
3579 /* legacy and MSI only use one vector */
3580 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3581 q_vectors = 1;
3582
3583 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003584 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003585 napi_disable(&q_vector->napi);
3586 }
3587}
3588
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003589#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003590/*
3591 * ixgbe_configure_dcb - Configure DCB hardware
3592 * @adapter: ixgbe adapter struct
3593 *
3594 * This is called by the driver on open to configure the DCB hardware.
3595 * This is also called by the gennetlink interface when reconfiguring
3596 * the DCB state.
3597 */
3598static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3599{
3600 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003601 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003602
Alexander Duyck67ebd792010-08-19 13:34:04 +00003603 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3604 if (hw->mac.type == ixgbe_mac_82598EB)
3605 netif_set_gso_max_size(adapter->netdev, 65536);
3606 return;
3607 }
3608
3609 if (hw->mac.type == ixgbe_mac_82598EB)
3610 netif_set_gso_max_size(adapter->netdev, 32768);
3611
Alexander Duyck2f90b862008-11-20 20:52:10 -08003612
Alexander Duyck2f90b862008-11-20 20:52:10 -08003613 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003614 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003615
Alexander Duyck2f90b862008-11-20 20:52:10 -08003616 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003617
3618 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003619 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
Alexander Duyck971060b2011-07-15 02:31:30 +00003620#ifdef IXGBE_FCOE
John Fastabendc27931d2011-02-23 05:58:25 +00003621 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3622 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3623#endif
3624 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3625 DCB_TX_CONFIG);
3626 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3627 DCB_RX_CONFIG);
3628 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3629 } else {
3630 struct net_device *dev = adapter->netdev;
3631
3632 if (adapter->ixgbe_ieee_ets)
3633 dev->dcbnl_ops->ieee_setets(dev,
3634 adapter->ixgbe_ieee_ets);
3635 if (adapter->ixgbe_ieee_pfc)
3636 dev->dcbnl_ops->ieee_setpfc(dev,
3637 adapter->ixgbe_ieee_pfc);
3638 }
John Fastabend8187cd42011-02-23 05:58:08 +00003639
3640 /* Enable RSS Hash per TC */
3641 if (hw->mac.type != ixgbe_mac_82598EB) {
3642 int i;
3643 u32 reg = 0;
3644
3645 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3646 u8 msb = 0;
3647 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3648
3649 while (cnt >>= 1)
3650 msb++;
3651
3652 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3653 }
3654 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3655 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003656}
3657
3658#endif
John Fastabend80605c652011-05-02 12:34:10 +00003659
3660static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3661{
3662 int hdrm = 0;
3663 int num_tc = netdev_get_num_tc(adapter->netdev);
3664 struct ixgbe_hw *hw = &adapter->hw;
3665
3666 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3667 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3668 hdrm = 64 << adapter->fdir_pballoc;
3669
3670 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3671}
3672
Alexander Duycke4911d52011-05-11 07:18:52 +00003673static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3674{
3675 struct ixgbe_hw *hw = &adapter->hw;
3676 struct hlist_node *node, *node2;
3677 struct ixgbe_fdir_filter *filter;
3678
3679 spin_lock(&adapter->fdir_perfect_lock);
3680
3681 if (!hlist_empty(&adapter->fdir_filter_list))
3682 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3683
3684 hlist_for_each_entry_safe(filter, node, node2,
3685 &adapter->fdir_filter_list, fdir_node) {
3686 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003687 &filter->filter,
3688 filter->sw_idx,
3689 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3690 IXGBE_FDIR_DROP_QUEUE :
3691 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003692 }
3693
3694 spin_unlock(&adapter->fdir_perfect_lock);
3695}
3696
Auke Kok9a799d72007-09-15 14:07:45 -07003697static void ixgbe_configure(struct ixgbe_adapter *adapter)
3698{
3699 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003700 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003701 int i;
3702
John Fastabend80605c652011-05-02 12:34:10 +00003703 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003704#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003705 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003706#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003707
Jesse Grossf62bbb52010-10-20 13:56:10 +00003708 ixgbe_set_rx_mode(netdev);
3709 ixgbe_restore_vlan(adapter);
3710
Yi Zoueacd73f2009-05-13 13:11:06 +00003711#ifdef IXGBE_FCOE
3712 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3713 ixgbe_configure_fcoe(adapter);
3714
3715#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003716 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3717 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003718 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003719 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003720 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003721 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3722 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3723 adapter->fdir_pballoc);
3724 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003725 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003726 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003727
Auke Kok9a799d72007-09-15 14:07:45 -07003728 ixgbe_configure_tx(adapter);
3729 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003730}
3731
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003732static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3733{
3734 switch (hw->phy.type) {
3735 case ixgbe_phy_sfp_avago:
3736 case ixgbe_phy_sfp_ftl:
3737 case ixgbe_phy_sfp_intel:
3738 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003739 case ixgbe_phy_sfp_passive_tyco:
3740 case ixgbe_phy_sfp_passive_unknown:
3741 case ixgbe_phy_sfp_active_unknown:
3742 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003743 return true;
3744 default:
3745 return false;
3746 }
3747}
3748
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003749/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003750 * ixgbe_sfp_link_config - set up SFP+ link
3751 * @adapter: pointer to private adapter struct
3752 **/
3753static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3754{
Alexander Duyck70864002011-04-27 09:13:56 +00003755 /*
3756 * We are assuming the worst case scenerio here, and that
3757 * is that an SFP was inserted/removed after the reset
3758 * but before SFP detection was enabled. As such the best
3759 * solution is to just start searching as soon as we start
3760 */
3761 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3762 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003763
Alexander Duyck70864002011-04-27 09:13:56 +00003764 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003765}
3766
3767/**
3768 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003769 * @hw: pointer to private hardware struct
3770 *
3771 * Returns 0 on success, negative on failure
3772 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003773static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003774{
3775 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003776 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003777 u32 ret = IXGBE_ERR_LINK_SETUP;
3778
3779 if (hw->mac.ops.check_link)
3780 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3781
3782 if (ret)
3783 goto link_cfg_out;
3784
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003785 autoneg = hw->phy.autoneg_advertised;
3786 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003787 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3788 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003789 if (ret)
3790 goto link_cfg_out;
3791
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003792 if (hw->mac.ops.setup_link)
3793 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003794link_cfg_out:
3795 return ret;
3796}
3797
Alexander Duycka34bcff2010-08-19 13:39:20 +00003798static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003799{
Auke Kok9a799d72007-09-15 14:07:45 -07003800 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003801 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003802
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003803 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003804 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3805 IXGBE_GPIE_OCD;
3806 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003807 /*
3808 * use EIAM to auto-mask when MSI-X interrupt is asserted
3809 * this saves a register write for every interrupt
3810 */
3811 switch (hw->mac.type) {
3812 case ixgbe_mac_82598EB:
3813 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3814 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003815 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003816 case ixgbe_mac_X540:
3817 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003818 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3819 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3820 break;
3821 }
3822 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003823 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3824 * specifically only auto mask tx and rx interrupts */
3825 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003826 }
3827
Alexander Duycka34bcff2010-08-19 13:39:20 +00003828 /* XXX: to interrupt immediately for EICS writes, enable this */
3829 /* gpie |= IXGBE_GPIE_EIMEN; */
3830
3831 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3832 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3833 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003834 }
3835
Alexander Duycka34bcff2010-08-19 13:39:20 +00003836 /* Enable fan failure interrupt */
3837 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003838 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003839
Don Skidmore2698b202011-04-13 07:01:52 +00003840 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003841 gpie |= IXGBE_SDP1_GPIEN;
3842 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003843 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003844
3845 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3846}
3847
3848static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3849{
3850 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003851 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003852 u32 ctrl_ext;
3853
3854 ixgbe_get_hw_control(adapter);
3855 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003856
Auke Kok9a799d72007-09-15 14:07:45 -07003857 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3858 ixgbe_configure_msix(adapter);
3859 else
3860 ixgbe_configure_msi_and_legacy(adapter);
3861
Don Skidmorec6ecf392010-12-03 03:31:51 +00003862 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3863 if (hw->mac.ops.enable_tx_laser &&
3864 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003865 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003866 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003867 hw->mac.ops.enable_tx_laser(hw);
3868
Auke Kok9a799d72007-09-15 14:07:45 -07003869 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003870 ixgbe_napi_enable_all(adapter);
3871
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003872 if (ixgbe_is_sfp(hw)) {
3873 ixgbe_sfp_link_config(adapter);
3874 } else {
3875 err = ixgbe_non_sfp_link_config(hw);
3876 if (err)
3877 e_err(probe, "link_config FAILED %d\n", err);
3878 }
3879
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003880 /* clear any pending interrupts, may auto mask */
3881 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003882 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003883
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003884 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003885 * If this adapter has a fan, check to see if we had a failure
3886 * before we enabled the interrupt.
3887 */
3888 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3889 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3890 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003891 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003892 }
3893
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003894 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003895 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003896
Auke Kok9a799d72007-09-15 14:07:45 -07003897 /* bring the link up in the watchdog, this could race with our first
3898 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003899 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3900 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003901 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003902
3903 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3904 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3905 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3906 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3907
Auke Kok9a799d72007-09-15 14:07:45 -07003908 return 0;
3909}
3910
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003911void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3912{
3913 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003914 /* put off any impending NetWatchDogTimeout */
3915 adapter->netdev->trans_start = jiffies;
3916
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003917 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003918 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003919 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003920 /*
3921 * If SR-IOV enabled then wait a bit before bringing the adapter
3922 * back up to give the VFs time to respond to the reset. The
3923 * two second wait is based upon the watchdog timer cycle in
3924 * the VF driver.
3925 */
3926 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3927 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003928 ixgbe_up(adapter);
3929 clear_bit(__IXGBE_RESETTING, &adapter->state);
3930}
3931
Auke Kok9a799d72007-09-15 14:07:45 -07003932int ixgbe_up(struct ixgbe_adapter *adapter)
3933{
3934 /* hardware has been reset, we need to reload some things */
3935 ixgbe_configure(adapter);
3936
3937 return ixgbe_up_complete(adapter);
3938}
3939
3940void ixgbe_reset(struct ixgbe_adapter *adapter)
3941{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003942 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003943 int err;
3944
Alexander Duyck70864002011-04-27 09:13:56 +00003945 /* lock SFP init bit to prevent race conditions with the watchdog */
3946 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3947 usleep_range(1000, 2000);
3948
3949 /* clear all SFP and link config related flags while holding SFP_INIT */
3950 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3951 IXGBE_FLAG2_SFP_NEEDS_RESET);
3952 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3953
Don Skidmore8ca783a2009-05-26 20:40:47 -07003954 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003955 switch (err) {
3956 case 0:
3957 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003958 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003959 break;
3960 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003961 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003962 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003963 case IXGBE_ERR_EEPROM_VERSION:
3964 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003965 e_dev_warn("This device is a pre-production adapter/LOM. "
3966 "Please be aware there may be issuesassociated with "
3967 "your hardware. If you are experiencing problems "
3968 "please contact your Intel or hardware "
3969 "representative who provided you with this "
3970 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003971 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003972 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003973 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003974 }
Auke Kok9a799d72007-09-15 14:07:45 -07003975
Alexander Duyck70864002011-04-27 09:13:56 +00003976 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3977
Auke Kok9a799d72007-09-15 14:07:45 -07003978 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003979 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3980 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003981}
3982
Auke Kok9a799d72007-09-15 14:07:45 -07003983/**
3984 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003985 * @rx_ring: ring to free buffers from
3986 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003987static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003988{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003989 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003990 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003991 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003992
Alexander Duyck84418e32010-08-19 13:40:54 +00003993 /* ring already cleared, nothing to do */
3994 if (!rx_ring->rx_buffer_info)
3995 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003996
Alexander Duyck84418e32010-08-19 13:40:54 +00003997 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003998 for (i = 0; i < rx_ring->count; i++) {
3999 struct ixgbe_rx_buffer *rx_buffer_info;
4000
4001 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4002 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004003 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004004 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004005 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004006 rx_buffer_info->dma = 0;
4007 }
4008 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004009 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004010 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004011 do {
4012 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004013 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004014 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004015 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004016 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004017 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004018 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004019 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004020 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004021 skb = skb->prev;
4022 dev_kfree_skb(this);
4023 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004024 }
4025 if (!rx_buffer_info->page)
4026 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004027 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004028 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004029 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004030 rx_buffer_info->page_dma = 0;
4031 }
Auke Kok9a799d72007-09-15 14:07:45 -07004032 put_page(rx_buffer_info->page);
4033 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004034 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004035 }
4036
4037 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4038 memset(rx_ring->rx_buffer_info, 0, size);
4039
4040 /* Zero out the descriptor ring */
4041 memset(rx_ring->desc, 0, rx_ring->size);
4042
4043 rx_ring->next_to_clean = 0;
4044 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004045}
4046
4047/**
4048 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004049 * @tx_ring: ring to be cleaned
4050 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004051static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004052{
4053 struct ixgbe_tx_buffer *tx_buffer_info;
4054 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004055 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004056
Alexander Duyck84418e32010-08-19 13:40:54 +00004057 /* ring already cleared, nothing to do */
4058 if (!tx_ring->tx_buffer_info)
4059 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004060
Alexander Duyck84418e32010-08-19 13:40:54 +00004061 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004062 for (i = 0; i < tx_ring->count; i++) {
4063 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004064 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004065 }
4066
4067 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4068 memset(tx_ring->tx_buffer_info, 0, size);
4069
4070 /* Zero out the descriptor ring */
4071 memset(tx_ring->desc, 0, tx_ring->size);
4072
4073 tx_ring->next_to_use = 0;
4074 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004075}
4076
4077/**
Auke Kok9a799d72007-09-15 14:07:45 -07004078 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4079 * @adapter: board private structure
4080 **/
4081static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4082{
4083 int i;
4084
4085 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004086 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004087}
4088
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004089/**
4090 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4091 * @adapter: board private structure
4092 **/
4093static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4094{
4095 int i;
4096
4097 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004098 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004099}
4100
Alexander Duycke4911d52011-05-11 07:18:52 +00004101static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4102{
4103 struct hlist_node *node, *node2;
4104 struct ixgbe_fdir_filter *filter;
4105
4106 spin_lock(&adapter->fdir_perfect_lock);
4107
4108 hlist_for_each_entry_safe(filter, node, node2,
4109 &adapter->fdir_filter_list, fdir_node) {
4110 hlist_del(&filter->fdir_node);
4111 kfree(filter);
4112 }
4113 adapter->fdir_filter_count = 0;
4114
4115 spin_unlock(&adapter->fdir_perfect_lock);
4116}
4117
Auke Kok9a799d72007-09-15 14:07:45 -07004118void ixgbe_down(struct ixgbe_adapter *adapter)
4119{
4120 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004121 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004122 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004123 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004124 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004125
4126 /* signal that we are down to the interrupt handler */
4127 set_bit(__IXGBE_DOWN, &adapter->state);
4128
4129 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004130 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4131 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004132
Yi Zou2d39d572011-01-06 14:29:56 +00004133 /* disable all enabled rx queues */
4134 for (i = 0; i < adapter->num_rx_queues; i++)
4135 /* this call also flushes the previous write */
4136 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4137
Don Skidmore032b4322011-03-18 09:32:53 +00004138 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004139
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004140 netif_tx_stop_all_queues(netdev);
4141
Alexander Duyck70864002011-04-27 09:13:56 +00004142 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004143 netif_carrier_off(netdev);
4144 netif_tx_disable(netdev);
4145
4146 ixgbe_irq_disable(adapter);
4147
4148 ixgbe_napi_disable_all(adapter);
4149
Alexander Duyckd034acf2011-04-27 09:25:34 +00004150 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4151 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004152 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4153
4154 del_timer_sync(&adapter->service_timer);
4155
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004156 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004157 if (adapter->num_vfs) {
4158 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004159 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004160
Auke Kok9a799d72007-09-15 14:07:45 -07004161 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004162 ixgbe_disable_tx_rx(adapter);
4163
4164 /* Mark all the VFs as inactive */
4165 for (i = 0 ; i < adapter->num_vfs; i++)
4166 adapter->vfinfo[i].clear_to_send = 0;
4167 }
4168
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004169 /* Cleanup the affinity_hint CPU mask memory and callback */
4170 for (i = 0; i < num_q_vectors; i++) {
4171 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4172 /* clear the affinity_mask in the IRQ descriptor */
4173 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4174 /* release the CPU mask memory */
4175 free_cpumask_var(q_vector->affinity_mask);
4176 }
4177
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004178 /* disable transmits in the hardware now that interrupts are off */
4179 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004180 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004181 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004182 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004183
4184 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004185 switch (hw->mac.type) {
4186 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004187 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004188 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004189 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4190 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004191 break;
4192 default:
4193 break;
4194 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004195
Paul Larson6f4a0e42008-06-24 17:00:56 -07004196 if (!pci_channel_offline(adapter->pdev))
4197 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004198
4199 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4200 if (hw->mac.ops.disable_tx_laser &&
4201 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004202 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004203 (hw->mac.type == ixgbe_mac_82599EB))))
4204 hw->mac.ops.disable_tx_laser(hw);
4205
Auke Kok9a799d72007-09-15 14:07:45 -07004206 ixgbe_clean_all_tx_rings(adapter);
4207 ixgbe_clean_all_rx_rings(adapter);
4208
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004209#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004210 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004211 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004212#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004213}
4214
Auke Kok9a799d72007-09-15 14:07:45 -07004215/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004216 * ixgbe_poll - NAPI Rx polling callback
4217 * @napi: structure for representing this polling device
4218 * @budget: how many packets driver is allowed to clean
4219 *
4220 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004221 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004222static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004223{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004224 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004225 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004226 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004227 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004228
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004229#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004230 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4231 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004232#endif
4233
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004234 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4235 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004236
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004237 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004238 work_done = budget;
4239
David S. Miller53e52c72008-01-07 21:06:12 -08004240 /* If budget not fully consumed, exit the polling mode */
4241 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004242 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004243 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004244 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004245 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004246 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004247 }
Auke Kok9a799d72007-09-15 14:07:45 -07004248 return work_done;
4249}
4250
4251/**
4252 * ixgbe_tx_timeout - Respond to a Tx Hang
4253 * @netdev: network interface device structure
4254 **/
4255static void ixgbe_tx_timeout(struct net_device *netdev)
4256{
4257 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4258
4259 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004260 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004261}
4262
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004263/**
4264 * ixgbe_set_rss_queues: Allocate queues for RSS
4265 * @adapter: board private structure to initialize
4266 *
4267 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4268 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4269 *
4270 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004271static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4272{
4273 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004274 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004275
4276 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004277 f->mask = 0xF;
4278 adapter->num_rx_queues = f->indices;
4279 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004280 ret = true;
4281 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004282 ret = false;
4283 }
4284
4285 return ret;
4286}
4287
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004288/**
4289 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4290 * @adapter: board private structure to initialize
4291 *
4292 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4293 * to the original CPU that initiated the Tx session. This runs in addition
4294 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4295 * Rx load across CPUs using RSS.
4296 *
4297 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004298static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004299{
4300 bool ret = false;
4301 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4302
4303 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4304 f_fdir->mask = 0;
4305
4306 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004307 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4308 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004309 adapter->num_tx_queues = f_fdir->indices;
4310 adapter->num_rx_queues = f_fdir->indices;
4311 ret = true;
4312 } else {
4313 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004314 }
4315 return ret;
4316}
4317
Yi Zou0331a832009-05-17 12:33:52 +00004318#ifdef IXGBE_FCOE
4319/**
4320 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4321 * @adapter: board private structure to initialize
4322 *
4323 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4324 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4325 * rx queues out of the max number of rx queues, instead, it is used as the
4326 * index of the first rx queue used by FCoE.
4327 *
4328 **/
4329static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4330{
Yi Zou0331a832009-05-17 12:33:52 +00004331 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4332
John Fastabende5b64632011-03-08 03:44:52 +00004333 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4334 return false;
4335
John Fastabende901acd2011-04-26 07:26:08 +00004336 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004337
John Fastabende901acd2011-04-26 07:26:08 +00004338 adapter->num_rx_queues = 1;
4339 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004340
John Fastabende901acd2011-04-26 07:26:08 +00004341 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4342 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004343 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004344 ixgbe_set_fdir_queues(adapter);
4345 else
4346 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004347 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004348
John Fastabende901acd2011-04-26 07:26:08 +00004349 /* adding FCoE rx rings to the end */
4350 f->mask = adapter->num_rx_queues;
4351 adapter->num_rx_queues += f->indices;
4352 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004353
John Fastabende5b64632011-03-08 03:44:52 +00004354 return true;
4355}
4356#endif /* IXGBE_FCOE */
4357
John Fastabende901acd2011-04-26 07:26:08 +00004358/* Artificial max queue cap per traffic class in DCB mode */
4359#define DCB_QUEUE_CAP 8
4360
John Fastabende5b64632011-03-08 03:44:52 +00004361#ifdef CONFIG_IXGBE_DCB
4362static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4363{
John Fastabende901acd2011-04-26 07:26:08 +00004364 int per_tc_q, q, i, offset = 0;
4365 struct net_device *dev = adapter->netdev;
4366 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004367
John Fastabende901acd2011-04-26 07:26:08 +00004368 if (!tcs)
4369 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004370
John Fastabende901acd2011-04-26 07:26:08 +00004371 /* Map queue offset and counts onto allocated tx queues */
4372 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4373 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004374
John Fastabend8b1c0b22011-05-03 02:26:48 +00004375 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004376 netdev_set_prio_tc_map(dev, i, i);
4377 netdev_set_tc_queue(dev, i, q, offset);
4378 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004379 }
4380
John Fastabende901acd2011-04-26 07:26:08 +00004381 adapter->num_tx_queues = q * tcs;
4382 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004383
4384#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004385 /* FCoE enabled queues require special configuration indexed
4386 * by feature specific indices and mask. Here we map FCoE
4387 * indices onto the DCB queue pairs allowing FCoE to own
4388 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004389 */
John Fastabende901acd2011-04-26 07:26:08 +00004390 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4391 int tc;
4392 struct ixgbe_ring_feature *f =
4393 &adapter->ring_feature[RING_F_FCOE];
4394
4395 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4396 f->indices = dev->tc_to_txq[tc].count;
4397 f->mask = dev->tc_to_txq[tc].offset;
4398 }
John Fastabende5b64632011-03-08 03:44:52 +00004399#endif
4400
John Fastabende901acd2011-04-26 07:26:08 +00004401 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004402}
John Fastabende5b64632011-03-08 03:44:52 +00004403#endif
Yi Zou0331a832009-05-17 12:33:52 +00004404
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004405/**
4406 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4407 * @adapter: board private structure to initialize
4408 *
4409 * IOV doesn't actually use anything, so just NAK the
4410 * request for now and let the other queue routines
4411 * figure out what to do.
4412 */
4413static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4414{
4415 return false;
4416}
4417
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004418/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004419 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004420 * @adapter: board private structure to initialize
4421 *
4422 * This is the top level queue allocation routine. The order here is very
4423 * important, starting with the "most" number of features turned on at once,
4424 * and ending with the smallest set of features. This way large combinations
4425 * can be allocated if they're turned on, and smaller combinations are the
4426 * fallthrough conditions.
4427 *
4428 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004429static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004430{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004431 /* Start with base case */
4432 adapter->num_rx_queues = 1;
4433 adapter->num_tx_queues = 1;
4434 adapter->num_rx_pools = adapter->num_rx_queues;
4435 adapter->num_rx_queues_per_pool = 1;
4436
4437 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004438 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004439
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004440#ifdef CONFIG_IXGBE_DCB
4441 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004442 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004443
4444#endif
John Fastabende5b64632011-03-08 03:44:52 +00004445#ifdef IXGBE_FCOE
4446 if (ixgbe_set_fcoe_queues(adapter))
4447 goto done;
4448
4449#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004450 if (ixgbe_set_fdir_queues(adapter))
4451 goto done;
4452
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004453 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004454 goto done;
4455
4456 /* fallback to base case */
4457 adapter->num_rx_queues = 1;
4458 adapter->num_tx_queues = 1;
4459
4460done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004461 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004462 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004463 return netif_set_real_num_rx_queues(adapter->netdev,
4464 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004465}
4466
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004467static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004468 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004469{
4470 int err, vector_threshold;
4471
4472 /* We'll want at least 3 (vector_threshold):
4473 * 1) TxQ[0] Cleanup
4474 * 2) RxQ[0] Cleanup
4475 * 3) Other (Link Status Change, etc.)
4476 * 4) TCP Timer (optional)
4477 */
4478 vector_threshold = MIN_MSIX_COUNT;
4479
4480 /* The more we get, the more we will assign to Tx/Rx Cleanup
4481 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4482 * Right now, we simply care about how many we'll get; we'll
4483 * set them up later while requesting irq's.
4484 */
4485 while (vectors >= vector_threshold) {
4486 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004487 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004488 if (!err) /* Success in acquiring all requested vectors. */
4489 break;
4490 else if (err < 0)
4491 vectors = 0; /* Nasty failure, quit now */
4492 else /* err == number of vectors we should try again with */
4493 vectors = err;
4494 }
4495
4496 if (vectors < vector_threshold) {
4497 /* Can't allocate enough MSI-X interrupts? Oh well.
4498 * This just means we'll go with either a single MSI
4499 * vector or fall back to legacy interrupts.
4500 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004501 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4502 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004503 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4504 kfree(adapter->msix_entries);
4505 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004506 } else {
4507 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004508 /*
4509 * Adjust for only the vectors we'll use, which is minimum
4510 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4511 * vectors we were allocated.
4512 */
4513 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004514 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004515 }
4516}
4517
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004518/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004519 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004520 * @adapter: board private structure to initialize
4521 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004522 * Cache the descriptor ring offsets for RSS to the assigned rings.
4523 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004524 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004525static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004526{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004527 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004528
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004529 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4530 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004531
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004532 for (i = 0; i < adapter->num_rx_queues; i++)
4533 adapter->rx_ring[i]->reg_idx = i;
4534 for (i = 0; i < adapter->num_tx_queues; i++)
4535 adapter->tx_ring[i]->reg_idx = i;
4536
4537 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004538}
4539
4540#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004541
4542/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004543static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4544 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004545{
4546 struct net_device *dev = adapter->netdev;
4547 struct ixgbe_hw *hw = &adapter->hw;
4548 u8 num_tcs = netdev_get_num_tc(dev);
4549
4550 *tx = 0;
4551 *rx = 0;
4552
4553 switch (hw->mac.type) {
4554 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004555 *tx = tc << 2;
4556 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004557 break;
4558 case ixgbe_mac_82599EB:
4559 case ixgbe_mac_X540:
4560 if (num_tcs == 8) {
4561 if (tc < 3) {
4562 *tx = tc << 5;
4563 *rx = tc << 4;
4564 } else if (tc < 5) {
4565 *tx = ((tc + 2) << 4);
4566 *rx = tc << 4;
4567 } else if (tc < num_tcs) {
4568 *tx = ((tc + 8) << 3);
4569 *rx = tc << 4;
4570 }
4571 } else if (num_tcs == 4) {
4572 *rx = tc << 5;
4573 switch (tc) {
4574 case 0:
4575 *tx = 0;
4576 break;
4577 case 1:
4578 *tx = 64;
4579 break;
4580 case 2:
4581 *tx = 96;
4582 break;
4583 case 3:
4584 *tx = 112;
4585 break;
4586 default:
4587 break;
4588 }
4589 }
4590 break;
4591 default:
4592 break;
4593 }
4594}
4595
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004596/**
4597 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4598 * @adapter: board private structure to initialize
4599 *
4600 * Cache the descriptor ring offsets for DCB to the assigned rings.
4601 *
4602 **/
4603static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4604{
John Fastabende5b64632011-03-08 03:44:52 +00004605 struct net_device *dev = adapter->netdev;
4606 int i, j, k;
4607 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004608
John Fastabend8b1c0b22011-05-03 02:26:48 +00004609 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004610 return false;
4611
John Fastabende5b64632011-03-08 03:44:52 +00004612 for (i = 0, k = 0; i < num_tcs; i++) {
4613 unsigned int tx_s, rx_s;
4614 u16 count = dev->tc_to_txq[i].count;
4615
4616 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4617 for (j = 0; j < count; j++, k++) {
4618 adapter->tx_ring[k]->reg_idx = tx_s + j;
4619 adapter->rx_ring[k]->reg_idx = rx_s + j;
4620 adapter->tx_ring[k]->dcb_tc = i;
4621 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004622 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004623 }
John Fastabende5b64632011-03-08 03:44:52 +00004624
4625 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004626}
4627#endif
4628
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004629/**
4630 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4631 * @adapter: board private structure to initialize
4632 *
4633 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4634 *
4635 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004636static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004637{
4638 int i;
4639 bool ret = false;
4640
Alexander Duyck03ecf912011-05-20 07:36:17 +00004641 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4642 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004643 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004644 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004645 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004646 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004647 ret = true;
4648 }
4649
4650 return ret;
4651}
4652
Yi Zou0331a832009-05-17 12:33:52 +00004653#ifdef IXGBE_FCOE
4654/**
4655 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4656 * @adapter: board private structure to initialize
4657 *
4658 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4659 *
4660 */
4661static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4662{
Yi Zou0331a832009-05-17 12:33:52 +00004663 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004664 int i;
4665 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004666
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004667 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4668 return false;
4669
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004670 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004671 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004672 ixgbe_cache_ring_fdir(adapter);
4673 else
4674 ixgbe_cache_ring_rss(adapter);
4675
4676 fcoe_rx_i = f->mask;
4677 fcoe_tx_i = f->mask;
4678 }
4679 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4680 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4681 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4682 }
4683 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004684}
4685
4686#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004687/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004688 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4689 * @adapter: board private structure to initialize
4690 *
4691 * SR-IOV doesn't use any descriptor rings but changes the default if
4692 * no other mapping is used.
4693 *
4694 */
4695static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4696{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004697 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4698 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004699 if (adapter->num_vfs)
4700 return true;
4701 else
4702 return false;
4703}
4704
4705/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004706 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4707 * @adapter: board private structure to initialize
4708 *
4709 * Once we know the feature-set enabled for the device, we'll cache
4710 * the register offset the descriptor ring is assigned to.
4711 *
4712 * Note, the order the various feature calls is important. It must start with
4713 * the "most" features enabled at the same time, then trickle down to the
4714 * least amount of features turned on at once.
4715 **/
4716static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4717{
4718 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004719 adapter->rx_ring[0]->reg_idx = 0;
4720 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004721
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004722 if (ixgbe_cache_ring_sriov(adapter))
4723 return;
4724
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004725#ifdef CONFIG_IXGBE_DCB
4726 if (ixgbe_cache_ring_dcb(adapter))
4727 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004728#endif
John Fastabende5b64632011-03-08 03:44:52 +00004729
4730#ifdef IXGBE_FCOE
4731 if (ixgbe_cache_ring_fcoe(adapter))
4732 return;
4733#endif /* IXGBE_FCOE */
4734
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004735 if (ixgbe_cache_ring_fdir(adapter))
4736 return;
4737
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004738 if (ixgbe_cache_ring_rss(adapter))
4739 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004740}
4741
Auke Kok9a799d72007-09-15 14:07:45 -07004742/**
4743 * ixgbe_alloc_queues - Allocate memory for all rings
4744 * @adapter: board private structure to initialize
4745 *
4746 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004747 * number of queues at compile-time. The polling_netdev array is
4748 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004749 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004750static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004751{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004752 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004753
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004754 if (nid < 0 || !node_online(nid))
4755 nid = first_online_node;
4756
4757 for (; tx < adapter->num_tx_queues; tx++) {
4758 struct ixgbe_ring *ring;
4759
4760 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004761 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004762 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004763 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004764 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004765 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004766 ring->queue_index = tx;
4767 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004768 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004769 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004770
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004771 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004772 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004773
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004774 for (; rx < adapter->num_rx_queues; rx++) {
4775 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004776
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004777 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004778 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004779 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004780 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004781 goto err_allocation;
4782 ring->count = adapter->rx_ring_count;
4783 ring->queue_index = rx;
4784 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004785 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004786 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004787
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004788 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004789 }
4790
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004791 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004792
4793 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004794
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004795err_allocation:
4796 while (tx)
4797 kfree(adapter->tx_ring[--tx]);
4798
4799 while (rx)
4800 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004801 return -ENOMEM;
4802}
4803
4804/**
4805 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4806 * @adapter: board private structure to initialize
4807 *
4808 * Attempt to configure the interrupts using the best available
4809 * capabilities of the hardware and the kernel.
4810 **/
Al Virofeea6a52008-11-27 15:34:07 -08004811static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004812{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004813 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004814 int err = 0;
4815 int vector, v_budget;
4816
4817 /*
4818 * It's easy to be greedy for MSI-X vectors, but it really
4819 * doesn't do us much good if we have a lot more vectors
4820 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004821 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004822 */
4823 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004824 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004825
4826 /*
4827 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004828 * hw.mac->max_msix_vectors vectors. With features
4829 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4830 * descriptor queues supported by our device. Thus, we cap it off in
4831 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004832 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004833 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004834
4835 /* A failure in MSI-X entry allocation isn't fatal, but it does
4836 * mean we disable MSI-X capabilities of the adapter. */
4837 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004838 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004839 if (adapter->msix_entries) {
4840 for (vector = 0; vector < v_budget; vector++)
4841 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842
Alexander Duyck7a921c92009-05-06 10:43:28 +00004843 ixgbe_acquire_msix_vectors(adapter, v_budget);
4844
4845 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4846 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004847 }
David S. Miller26d27842010-05-03 15:18:22 -07004848
Alexander Duyck7a921c92009-05-06 10:43:28 +00004849 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4850 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004851 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004852 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004853 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004854 "queues are disabled. Disabling Flow Director\n");
4855 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004856 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004857 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004858 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4859 ixgbe_disable_sriov(adapter);
4860
Ben Hutchings847f53f2010-09-27 08:28:56 +00004861 err = ixgbe_set_num_queues(adapter);
4862 if (err)
4863 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004864
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004865 err = pci_enable_msi(adapter->pdev);
4866 if (!err) {
4867 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4868 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004869 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4870 "Unable to allocate MSI interrupt, "
4871 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004872 /* reset err */
4873 err = 0;
4874 }
4875
4876out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004877 return err;
4878}
4879
Alexander Duyck7a921c92009-05-06 10:43:28 +00004880/**
4881 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4882 * @adapter: board private structure to initialize
4883 *
4884 * We allocate one q_vector per queue interrupt. If allocation fails we
4885 * return -ENOMEM.
4886 **/
4887static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4888{
4889 int q_idx, num_q_vectors;
4890 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004891 int (*poll)(struct napi_struct *, int);
4892
4893 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4894 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004895 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004896 } else {
4897 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004898 poll = &ixgbe_poll;
4899 }
4900
4901 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004902 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004903 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004904 if (!q_vector)
4905 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004906 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004907 if (!q_vector)
4908 goto err_out;
4909 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004910 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004911 q_vector->eitr = adapter->tx_eitr_param;
4912 else
4913 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004914 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004915 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004916 adapter->q_vector[q_idx] = q_vector;
4917 }
4918
4919 return 0;
4920
4921err_out:
4922 while (q_idx) {
4923 q_idx--;
4924 q_vector = adapter->q_vector[q_idx];
4925 netif_napi_del(&q_vector->napi);
4926 kfree(q_vector);
4927 adapter->q_vector[q_idx] = NULL;
4928 }
4929 return -ENOMEM;
4930}
4931
4932/**
4933 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4934 * @adapter: board private structure to initialize
4935 *
4936 * This function frees the memory allocated to the q_vectors. In addition if
4937 * NAPI is enabled it will delete any references to the NAPI struct prior
4938 * to freeing the q_vector.
4939 **/
4940static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4941{
4942 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004943
Alexander Duyck91281fd2009-06-04 16:00:27 +00004944 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004945 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004946 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004947 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004948
4949 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4950 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004951 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004952 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004953 kfree(q_vector);
4954 }
4955}
4956
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004957static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004958{
4959 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4960 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4961 pci_disable_msix(adapter->pdev);
4962 kfree(adapter->msix_entries);
4963 adapter->msix_entries = NULL;
4964 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4965 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4966 pci_disable_msi(adapter->pdev);
4967 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004968}
4969
4970/**
4971 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4972 * @adapter: board private structure to initialize
4973 *
4974 * We determine which interrupt scheme to use based on...
4975 * - Kernel support (MSI, MSI-X)
4976 * - which can be user-defined (via MODULE_PARAM)
4977 * - Hardware queue count (num_*_queues)
4978 * - defined by miscellaneous hardware support/features (RSS, etc.)
4979 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004980int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004981{
4982 int err;
4983
4984 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004985 err = ixgbe_set_num_queues(adapter);
4986 if (err)
4987 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004988
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004989 err = ixgbe_set_interrupt_capability(adapter);
4990 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004991 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004992 goto err_set_interrupt;
4993 }
4994
Alexander Duyck7a921c92009-05-06 10:43:28 +00004995 err = ixgbe_alloc_q_vectors(adapter);
4996 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004997 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004998 goto err_alloc_q_vectors;
4999 }
5000
5001 err = ixgbe_alloc_queues(adapter);
5002 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005003 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005004 goto err_alloc_queues;
5005 }
5006
Emil Tantilov849c4542010-06-03 16:53:41 +00005007 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005008 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5009 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005010
5011 set_bit(__IXGBE_DOWN, &adapter->state);
5012
5013 return 0;
5014
Alexander Duyck7a921c92009-05-06 10:43:28 +00005015err_alloc_queues:
5016 ixgbe_free_q_vectors(adapter);
5017err_alloc_q_vectors:
5018 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005019err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005020 return err;
5021}
5022
5023/**
5024 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5025 * @adapter: board private structure to clear interrupt scheme on
5026 *
5027 * We go through and clear interrupt specific resources and reset the structure
5028 * to pre-load conditions
5029 **/
5030void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5031{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005032 int i;
5033
5034 for (i = 0; i < adapter->num_tx_queues; i++) {
5035 kfree(adapter->tx_ring[i]);
5036 adapter->tx_ring[i] = NULL;
5037 }
5038 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005039 struct ixgbe_ring *ring = adapter->rx_ring[i];
5040
5041 /* ixgbe_get_stats64() might access this ring, we must wait
5042 * a grace period before freeing it.
5043 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005044 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005045 adapter->rx_ring[i] = NULL;
5046 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005047
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005048 adapter->num_tx_queues = 0;
5049 adapter->num_rx_queues = 0;
5050
Alexander Duyck7a921c92009-05-06 10:43:28 +00005051 ixgbe_free_q_vectors(adapter);
5052 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005053}
5054
5055/**
5056 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5057 * @adapter: board private structure to initialize
5058 *
5059 * ixgbe_sw_init initializes the Adapter private data structure.
5060 * Fields are initialized based on PCI device information and
5061 * OS network device settings (MTU size).
5062 **/
5063static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5064{
5065 struct ixgbe_hw *hw = &adapter->hw;
5066 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005067 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005068 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005069#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005070 int j;
5071 struct tc_configuration *tc;
5072#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005073 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005074
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005075 /* PCI config space info */
5076
5077 hw->vendor_id = pdev->vendor;
5078 hw->device_id = pdev->device;
5079 hw->revision_id = pdev->revision;
5080 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5081 hw->subsystem_device_id = pdev->subsystem_device;
5082
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005083 /* Set capability flags */
5084 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5085 adapter->ring_feature[RING_F_RSS].indices = rss;
5086 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005087 switch (hw->mac.type) {
5088 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005089 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5090 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005091 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005092 break;
5093 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005094 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005095 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005096 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5097 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005098 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5099 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005100 /* Flow Director hash filters enabled */
5101 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5102 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005103 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005104 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005105 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005106#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005107 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5108 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5109 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005110#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005111 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005112 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005113#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005114#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005115 break;
5116 default:
5117 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005118 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005119
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005120 /* n-tuple support exists, always init our spinlock */
5121 spin_lock_init(&adapter->fdir_perfect_lock);
5122
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005123#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005124 /* Configure DCB traffic classes */
5125 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5126 tc = &adapter->dcb_cfg.tc_config[j];
5127 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5128 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5129 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5130 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5131 tc->dcb_pfc = pfc_disabled;
5132 }
5133 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5134 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005135 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005136 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005137 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005138 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005139 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005140
5141#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005142
5143 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005144 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005145 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005146#ifdef CONFIG_DCB
5147 adapter->last_lfc_mode = hw->fc.current_mode;
5148#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005149 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5150 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005151 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5152 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005153 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005154
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005155 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005156 adapter->rx_itr_setting = 1;
5157 adapter->rx_eitr_param = 20000;
5158 adapter->tx_itr_setting = 1;
5159 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005160
5161 /* set defaults for eitr in MegaBytes */
5162 adapter->eitr_low = 10;
5163 adapter->eitr_high = 20;
5164
5165 /* set default ring sizes */
5166 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5167 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5168
Alexander Duyckbd198052011-06-11 01:45:08 +00005169 /* set default work limits */
5170 adapter->tx_work_limit = adapter->tx_ring_count;
5171
Auke Kok9a799d72007-09-15 14:07:45 -07005172 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005173 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005174 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005175 return -EIO;
5176 }
5177
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005178 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005179 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5180
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005181 /* get assigned NUMA node */
5182 adapter->node = dev_to_node(&pdev->dev);
5183
Auke Kok9a799d72007-09-15 14:07:45 -07005184 set_bit(__IXGBE_DOWN, &adapter->state);
5185
5186 return 0;
5187}
5188
5189/**
5190 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005191 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005192 *
5193 * Return 0 on success, negative on failure
5194 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005195int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005196{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005197 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005198 int size;
5199
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005200 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005201 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005202 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005203 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005204 if (!tx_ring->tx_buffer_info)
5205 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005206
5207 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005208 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005209 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005210
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005211 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005212 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005213 if (!tx_ring->desc)
5214 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005215
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005216 tx_ring->next_to_use = 0;
5217 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005218 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005219
5220err:
5221 vfree(tx_ring->tx_buffer_info);
5222 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005223 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005224 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005225}
5226
5227/**
Alexander Duyck69888672008-09-11 20:05:39 -07005228 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5229 * @adapter: board private structure
5230 *
5231 * If this function returns with an error, then it's possible one or
5232 * more of the rings is populated (while the rest are not). It is the
5233 * callers duty to clean those orphaned rings.
5234 *
5235 * Return 0 on success, negative on failure
5236 **/
5237static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5238{
5239 int i, err = 0;
5240
5241 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005242 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005243 if (!err)
5244 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005245 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005246 break;
5247 }
5248
5249 return err;
5250}
5251
5252/**
Auke Kok9a799d72007-09-15 14:07:45 -07005253 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005254 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005255 *
5256 * Returns 0 on success, negative on failure
5257 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005258int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005259{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005260 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005261 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005262
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005263 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005264 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005265 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005266 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005267 if (!rx_ring->rx_buffer_info)
5268 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005269
Auke Kok9a799d72007-09-15 14:07:45 -07005270 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005271 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5272 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005273
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005274 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005275 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005276
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005277 if (!rx_ring->desc)
5278 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005279
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005280 rx_ring->next_to_clean = 0;
5281 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005282
5283 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005284err:
5285 vfree(rx_ring->rx_buffer_info);
5286 rx_ring->rx_buffer_info = NULL;
5287 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005288 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005289}
5290
5291/**
Alexander Duyck69888672008-09-11 20:05:39 -07005292 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5293 * @adapter: board private structure
5294 *
5295 * If this function returns with an error, then it's possible one or
5296 * more of the rings is populated (while the rest are not). It is the
5297 * callers duty to clean those orphaned rings.
5298 *
5299 * Return 0 on success, negative on failure
5300 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005301static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5302{
5303 int i, err = 0;
5304
5305 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005306 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005307 if (!err)
5308 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005309 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005310 break;
5311 }
5312
5313 return err;
5314}
5315
5316/**
Auke Kok9a799d72007-09-15 14:07:45 -07005317 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005318 * @tx_ring: Tx descriptor ring for a specific queue
5319 *
5320 * Free all transmit software resources
5321 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005323{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005324 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005325
5326 vfree(tx_ring->tx_buffer_info);
5327 tx_ring->tx_buffer_info = NULL;
5328
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005329 /* if not set, then don't free */
5330 if (!tx_ring->desc)
5331 return;
5332
5333 dma_free_coherent(tx_ring->dev, tx_ring->size,
5334 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005335
5336 tx_ring->desc = NULL;
5337}
5338
5339/**
5340 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5341 * @adapter: board private structure
5342 *
5343 * Free all transmit software resources
5344 **/
5345static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5346{
5347 int i;
5348
5349 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005350 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005351 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005352}
5353
5354/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005355 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005356 * @rx_ring: ring to clean the resources from
5357 *
5358 * Free all receive software resources
5359 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005360void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005361{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005362 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005363
5364 vfree(rx_ring->rx_buffer_info);
5365 rx_ring->rx_buffer_info = NULL;
5366
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005367 /* if not set, then don't free */
5368 if (!rx_ring->desc)
5369 return;
5370
5371 dma_free_coherent(rx_ring->dev, rx_ring->size,
5372 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005373
5374 rx_ring->desc = NULL;
5375}
5376
5377/**
5378 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5379 * @adapter: board private structure
5380 *
5381 * Free all receive software resources
5382 **/
5383static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5384{
5385 int i;
5386
5387 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005388 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005390}
5391
5392/**
Auke Kok9a799d72007-09-15 14:07:45 -07005393 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5394 * @netdev: network interface device structure
5395 * @new_mtu: new value for maximum frame size
5396 *
5397 * Returns 0 on success, negative on failure
5398 **/
5399static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5400{
5401 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005402 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005403 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5404
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005405 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005406 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5407 hw->mac.type != ixgbe_mac_X540) {
5408 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5409 return -EINVAL;
5410 } else {
5411 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5412 return -EINVAL;
5413 }
Auke Kok9a799d72007-09-15 14:07:45 -07005414
Emil Tantilov396e7992010-07-01 20:05:12 +00005415 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005416 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005417 netdev->mtu = new_mtu;
5418
John Fastabend16b61be2010-11-16 19:26:44 -08005419 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5420 hw->fc.low_water = FC_LOW_WATER(max_frame);
5421
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005422 if (netif_running(netdev))
5423 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005424
5425 return 0;
5426}
5427
5428/**
5429 * ixgbe_open - Called when a network interface is made active
5430 * @netdev: network interface device structure
5431 *
5432 * Returns 0 on success, negative value on failure
5433 *
5434 * The open entry point is called when a network interface is made
5435 * active by the system (IFF_UP). At this point all resources needed
5436 * for transmit and receive operations are allocated, the interrupt
5437 * handler is registered with the OS, the watchdog timer is started,
5438 * and the stack is notified that the interface is ready.
5439 **/
5440static int ixgbe_open(struct net_device *netdev)
5441{
5442 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5443 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005444
Auke Kok4bebfaa2008-02-11 09:26:01 -08005445 /* disallow open during test */
5446 if (test_bit(__IXGBE_TESTING, &adapter->state))
5447 return -EBUSY;
5448
Jesse Brandeburg54386462009-04-17 20:44:27 +00005449 netif_carrier_off(netdev);
5450
Auke Kok9a799d72007-09-15 14:07:45 -07005451 /* allocate transmit descriptors */
5452 err = ixgbe_setup_all_tx_resources(adapter);
5453 if (err)
5454 goto err_setup_tx;
5455
Auke Kok9a799d72007-09-15 14:07:45 -07005456 /* allocate receive descriptors */
5457 err = ixgbe_setup_all_rx_resources(adapter);
5458 if (err)
5459 goto err_setup_rx;
5460
5461 ixgbe_configure(adapter);
5462
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005463 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005464 if (err)
5465 goto err_req_irq;
5466
Auke Kok9a799d72007-09-15 14:07:45 -07005467 err = ixgbe_up_complete(adapter);
5468 if (err)
5469 goto err_up;
5470
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005471 netif_tx_start_all_queues(netdev);
5472
Auke Kok9a799d72007-09-15 14:07:45 -07005473 return 0;
5474
5475err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005476 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005477 ixgbe_free_irq(adapter);
5478err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005479err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005480 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005481err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005482 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005483 ixgbe_reset(adapter);
5484
5485 return err;
5486}
5487
5488/**
5489 * ixgbe_close - Disables a network interface
5490 * @netdev: network interface device structure
5491 *
5492 * Returns 0, this is not allowed to fail
5493 *
5494 * The close entry point is called when an interface is de-activated
5495 * by the OS. The hardware is still under the drivers control, but
5496 * needs to be disabled. A global MAC reset is issued to stop the
5497 * hardware, and all transmit and receive resources are freed.
5498 **/
5499static int ixgbe_close(struct net_device *netdev)
5500{
5501 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005502
5503 ixgbe_down(adapter);
5504 ixgbe_free_irq(adapter);
5505
Alexander Duycke4911d52011-05-11 07:18:52 +00005506 ixgbe_fdir_filter_exit(adapter);
5507
Auke Kok9a799d72007-09-15 14:07:45 -07005508 ixgbe_free_all_tx_resources(adapter);
5509 ixgbe_free_all_rx_resources(adapter);
5510
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005511 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005512
5513 return 0;
5514}
5515
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005516#ifdef CONFIG_PM
5517static int ixgbe_resume(struct pci_dev *pdev)
5518{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005519 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5520 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005521 u32 err;
5522
5523 pci_set_power_state(pdev, PCI_D0);
5524 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005525 /*
5526 * pci_restore_state clears dev->state_saved so call
5527 * pci_save_state to restore it.
5528 */
5529 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005530
5531 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005532 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005533 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005534 return err;
5535 }
5536 pci_set_master(pdev);
5537
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005538 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005539
5540 err = ixgbe_init_interrupt_scheme(adapter);
5541 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005542 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005543 return err;
5544 }
5545
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005546 ixgbe_reset(adapter);
5547
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005548 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5549
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005550 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005551 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005552 if (err)
5553 return err;
5554 }
5555
5556 netif_device_attach(netdev);
5557
5558 return 0;
5559}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005560#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005561
5562static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005563{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005564 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5565 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005566 struct ixgbe_hw *hw = &adapter->hw;
5567 u32 ctrl, fctrl;
5568 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005569#ifdef CONFIG_PM
5570 int retval = 0;
5571#endif
5572
5573 netif_device_detach(netdev);
5574
5575 if (netif_running(netdev)) {
5576 ixgbe_down(adapter);
5577 ixgbe_free_irq(adapter);
5578 ixgbe_free_all_tx_resources(adapter);
5579 ixgbe_free_all_rx_resources(adapter);
5580 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005581
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005582 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005583#ifdef CONFIG_DCB
5584 kfree(adapter->ixgbe_ieee_pfc);
5585 kfree(adapter->ixgbe_ieee_ets);
5586#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005587
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005588#ifdef CONFIG_PM
5589 retval = pci_save_state(pdev);
5590 if (retval)
5591 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005592
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005593#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005594 if (wufc) {
5595 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005596
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005597 /* turn on all-multi mode if wake on multicast is enabled */
5598 if (wufc & IXGBE_WUFC_MC) {
5599 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5600 fctrl |= IXGBE_FCTRL_MPE;
5601 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5602 }
5603
5604 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5605 ctrl |= IXGBE_CTRL_GIO_DIS;
5606 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5607
5608 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5609 } else {
5610 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5611 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5612 }
5613
Alexander Duyckbd508172010-11-16 19:27:03 -08005614 switch (hw->mac.type) {
5615 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005616 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005617 break;
5618 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005619 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005620 pci_wake_from_d3(pdev, !!wufc);
5621 break;
5622 default:
5623 break;
5624 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005625
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005626 *enable_wake = !!wufc;
5627
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628 ixgbe_release_hw_control(adapter);
5629
5630 pci_disable_device(pdev);
5631
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005632 return 0;
5633}
5634
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005635#ifdef CONFIG_PM
5636static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5637{
5638 int retval;
5639 bool wake;
5640
5641 retval = __ixgbe_shutdown(pdev, &wake);
5642 if (retval)
5643 return retval;
5644
5645 if (wake) {
5646 pci_prepare_to_sleep(pdev);
5647 } else {
5648 pci_wake_from_d3(pdev, false);
5649 pci_set_power_state(pdev, PCI_D3hot);
5650 }
5651
5652 return 0;
5653}
5654#endif /* CONFIG_PM */
5655
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005656static void ixgbe_shutdown(struct pci_dev *pdev)
5657{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005658 bool wake;
5659
5660 __ixgbe_shutdown(pdev, &wake);
5661
5662 if (system_state == SYSTEM_POWER_OFF) {
5663 pci_wake_from_d3(pdev, wake);
5664 pci_set_power_state(pdev, PCI_D3hot);
5665 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005666}
5667
5668/**
Auke Kok9a799d72007-09-15 14:07:45 -07005669 * ixgbe_update_stats - Update the board statistics counters.
5670 * @adapter: board private structure
5671 **/
5672void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5673{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005674 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005675 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005676 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005677 u64 total_mpc = 0;
5678 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005679 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5680 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5681 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005682
Don Skidmored08935c2010-06-11 13:20:29 +00005683 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5684 test_bit(__IXGBE_RESETTING, &adapter->state))
5685 return;
5686
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005687 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005688 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005689 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005690 for (i = 0; i < 16; i++)
5691 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005692 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005693 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005694 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5695 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005696 }
5697 adapter->rsc_total_count = rsc_count;
5698 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005699 }
5700
Alexander Duyck5b7da512010-11-16 19:26:50 -08005701 for (i = 0; i < adapter->num_rx_queues; i++) {
5702 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5703 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5704 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5705 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5706 bytes += rx_ring->stats.bytes;
5707 packets += rx_ring->stats.packets;
5708 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005709 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005710 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5711 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5712 netdev->stats.rx_bytes = bytes;
5713 netdev->stats.rx_packets = packets;
5714
5715 bytes = 0;
5716 packets = 0;
5717 /* gather some stats to the adapter struct that are per queue */
5718 for (i = 0; i < adapter->num_tx_queues; i++) {
5719 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5720 restart_queue += tx_ring->tx_stats.restart_queue;
5721 tx_busy += tx_ring->tx_stats.tx_busy;
5722 bytes += tx_ring->stats.bytes;
5723 packets += tx_ring->stats.packets;
5724 }
5725 adapter->restart_queue = restart_queue;
5726 adapter->tx_busy = tx_busy;
5727 netdev->stats.tx_bytes = bytes;
5728 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005729
Joe Perches7ca647b2010-09-07 21:35:40 +00005730 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005731 for (i = 0; i < 8; i++) {
5732 /* for packet buffers not used, the register should read 0 */
5733 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5734 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005735 hwstats->mpc[i] += mpc;
5736 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005737 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005738 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5739 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5740 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5741 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5742 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005743 switch (hw->mac.type) {
5744 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005745 hwstats->pxonrxc[i] +=
5746 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005747 break;
5748 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005749 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005750 hwstats->pxonrxc[i] +=
5751 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005752 break;
5753 default:
5754 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005755 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005756 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5757 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005758 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005759 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005760 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005761 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005762
John Fastabendc84d3242010-11-16 19:27:12 -08005763 ixgbe_update_xoff_received(adapter);
5764
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005765 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005766 switch (hw->mac.type) {
5767 case ixgbe_mac_82598EB:
5768 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005769 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5770 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5771 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5772 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005773 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005774 /* OS2BMC stats are X540 only*/
5775 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5776 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5777 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5778 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5779 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005780 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005781 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005782 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005783 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005784 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005785 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005786 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005787 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5788 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005789#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005790 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5791 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5792 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5793 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5794 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5795 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005796#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005797 break;
5798 default:
5799 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005800 }
Auke Kok9a799d72007-09-15 14:07:45 -07005801 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005802 hwstats->bprc += bprc;
5803 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005804 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005805 hwstats->mprc -= bprc;
5806 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5807 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5808 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5809 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5810 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5811 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5812 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5813 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005814 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005815 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005816 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005817 hwstats->lxofftxc += lxoff;
5818 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5819 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5820 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005821 /*
5822 * 82598 errata - tx of flow control packets is included in tx counters
5823 */
5824 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005825 hwstats->gptc -= xon_off_tot;
5826 hwstats->mptc -= xon_off_tot;
5827 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5828 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5829 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5830 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5831 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5832 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5833 hwstats->ptc64 -= xon_off_tot;
5834 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5835 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5836 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5837 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5838 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5839 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005840
5841 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005842 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005843
5844 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005845 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005846 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 netdev->stats.rx_length_errors = hwstats->rlec;
5848 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005849 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005850}
5851
5852/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005853 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5854 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005855 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005856static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005857{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005858 struct ixgbe_hw *hw = &adapter->hw;
5859 int i;
5860
Alexander Duyckd034acf2011-04-27 09:25:34 +00005861 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5862 return;
5863
5864 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5865
5866 /* if interface is down do nothing */
5867 if (test_bit(__IXGBE_DOWN, &adapter->state))
5868 return;
5869
5870 /* do nothing if we are not using signature filters */
5871 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5872 return;
5873
5874 adapter->fdir_overflow++;
5875
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005876 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5877 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005878 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005879 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005880 /* re-enable flow director interrupts */
5881 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005882 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005883 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005884 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005885 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005886}
5887
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005888/**
5889 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5890 * @adapter - pointer to the device adapter structure
5891 *
5892 * This function serves two purposes. First it strobes the interrupt lines
5893 * in order to make certain interrupts are occuring. Secondly it sets the
5894 * bits needed to check for TX hangs. As a result we should immediately
5895 * determine if a hang has occured.
5896 */
5897static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5898{
Auke Kok9a799d72007-09-15 14:07:45 -07005899 struct ixgbe_hw *hw = &adapter->hw;
5900 u64 eics = 0;
5901 int i;
5902
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005903 /* If we're down or resetting, just bail */
5904 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5905 test_bit(__IXGBE_RESETTING, &adapter->state))
5906 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005907
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005908 /* Force detection of hung controller */
5909 if (netif_carrier_ok(adapter->netdev)) {
5910 for (i = 0; i < adapter->num_tx_queues; i++)
5911 set_check_for_tx_hang(adapter->tx_ring[i]);
5912 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005913
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005914 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005915 /*
5916 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005917 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005918 * would set *both* EIMS and EICS for any bit in EIAM
5919 */
5920 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5921 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005922 } else {
5923 /* get one bit for every active tx/rx interrupt vector */
5924 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5925 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005926 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005927 eics |= ((u64)1 << i);
5928 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005929 }
5930
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005931 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005932 ixgbe_irq_rearm_queues(adapter, eics);
5933
Alexander Duyckfe49f042009-06-04 16:00:09 +00005934}
5935
5936/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005937 * ixgbe_watchdog_update_link - update the link status
5938 * @adapter - pointer to the device adapter structure
5939 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005940 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005941static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005942{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005943 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005944 u32 link_speed = adapter->link_speed;
5945 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005946 int i;
5947
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005948 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5949 return;
5950
5951 if (hw->mac.ops.check_link) {
5952 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005953 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005954 /* always assume link is up, if no check link function */
5955 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5956 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005957 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005958 if (link_up) {
5959 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5960 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5961 hw->mac.ops.fc_enable(hw, i);
5962 } else {
5963 hw->mac.ops.fc_enable(hw, 0);
5964 }
5965 }
5966
5967 if (link_up ||
5968 time_after(jiffies, (adapter->link_check_timeout +
5969 IXGBE_TRY_LINK_TIMEOUT))) {
5970 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5971 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5972 IXGBE_WRITE_FLUSH(hw);
5973 }
5974
5975 adapter->link_up = link_up;
5976 adapter->link_speed = link_speed;
5977}
5978
5979/**
5980 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5981 * print link up message
5982 * @adapter - pointer to the device adapter structure
5983 **/
5984static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5985{
5986 struct net_device *netdev = adapter->netdev;
5987 struct ixgbe_hw *hw = &adapter->hw;
5988 u32 link_speed = adapter->link_speed;
5989 bool flow_rx, flow_tx;
5990
5991 /* only continue if link was previously down */
5992 if (netif_carrier_ok(netdev))
5993 return;
5994
5995 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5996
5997 switch (hw->mac.type) {
5998 case ixgbe_mac_82598EB: {
5999 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6000 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6001 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6002 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6003 }
6004 break;
6005 case ixgbe_mac_X540:
6006 case ixgbe_mac_82599EB: {
6007 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6008 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6009 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6010 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6011 }
6012 break;
6013 default:
6014 flow_tx = false;
6015 flow_rx = false;
6016 break;
6017 }
6018 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6019 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6020 "10 Gbps" :
6021 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6022 "1 Gbps" :
6023 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6024 "100 Mbps" :
6025 "unknown speed"))),
6026 ((flow_rx && flow_tx) ? "RX/TX" :
6027 (flow_rx ? "RX" :
6028 (flow_tx ? "TX" : "None"))));
6029
6030 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006031 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006032}
6033
6034/**
6035 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6036 * print link down message
6037 * @adapter - pointer to the adapter structure
6038 **/
6039static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6040{
6041 struct net_device *netdev = adapter->netdev;
6042 struct ixgbe_hw *hw = &adapter->hw;
6043
6044 adapter->link_up = false;
6045 adapter->link_speed = 0;
6046
6047 /* only continue if link was up previously */
6048 if (!netif_carrier_ok(netdev))
6049 return;
6050
6051 /* poll for SFP+ cable when link is down */
6052 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6053 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6054
6055 e_info(drv, "NIC Link is Down\n");
6056 netif_carrier_off(netdev);
6057}
6058
6059/**
6060 * ixgbe_watchdog_flush_tx - flush queues on link down
6061 * @adapter - pointer to the device adapter structure
6062 **/
6063static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6064{
6065 int i;
6066 int some_tx_pending = 0;
6067
6068 if (!netif_carrier_ok(adapter->netdev)) {
6069 for (i = 0; i < adapter->num_tx_queues; i++) {
6070 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6071 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6072 some_tx_pending = 1;
6073 break;
6074 }
6075 }
6076
6077 if (some_tx_pending) {
6078 /* We've lost link, so the controller stops DMA,
6079 * but we've got queued Tx work that's never going
6080 * to get done, so reset controller to flush Tx.
6081 * (Do the reset outside of interrupt context).
6082 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006083 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006084 }
6085 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006086}
6087
Greg Rosea985b6c32010-11-18 03:02:52 +00006088static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6089{
6090 u32 ssvpc;
6091
6092 /* Do not perform spoof check for 82598 */
6093 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6094 return;
6095
6096 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6097
6098 /*
6099 * ssvpc register is cleared on read, if zero then no
6100 * spoofed packets in the last interval.
6101 */
6102 if (!ssvpc)
6103 return;
6104
6105 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6106}
6107
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006108/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006109 * ixgbe_watchdog_subtask - check and bring link up
6110 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006111 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006112static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006113{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006114 /* if interface is down do nothing */
6115 if (test_bit(__IXGBE_DOWN, &adapter->state))
6116 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006117
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006118 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006119
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006120 if (adapter->link_up)
6121 ixgbe_watchdog_link_is_up(adapter);
6122 else
6123 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006124
Greg Rosea985b6c32010-11-18 03:02:52 +00006125 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006126 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006127
6128 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006129}
6130
Alexander Duyck70864002011-04-27 09:13:56 +00006131/**
6132 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6133 * @adapter - the ixgbe adapter structure
6134 **/
6135static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6136{
6137 struct ixgbe_hw *hw = &adapter->hw;
6138 s32 err;
6139
6140 /* not searching for SFP so there is nothing to do here */
6141 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6142 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6143 return;
6144
6145 /* someone else is in init, wait until next service event */
6146 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6147 return;
6148
6149 err = hw->phy.ops.identify_sfp(hw);
6150 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6151 goto sfp_out;
6152
6153 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6154 /* If no cable is present, then we need to reset
6155 * the next time we find a good cable. */
6156 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6157 }
6158
6159 /* exit on error */
6160 if (err)
6161 goto sfp_out;
6162
6163 /* exit if reset not needed */
6164 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6165 goto sfp_out;
6166
6167 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6168
6169 /*
6170 * A module may be identified correctly, but the EEPROM may not have
6171 * support for that module. setup_sfp() will fail in that case, so
6172 * we should not allow that module to load.
6173 */
6174 if (hw->mac.type == ixgbe_mac_82598EB)
6175 err = hw->phy.ops.reset(hw);
6176 else
6177 err = hw->mac.ops.setup_sfp(hw);
6178
6179 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6180 goto sfp_out;
6181
6182 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6183 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6184
6185sfp_out:
6186 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6187
6188 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6189 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6190 e_dev_err("failed to initialize because an unsupported "
6191 "SFP+ module type was detected.\n");
6192 e_dev_err("Reload the driver after installing a "
6193 "supported module.\n");
6194 unregister_netdev(adapter->netdev);
6195 }
6196}
6197
6198/**
6199 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6200 * @adapter - the ixgbe adapter structure
6201 **/
6202static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6203{
6204 struct ixgbe_hw *hw = &adapter->hw;
6205 u32 autoneg;
6206 bool negotiation;
6207
6208 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6209 return;
6210
6211 /* someone else is in init, wait until next service event */
6212 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6213 return;
6214
6215 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6216
6217 autoneg = hw->phy.autoneg_advertised;
6218 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6219 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6220 hw->mac.autotry_restart = false;
6221 if (hw->mac.ops.setup_link)
6222 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6223
6224 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6225 adapter->link_check_timeout = jiffies;
6226 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6227}
6228
6229/**
6230 * ixgbe_service_timer - Timer Call-back
6231 * @data: pointer to adapter cast into an unsigned long
6232 **/
6233static void ixgbe_service_timer(unsigned long data)
6234{
6235 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6236 unsigned long next_event_offset;
6237
6238 /* poll faster when waiting for link */
6239 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6240 next_event_offset = HZ / 10;
6241 else
6242 next_event_offset = HZ * 2;
6243
6244 /* Reset the timer */
6245 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6246
6247 ixgbe_service_event_schedule(adapter);
6248}
6249
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006250static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6251{
6252 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6253 return;
6254
6255 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6256
6257 /* If we're already down or resetting, just bail */
6258 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6259 test_bit(__IXGBE_RESETTING, &adapter->state))
6260 return;
6261
6262 ixgbe_dump(adapter);
6263 netdev_err(adapter->netdev, "Reset adapter\n");
6264 adapter->tx_timeout_count++;
6265
6266 ixgbe_reinit_locked(adapter);
6267}
6268
Alexander Duyck70864002011-04-27 09:13:56 +00006269/**
6270 * ixgbe_service_task - manages and runs subtasks
6271 * @work: pointer to work_struct containing our data
6272 **/
6273static void ixgbe_service_task(struct work_struct *work)
6274{
6275 struct ixgbe_adapter *adapter = container_of(work,
6276 struct ixgbe_adapter,
6277 service_task);
6278
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006279 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006280 ixgbe_sfp_detection_subtask(adapter);
6281 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006282 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006283 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006284 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006285 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006286
6287 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006288}
6289
Alexander Duyck897ab152011-05-27 05:31:47 +00006290void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6291 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006292{
6293 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006294 u16 i = tx_ring->next_to_use;
6295
6296 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6297
6298 i++;
6299 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6300
6301 /* set bits to identify this as an advanced context descriptor */
6302 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6303
6304 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6305 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6306 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6307 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6308}
6309
6310static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6311 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6312{
Auke Kok9a799d72007-09-15 14:07:45 -07006313 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006314 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006315 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006316
Alexander Duyck897ab152011-05-27 05:31:47 +00006317 if (!skb_is_gso(skb))
6318 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006319
Alexander Duyck897ab152011-05-27 05:31:47 +00006320 if (skb_header_cloned(skb)) {
6321 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6322 if (err)
6323 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006324 }
6325
Alexander Duyck897ab152011-05-27 05:31:47 +00006326 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6327 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6328
6329 if (protocol == __constant_htons(ETH_P_IP)) {
6330 struct iphdr *iph = ip_hdr(skb);
6331 iph->tot_len = 0;
6332 iph->check = 0;
6333 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6334 iph->daddr, 0,
6335 IPPROTO_TCP,
6336 0);
6337 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6338 } else if (skb_is_gso_v6(skb)) {
6339 ipv6_hdr(skb)->payload_len = 0;
6340 tcp_hdr(skb)->check =
6341 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6342 &ipv6_hdr(skb)->daddr,
6343 0, IPPROTO_TCP, 0);
6344 }
6345
6346 l4len = tcp_hdrlen(skb);
6347 *hdr_len = skb_transport_offset(skb) + l4len;
6348
6349 /* mss_l4len_id: use 1 as index for TSO */
6350 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6351 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6352 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6353
6354 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6355 vlan_macip_lens = skb_network_header_len(skb);
6356 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6357 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6358
6359 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6360 mss_l4len_idx);
6361
6362 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006363}
6364
Alexander Duyck897ab152011-05-27 05:31:47 +00006365static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006366 struct sk_buff *skb, u32 tx_flags,
6367 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006368{
Alexander Duyck897ab152011-05-27 05:31:47 +00006369 u32 vlan_macip_lens = 0;
6370 u32 mss_l4len_idx = 0;
6371 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006372
Alexander Duyck897ab152011-05-27 05:31:47 +00006373 if (skb->ip_summed != CHECKSUM_PARTIAL) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006374 if (!(tx_flags & IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck897ab152011-05-27 05:31:47 +00006375 return false;
6376 } else {
6377 u8 l4_hdr = 0;
6378 switch (protocol) {
6379 case __constant_htons(ETH_P_IP):
6380 vlan_macip_lens |= skb_network_header_len(skb);
6381 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6382 l4_hdr = ip_hdr(skb)->protocol;
6383 break;
6384 case __constant_htons(ETH_P_IPV6):
6385 vlan_macip_lens |= skb_network_header_len(skb);
6386 l4_hdr = ipv6_hdr(skb)->nexthdr;
6387 break;
6388 default:
6389 if (unlikely(net_ratelimit())) {
6390 dev_warn(tx_ring->dev,
6391 "partial checksum but proto=%x!\n",
6392 skb->protocol);
6393 }
6394 break;
6395 }
Auke Kok9a799d72007-09-15 14:07:45 -07006396
Alexander Duyck897ab152011-05-27 05:31:47 +00006397 switch (l4_hdr) {
6398 case IPPROTO_TCP:
6399 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6400 mss_l4len_idx = tcp_hdrlen(skb) <<
6401 IXGBE_ADVTXD_L4LEN_SHIFT;
6402 break;
6403 case IPPROTO_SCTP:
6404 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6405 mss_l4len_idx = sizeof(struct sctphdr) <<
6406 IXGBE_ADVTXD_L4LEN_SHIFT;
6407 break;
6408 case IPPROTO_UDP:
6409 mss_l4len_idx = sizeof(struct udphdr) <<
6410 IXGBE_ADVTXD_L4LEN_SHIFT;
6411 break;
6412 default:
6413 if (unlikely(net_ratelimit())) {
6414 dev_warn(tx_ring->dev,
6415 "partial checksum but l4 proto=%x!\n",
6416 skb->protocol);
6417 }
6418 break;
6419 }
Auke Kok9a799d72007-09-15 14:07:45 -07006420 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006421
Alexander Duyck897ab152011-05-27 05:31:47 +00006422 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6423 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6424
6425 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6426 type_tucmd, mss_l4len_idx);
6427
6428 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006429}
6430
Alexander Duyckd3d00232011-07-15 02:31:25 +00006431static __le32 ixgbe_tx_cmd_type(u32 tx_flags)
6432{
6433 /* set type for advanced descriptor with frame checksum insertion */
6434 __le32 cmd_type = cpu_to_le32(IXGBE_ADVTXD_DTYP_DATA |
6435 IXGBE_ADVTXD_DCMD_IFCS |
6436 IXGBE_ADVTXD_DCMD_DEXT);
6437
6438 /* set HW vlan bit if vlan is present */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006439 if (tx_flags & IXGBE_TX_FLAGS_HW_VLAN)
Alexander Duyckd3d00232011-07-15 02:31:25 +00006440 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_VLE);
6441
6442 /* set segmentation enable bits for TSO/FSO */
6443#ifdef IXGBE_FCOE
6444 if ((tx_flags & IXGBE_TX_FLAGS_TSO) || (tx_flags & IXGBE_TX_FLAGS_FSO))
6445#else
6446 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6447#endif
6448 cmd_type |= cpu_to_le32(IXGBE_ADVTXD_DCMD_TSE);
6449
6450 return cmd_type;
6451}
6452
6453static __le32 ixgbe_tx_olinfo_status(u32 tx_flags, unsigned int paylen)
6454{
6455 __le32 olinfo_status =
6456 cpu_to_le32(paylen << IXGBE_ADVTXD_PAYLEN_SHIFT);
6457
6458 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6459 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM |
6460 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6461 /* enble IPv4 checksum for TSO */
6462 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6463 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_IXSM);
6464 }
6465
6466 /* enable L4 checksum for TSO and TX checksum offload */
6467 if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6468 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_POPTS_TXSM);
6469
6470#ifdef IXGBE_FCOE
6471 /* use index 1 context for FCOE/FSO */
6472 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6473 olinfo_status |= cpu_to_le32(IXGBE_ADVTXD_CC |
6474 (1 << IXGBE_ADVTXD_IDX_SHIFT));
6475
6476#endif
6477 return olinfo_status;
6478}
6479
6480#define IXGBE_TXD_CMD (IXGBE_TXD_CMD_EOP | \
6481 IXGBE_TXD_CMD_RS)
6482
6483static void ixgbe_tx_map(struct ixgbe_ring *tx_ring,
6484 struct sk_buff *skb,
6485 struct ixgbe_tx_buffer *first,
6486 u32 tx_flags,
6487 const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006488{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006489 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006490 struct ixgbe_tx_buffer *tx_buffer_info;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006491 union ixgbe_adv_tx_desc *tx_desc;
6492 dma_addr_t dma;
6493 __le32 cmd_type, olinfo_status;
6494 struct skb_frag_struct *frag;
6495 unsigned int f = 0;
6496 unsigned int data_len = skb->data_len;
6497 unsigned int size = skb_headlen(skb);
6498 u32 offset = 0;
6499 u32 paylen = skb->len - hdr_len;
6500 u16 i = tx_ring->next_to_use;
6501 u16 gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006502
Alexander Duyckd3d00232011-07-15 02:31:25 +00006503#ifdef IXGBE_FCOE
6504 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6505 if (data_len >= sizeof(struct fcoe_crc_eof)) {
6506 data_len -= sizeof(struct fcoe_crc_eof);
6507 } else {
6508 size -= sizeof(struct fcoe_crc_eof) - data_len;
6509 data_len = 0;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006510 }
Auke Kok9a799d72007-09-15 14:07:45 -07006511 }
6512
Alexander Duyckd3d00232011-07-15 02:31:25 +00006513#endif
6514 dma = dma_map_single(dev, skb->data, size, DMA_TO_DEVICE);
6515 if (dma_mapping_error(dev, dma))
6516 goto dma_error;
6517
6518 cmd_type = ixgbe_tx_cmd_type(tx_flags);
6519 olinfo_status = ixgbe_tx_olinfo_status(tx_flags, paylen);
6520
6521 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
6522
6523 for (;;) {
6524 while (size > IXGBE_MAX_DATA_PER_TXD) {
6525 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6526 tx_desc->read.cmd_type_len =
6527 cmd_type | cpu_to_le32(IXGBE_MAX_DATA_PER_TXD);
6528 tx_desc->read.olinfo_status = olinfo_status;
6529
6530 offset += IXGBE_MAX_DATA_PER_TXD;
6531 size -= IXGBE_MAX_DATA_PER_TXD;
6532
6533 tx_desc++;
6534 i++;
6535 if (i == tx_ring->count) {
6536 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6537 i = 0;
6538 }
6539 }
6540
6541 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6542 tx_buffer_info->length = offset + size;
6543 tx_buffer_info->tx_flags = tx_flags;
6544 tx_buffer_info->dma = dma;
6545
6546 tx_desc->read.buffer_addr = cpu_to_le64(dma + offset);
6547 tx_desc->read.cmd_type_len = cmd_type | cpu_to_le32(size);
6548 tx_desc->read.olinfo_status = olinfo_status;
6549
6550 if (!data_len)
6551 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006552
6553 frag = &skb_shinfo(skb)->frags[f];
Alexander Duyckd3d00232011-07-15 02:31:25 +00006554#ifdef IXGBE_FCOE
6555 size = min_t(unsigned int, data_len, frag->size);
6556#else
6557 size = frag->size;
6558#endif
6559 data_len -= size;
6560 f++;
Auke Kok9a799d72007-09-15 14:07:45 -07006561
Alexander Duyckd3d00232011-07-15 02:31:25 +00006562 offset = 0;
6563 tx_flags |= IXGBE_TX_FLAGS_MAPPED_AS_PAGE;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006564
Alexander Duyckd3d00232011-07-15 02:31:25 +00006565 dma = dma_map_page(dev, frag->page, frag->page_offset,
6566 size, DMA_TO_DEVICE);
6567 if (dma_mapping_error(dev, dma))
6568 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006569
Alexander Duyckd3d00232011-07-15 02:31:25 +00006570 tx_desc++;
6571 i++;
6572 if (i == tx_ring->count) {
6573 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, 0);
6574 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006575 }
6576 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006577
Alexander Duyckd3d00232011-07-15 02:31:25 +00006578 tx_desc->read.cmd_type_len |= cpu_to_le32(IXGBE_TXD_CMD);
6579
6580 i++;
6581 if (i == tx_ring->count)
6582 i = 0;
6583
6584 tx_ring->next_to_use = i;
6585
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006586 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6587 gso_segs = skb_shinfo(skb)->gso_segs;
6588#ifdef IXGBE_FCOE
6589 /* adjust for FCoE Sequence Offload */
6590 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6591 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6592 skb_shinfo(skb)->gso_size);
6593#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006594 else
6595 gso_segs = 1;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006596
6597 /* multiply data chunks by size of headers */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006598 tx_buffer_info->bytecount = paylen + (gso_segs * hdr_len);
6599 tx_buffer_info->gso_segs = gso_segs;
6600 tx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07006601
Alexander Duyckd3d00232011-07-15 02:31:25 +00006602 /* set the timestamp */
6603 first->time_stamp = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07006604
6605 /*
6606 * Force memory writes to complete before letting h/w
6607 * know there are new descriptors to fetch. (Only
6608 * applicable for weak-ordered memory model archs,
6609 * such as IA-64).
6610 */
6611 wmb();
6612
Alexander Duyckd3d00232011-07-15 02:31:25 +00006613 /* set next_to_watch value indicating a packet is present */
6614 first->next_to_watch = tx_desc;
6615
6616 /* notify HW of packet */
Alexander Duyck84ea2592010-11-16 19:26:49 -08006617 writel(i, tx_ring->tail);
Alexander Duyckd3d00232011-07-15 02:31:25 +00006618
6619 return;
6620dma_error:
6621 dev_err(dev, "TX DMA map failed\n");
6622
6623 /* clear dma mappings for failed tx_buffer_info map */
6624 for (;;) {
6625 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6626 ixgbe_unmap_tx_resource(tx_ring, tx_buffer_info);
6627 if (tx_buffer_info == first)
6628 break;
6629 if (i == 0)
6630 i = tx_ring->count;
6631 i--;
6632 }
6633
6634 dev_kfree_skb_any(skb);
6635
6636 tx_ring->next_to_use = i;
Auke Kok9a799d72007-09-15 14:07:45 -07006637}
6638
Alexander Duyck69830522011-01-06 14:29:58 +00006639static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6640 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006641{
Alexander Duyck69830522011-01-06 14:29:58 +00006642 struct ixgbe_q_vector *q_vector = ring->q_vector;
6643 union ixgbe_atr_hash_dword input = { .dword = 0 };
6644 union ixgbe_atr_hash_dword common = { .dword = 0 };
6645 union {
6646 unsigned char *network;
6647 struct iphdr *ipv4;
6648 struct ipv6hdr *ipv6;
6649 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006650 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006651 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006652
Alexander Duyck69830522011-01-06 14:29:58 +00006653 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6654 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006655 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006656
Alexander Duyck69830522011-01-06 14:29:58 +00006657 /* do nothing if sampling is disabled */
6658 if (!ring->atr_sample_rate)
6659 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006660
Alexander Duyck69830522011-01-06 14:29:58 +00006661 ring->atr_count++;
6662
6663 /* snag network header to get L4 type and address */
6664 hdr.network = skb_network_header(skb);
6665
6666 /* Currently only IPv4/IPv6 with TCP is supported */
6667 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6668 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6669 (protocol != __constant_htons(ETH_P_IP) ||
6670 hdr.ipv4->protocol != IPPROTO_TCP))
6671 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006672
6673 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006674
Alexander Duyck66f32a82011-06-29 05:43:22 +00006675 /* skip this packet since it is invalid or the socket is closing */
6676 if (!th || th->fin)
Alexander Duyck69830522011-01-06 14:29:58 +00006677 return;
6678
6679 /* sample on all syn packets or once every atr sample count */
6680 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6681 return;
6682
6683 /* reset sample count */
6684 ring->atr_count = 0;
6685
6686 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6687
6688 /*
6689 * src and dst are inverted, think how the receiver sees them
6690 *
6691 * The input is broken into two sections, a non-compressed section
6692 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6693 * is XORed together and stored in the compressed dword.
6694 */
6695 input.formatted.vlan_id = vlan_id;
6696
6697 /*
6698 * since src port and flex bytes occupy the same word XOR them together
6699 * and write the value to source port portion of compressed dword
6700 */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006701 if (tx_flags & (IXGBE_TX_FLAGS_SW_VLAN | IXGBE_TX_FLAGS_HW_VLAN))
Alexander Duyck69830522011-01-06 14:29:58 +00006702 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6703 else
6704 common.port.src ^= th->dest ^ protocol;
6705 common.port.dst ^= th->source;
6706
6707 if (protocol == __constant_htons(ETH_P_IP)) {
6708 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6709 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6710 } else {
6711 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6712 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6713 hdr.ipv6->saddr.s6_addr32[1] ^
6714 hdr.ipv6->saddr.s6_addr32[2] ^
6715 hdr.ipv6->saddr.s6_addr32[3] ^
6716 hdr.ipv6->daddr.s6_addr32[0] ^
6717 hdr.ipv6->daddr.s6_addr32[1] ^
6718 hdr.ipv6->daddr.s6_addr32[2] ^
6719 hdr.ipv6->daddr.s6_addr32[3];
6720 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006721
6722 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006723 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6724 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006725}
6726
Alexander Duyck63544e92011-05-27 05:31:42 +00006727static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006728{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006729 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006730 /* Herbert's original patch had:
6731 * smp_mb__after_netif_stop_queue();
6732 * but since that doesn't exist yet, just open code it. */
6733 smp_mb();
6734
6735 /* We need to check again in a case another CPU has just
6736 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006737 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006738 return -EBUSY;
6739
6740 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006741 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006742 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006743 return 0;
6744}
6745
Alexander Duyck82d4e462011-06-11 01:44:58 +00006746static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006747{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006748 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006749 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006750 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006751}
6752
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006753static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6754{
6755 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006756 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6757 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006758#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006759 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006760
John Fastabende5b64632011-03-08 03:44:52 +00006761 if (((protocol == htons(ETH_P_FCOE)) ||
6762 (protocol == htons(ETH_P_FIP))) &&
6763 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6764 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6765 txq += adapter->ring_feature[RING_F_FCOE].mask;
6766 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006767 }
6768#endif
6769
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006770 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6771 while (unlikely(txq >= dev->real_num_tx_queues))
6772 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006773 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006774 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006775
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006776 return skb_tx_hash(dev, skb);
6777}
6778
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006779netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006780 struct ixgbe_adapter *adapter,
6781 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006782{
Alexander Duyckd3d00232011-07-15 02:31:25 +00006783 struct ixgbe_tx_buffer *first;
Yi Zou5f715822009-12-03 11:32:44 +00006784 int tso;
Alexander Duyckd3d00232011-07-15 02:31:25 +00006785 u32 tx_flags = 0;
Alexander Duycka535c302011-05-27 05:31:52 +00006786#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6787 unsigned short f;
6788#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006789 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Alexander Duyck66f32a82011-06-29 05:43:22 +00006790 __be16 protocol = skb->protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006791 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006792
Alexander Duycka535c302011-05-27 05:31:52 +00006793 /*
6794 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6795 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6796 * + 2 desc gap to keep tail from touching head,
6797 * + 1 desc for context descriptor,
6798 * otherwise try next time
6799 */
6800#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6801 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6802 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6803#else
6804 count += skb_shinfo(skb)->nr_frags;
6805#endif
6806 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6807 tx_ring->tx_stats.tx_busy++;
6808 return NETDEV_TX_BUSY;
6809 }
6810
Alexander Duyck66f32a82011-06-29 05:43:22 +00006811 /* if we have a HW VLAN tag being added default to the HW one */
Jesse Grosseab6d182010-10-20 13:56:03 +00006812 if (vlan_tx_tag_present(skb)) {
Alexander Duyck66f32a82011-06-29 05:43:22 +00006813 tx_flags |= vlan_tx_tag_get(skb) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6814 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6815 /* else if it is a SW VLAN check the next protocol and store the tag */
6816 } else if (protocol == __constant_htons(ETH_P_8021Q)) {
6817 struct vlan_hdr *vhdr, _vhdr;
6818 vhdr = skb_header_pointer(skb, ETH_HLEN, sizeof(_vhdr), &_vhdr);
6819 if (!vhdr)
6820 goto out_drop;
6821
6822 protocol = vhdr->h_vlan_encapsulated_proto;
6823 tx_flags |= ntohs(vhdr->h_vlan_TCI) << IXGBE_TX_FLAGS_VLAN_SHIFT;
6824 tx_flags |= IXGBE_TX_FLAGS_SW_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006825 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006826
Alexander Duyck66f32a82011-06-29 05:43:22 +00006827 if ((adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
6828 skb->priority != TC_PRIO_CONTROL) {
6829 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
6830 tx_flags |= tx_ring->dcb_tc <<
6831 IXGBE_TX_FLAGS_VLAN_PRIO_SHIFT;
6832 if (tx_flags & IXGBE_TX_FLAGS_SW_VLAN) {
6833 struct vlan_ethhdr *vhdr;
6834 if (skb_header_cloned(skb) &&
6835 pskb_expand_head(skb, 0, 0, GFP_ATOMIC))
6836 goto out_drop;
6837 vhdr = (struct vlan_ethhdr *)skb->data;
6838 vhdr->h_vlan_TCI = htons(tx_flags >>
6839 IXGBE_TX_FLAGS_VLAN_SHIFT);
6840 } else {
6841 tx_flags |= IXGBE_TX_FLAGS_HW_VLAN;
6842 }
6843 }
Alexander Duycka535c302011-05-27 05:31:52 +00006844
Alexander Duycka535c302011-05-27 05:31:52 +00006845 /* record the location of the first descriptor for this packet */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006846 first = &tx_ring->tx_buffer_info[tx_ring->next_to_use];
Alexander Duycka535c302011-05-27 05:31:52 +00006847
Yi Zoueacd73f2009-05-13 13:11:06 +00006848#ifdef IXGBE_FCOE
Alexander Duyck66f32a82011-06-29 05:43:22 +00006849 /* setup tx offload for FCoE */
6850 if ((protocol == __constant_htons(ETH_P_FCOE)) &&
6851 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
Alexander Duyck897ab152011-05-27 05:31:47 +00006852 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6853 if (tso < 0)
6854 goto out_drop;
6855 else if (tso)
Alexander Duyck66f32a82011-06-29 05:43:22 +00006856 tx_flags |= IXGBE_TX_FLAGS_FSO |
6857 IXGBE_TX_FLAGS_FCOE;
6858 else
6859 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Auke Kok9a799d72007-09-15 14:07:45 -07006860
Alexander Duyck66f32a82011-06-29 05:43:22 +00006861 goto xmit_fcoe;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006862 }
Auke Kok9a799d72007-09-15 14:07:45 -07006863
Auke Kok9a799d72007-09-15 14:07:45 -07006864#endif /* IXGBE_FCOE */
Alexander Duyck66f32a82011-06-29 05:43:22 +00006865 /* setup IPv4/IPv6 offloads */
6866 if (protocol == __constant_htons(ETH_P_IP))
6867 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006868
Alexander Duyck66f32a82011-06-29 05:43:22 +00006869 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6870 if (tso < 0)
Auke Kok9a799d72007-09-15 14:07:45 -07006871 goto out_drop;
Alexander Duyck66f32a82011-06-29 05:43:22 +00006872 else if (tso)
6873 tx_flags |= IXGBE_TX_FLAGS_TSO;
6874 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
6875 tx_flags |= IXGBE_TX_FLAGS_CSUM;
6876
6877 /* add the ATR filter if ATR is on */
6878 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6879 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
6880
6881#ifdef IXGBE_FCOE
6882xmit_fcoe:
6883#endif /* IXGBE_FCOE */
Alexander Duyckd3d00232011-07-15 02:31:25 +00006884 ixgbe_tx_map(tx_ring, skb, first, tx_flags, hdr_len);
6885
6886 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006887
6888 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006889
6890out_drop:
6891 dev_kfree_skb_any(skb);
6892 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006893}
6894
6895static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6896{
6897 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6898 struct ixgbe_ring *tx_ring;
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006899
Auke Kok9a799d72007-09-15 14:07:45 -07006900 tx_ring = adapter->tx_ring[skb->queue_mapping];
6901 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
6902}
6903
6904/**
6905 * ixgbe_set_mac - Change the Ethernet Address of the NIC
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006906 * @netdev: network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07006907 * @p: pointer to an address structure
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006908 *
Auke Kok9a799d72007-09-15 14:07:45 -07006909 * Returns 0 on success, negative on failure
6910 **/
6911static int ixgbe_set_mac(struct net_device *netdev, void *p)
6912{
Ben Hutchings6b73e102009-04-29 08:08:58 +00006913 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6914 struct ixgbe_hw *hw = &adapter->hw;
6915 struct sockaddr *addr = p;
6916
6917 if (!is_valid_ether_addr(addr->sa_data))
6918 return -EADDRNOTAVAIL;
6919
6920 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
6921 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
6922
6923 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6924 IXGBE_RAH_AV);
6925
6926 return 0;
6927}
6928
6929static int
6930ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6931{
6932 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6933 struct ixgbe_hw *hw = &adapter->hw;
6934 u16 value;
6935 int rc;
6936
6937 if (prtad != hw->phy.mdio.prtad)
6938 return -EINVAL;
6939 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6940 if (!rc)
6941 rc = value;
6942 return rc;
6943}
6944
6945static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6946 u16 addr, u16 value)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006947{
6948 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jiri Pirko31278e72009-06-17 01:12:19 +00006949 struct ixgbe_hw *hw = &adapter->hw;
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006950
6951 if (prtad != hw->phy.mdio.prtad)
6952 return -EINVAL;
6953 return hw->phy.ops.write_reg(hw, addr, devad, value);
6954}
6955
6956static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6957{
6958 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6959
6960 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6961}
6962
6963/**
6964 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
6965 * netdev->dev_addrs
6966 * @netdev: network interface device structure
6967 *
6968 * Returns non-zero on failure
6969 **/
Jiri Pirko31278e72009-06-17 01:12:19 +00006970static int ixgbe_add_sanmac_netdev(struct net_device *dev)
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006971{
6972 int err = 0;
6973 struct ixgbe_adapter *adapter = netdev_priv(dev);
6974 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6975
6976 if (is_valid_ether_addr(mac->san_addr)) {
6977 rtnl_lock();
6978 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6979 rtnl_unlock();
6980 }
6981 return err;
6982}
6983
6984/**
6985 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
6986 * netdev->dev_addrs
6987 * @netdev: network interface device structure
6988 *
Auke Kok9a799d72007-09-15 14:07:45 -07006989 * Returns non-zero on failure
6990 **/
6991static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6992{
6993 int err = 0;
6994 struct ixgbe_adapter *adapter = netdev_priv(dev);
6995 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6996
6997 if (is_valid_ether_addr(mac->san_addr)) {
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006998 rtnl_lock();
Auke Kok9a799d72007-09-15 14:07:45 -07006999 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007000 rtnl_unlock();
7001 }
7002 return err;
7003}
Auke Kok9a799d72007-09-15 14:07:45 -07007004
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007005#ifdef CONFIG_NET_POLL_CONTROLLER
7006/*
7007 * Polling 'interrupt' - used by things like netconsole to send skbs
7008 * without having to re-enable interrupts. It's not called while
7009 * the interrupt routine is executing.
7010 */
7011static void ixgbe_netpoll(struct net_device *netdev)
7012{
7013 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007014 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007015
7016 /* if interface is down do nothing */
7017 if (test_bit(__IXGBE_DOWN, &adapter->state))
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007018 return;
7019
7020 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Stephen Hemminger00829822008-11-20 20:14:53 -08007021 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007022 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Chris Leeche90d4002009-03-10 16:00:24 +00007023 for (i = 0; i < num_q_vectors; i++) {
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007024 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7025 ixgbe_msix_clean_many(0, q_vector);
7026 }
7027 } else {
7028 ixgbe_intr(adapter->pdev->irq, netdev);
7029 }
7030 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Eric Dumazetde1036b2010-10-20 23:00:04 +00007031}
7032#endif
7033
7034static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7035 struct rtnl_link_stats64 *stats)
7036{
7037 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7038 int i;
Eric Dumazet1a515022010-11-16 19:26:42 -08007039
Eric Dumazetde1036b2010-10-20 23:00:04 +00007040 rcu_read_lock();
7041 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007042 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007043 u64 bytes, packets;
7044 unsigned int start;
7045
Eric Dumazet1a515022010-11-16 19:26:42 -08007046 if (ring) {
7047 do {
7048 start = u64_stats_fetch_begin_bh(&ring->syncp);
7049 packets = ring->stats.packets;
7050 bytes = ring->stats.bytes;
7051 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7052 stats->rx_packets += packets;
7053 stats->rx_bytes += bytes;
7054 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007055 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007056
7057 for (i = 0; i < adapter->num_tx_queues; i++) {
7058 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7059 u64 bytes, packets;
7060 unsigned int start;
7061
7062 if (ring) {
7063 do {
7064 start = u64_stats_fetch_begin_bh(&ring->syncp);
7065 packets = ring->stats.packets;
7066 bytes = ring->stats.bytes;
7067 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7068 stats->tx_packets += packets;
7069 stats->tx_bytes += bytes;
7070 }
7071 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007072 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007073 /* following stats updated by ixgbe_watchdog_task() */
7074 stats->multicast = netdev->stats.multicast;
7075 stats->rx_errors = netdev->stats.rx_errors;
7076 stats->rx_length_errors = netdev->stats.rx_length_errors;
7077 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7078 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7079 return stats;
7080}
7081
John Fastabend8b1c0b22011-05-03 02:26:48 +00007082/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7083 * #adapter: pointer to ixgbe_adapter
7084 * @tc: number of traffic classes currently enabled
7085 *
7086 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7087 * 802.1Q priority maps to a packet buffer that exists.
7088 */
7089static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7090{
7091 struct ixgbe_hw *hw = &adapter->hw;
7092 u32 reg, rsave;
7093 int i;
7094
7095 /* 82598 have a static priority to TC mapping that can not
7096 * be changed so no validation is needed.
7097 */
7098 if (hw->mac.type == ixgbe_mac_82598EB)
7099 return;
7100
7101 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7102 rsave = reg;
7103
7104 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7105 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7106
7107 /* If up2tc is out of bounds default to zero */
7108 if (up2tc > tc)
7109 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7110 }
7111
7112 if (reg != rsave)
7113 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7114
7115 return;
7116}
7117
7118
7119/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7120 * classes.
7121 *
7122 * @netdev: net device to configure
7123 * @tc: number of traffic classes to enable
7124 */
7125int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7126{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007127 struct ixgbe_adapter *adapter = netdev_priv(dev);
7128 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007129
7130 /* If DCB is anabled do not remove traffic classes, multiple
7131 * traffic classes are required to implement DCB
7132 */
7133 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7134 return 0;
7135
7136 /* Hardware supports up to 8 traffic classes */
7137 if (tc > MAX_TRAFFIC_CLASS ||
7138 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7139 return -EINVAL;
7140
7141 /* Hardware has to reinitialize queues and interrupts to
7142 * match packet buffer alignment. Unfortunantly, the
7143 * hardware is not flexible enough to do this dynamically.
7144 */
7145 if (netif_running(dev))
7146 ixgbe_close(dev);
7147 ixgbe_clear_interrupt_scheme(adapter);
7148
7149 if (tc)
7150 netdev_set_num_tc(dev, tc);
7151 else
7152 netdev_reset_tc(dev);
7153
John Fastabend8b1c0b22011-05-03 02:26:48 +00007154 ixgbe_init_interrupt_scheme(adapter);
7155 ixgbe_validate_rtr(adapter, tc);
7156 if (netif_running(dev))
7157 ixgbe_open(dev);
7158
7159 return 0;
7160}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007161
Don Skidmore082757a2011-07-21 05:55:00 +00007162void ixgbe_do_reset(struct net_device *netdev)
7163{
7164 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7165
7166 if (netif_running(netdev))
7167 ixgbe_reinit_locked(adapter);
7168 else
7169 ixgbe_reset(adapter);
7170}
7171
7172static u32 ixgbe_fix_features(struct net_device *netdev, u32 data)
7173{
7174 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7175
7176#ifdef CONFIG_DCB
7177 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED)
7178 data &= ~NETIF_F_HW_VLAN_RX;
7179#endif
7180
7181 /* return error if RXHASH is being enabled when RSS is not supported */
7182 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7183 data &= ~NETIF_F_RXHASH;
7184
7185 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7186 if (!(data & NETIF_F_RXCSUM))
7187 data &= ~NETIF_F_LRO;
7188
7189 /* Turn off LRO if not RSC capable or invalid ITR settings */
7190 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)) {
7191 data &= ~NETIF_F_LRO;
7192 } else if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
7193 (adapter->rx_itr_setting != 1 &&
7194 adapter->rx_itr_setting > IXGBE_MAX_RSC_INT_RATE)) {
7195 data &= ~NETIF_F_LRO;
7196 e_info(probe, "rx-usecs set too low, not enabling RSC\n");
7197 }
7198
7199 return data;
7200}
7201
7202static int ixgbe_set_features(struct net_device *netdev, u32 data)
7203{
7204 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7205 bool need_reset = false;
7206
7207 /* If Rx checksum is disabled, then RSC/LRO should also be disabled */
7208 if (!(data & NETIF_F_RXCSUM))
7209 adapter->flags &= ~IXGBE_FLAG_RX_CSUM_ENABLED;
7210 else
7211 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
7212
7213 /* Make sure RSC matches LRO, reset if change */
7214 if (!!(data & NETIF_F_LRO) !=
7215 !!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)) {
7216 adapter->flags2 ^= IXGBE_FLAG2_RSC_ENABLED;
7217 switch (adapter->hw.mac.type) {
7218 case ixgbe_mac_X540:
7219 case ixgbe_mac_82599EB:
7220 need_reset = true;
7221 break;
7222 default:
7223 break;
7224 }
7225 }
7226
7227 /*
7228 * Check if Flow Director n-tuple support was enabled or disabled. If
7229 * the state changed, we need to reset.
7230 */
7231 if (!(adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
7232 /* turn off ATR, enable perfect filters and reset */
7233 if (data & NETIF_F_NTUPLE) {
7234 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
7235 adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7236 need_reset = true;
7237 }
7238 } else if (!(data & NETIF_F_NTUPLE)) {
7239 /* turn off Flow Director, set ATR and reset */
7240 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
7241 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
7242 !(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7243 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
7244 need_reset = true;
7245 }
7246
7247 if (need_reset)
7248 ixgbe_do_reset(netdev);
7249
7250 return 0;
7251
7252}
7253
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007254static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007255 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007256 .ndo_stop = ixgbe_close,
7257 .ndo_start_xmit = ixgbe_xmit_frame,
7258 .ndo_select_queue = ixgbe_select_queue,
7259 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007260 .ndo_validate_addr = eth_validate_addr,
7261 .ndo_set_mac_address = ixgbe_set_mac,
7262 .ndo_change_mtu = ixgbe_change_mtu,
7263 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007264 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7265 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007266 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007267 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7268 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7269 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7270 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007271 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007272 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007273#ifdef CONFIG_NET_POLL_CONTROLLER
7274 .ndo_poll_controller = ixgbe_netpoll,
7275#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007276#ifdef IXGBE_FCOE
7277 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007278 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007279 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007280 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7281 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007282 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007283#endif /* IXGBE_FCOE */
Don Skidmore082757a2011-07-21 05:55:00 +00007284 .ndo_set_features = ixgbe_set_features,
7285 .ndo_fix_features = ixgbe_fix_features,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007286};
7287
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007288static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7289 const struct ixgbe_info *ii)
7290{
7291#ifdef CONFIG_PCI_IOV
7292 struct ixgbe_hw *hw = &adapter->hw;
7293 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007294 int num_vf_macvlans, i;
7295 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007296
Greg Rose3377eba792010-12-07 08:16:45 +00007297 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007298 return;
7299
7300 /* The 82599 supports up to 64 VFs per physical function
7301 * but this implementation limits allocation to 63 so that
7302 * basic networking resources are still available to the
7303 * physical function
7304 */
7305 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7306 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7307 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7308 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007309 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007310 goto err_novfs;
7311 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007312
7313 num_vf_macvlans = hw->mac.num_rar_entries -
7314 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7315
7316 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7317 sizeof(struct vf_macvlans),
7318 GFP_KERNEL);
7319 if (mv_list) {
7320 /* Initialize list of VF macvlans */
7321 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7322 for (i = 0; i < num_vf_macvlans; i++) {
7323 mv_list->vf = -1;
7324 mv_list->free = true;
7325 mv_list->rar_entry = hw->mac.num_rar_entries -
7326 (i + adapter->num_vfs + 1);
7327 list_add(&mv_list->l, &adapter->vf_mvs.l);
7328 mv_list++;
7329 }
7330 }
7331
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007332 /* If call to enable VFs succeeded then allocate memory
7333 * for per VF control structures.
7334 */
7335 adapter->vfinfo =
7336 kcalloc(adapter->num_vfs,
7337 sizeof(struct vf_data_storage), GFP_KERNEL);
7338 if (adapter->vfinfo) {
7339 /* Now that we're sure SR-IOV is enabled
7340 * and memory allocated set up the mailbox parameters
7341 */
7342 ixgbe_init_mbx_params_pf(hw);
7343 memcpy(&hw->mbx.ops, ii->mbx_ops,
7344 sizeof(hw->mbx.ops));
7345
7346 /* Disable RSC when in SR-IOV mode */
7347 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7348 IXGBE_FLAG2_RSC_ENABLED);
7349 return;
7350 }
7351
7352 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007353 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7354 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007355 pci_disable_sriov(adapter->pdev);
7356
7357err_novfs:
7358 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7359 adapter->num_vfs = 0;
7360#endif /* CONFIG_PCI_IOV */
7361}
7362
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007363/**
Auke Kok9a799d72007-09-15 14:07:45 -07007364 * ixgbe_probe - Device Initialization Routine
7365 * @pdev: PCI device information struct
7366 * @ent: entry in ixgbe_pci_tbl
7367 *
7368 * Returns 0 on success, negative on failure
7369 *
7370 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7371 * The OS initialization, configuring of the adapter private structure,
7372 * and a hardware reset occur.
7373 **/
7374static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007375 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007376{
7377 struct net_device *netdev;
7378 struct ixgbe_adapter *adapter = NULL;
7379 struct ixgbe_hw *hw;
7380 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007381 static int cards_found;
7382 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007383 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007384 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007385#ifdef IXGBE_FCOE
7386 u16 device_caps;
7387#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007388 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007389
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007390 /* Catch broken hardware that put the wrong VF device ID in
7391 * the PCIe SR-IOV capability.
7392 */
7393 if (pdev->is_virtfn) {
7394 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7395 pci_name(pdev), pdev->vendor, pdev->device);
7396 return -EINVAL;
7397 }
7398
gouji-new9ce77662009-05-06 10:44:45 +00007399 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007400 if (err)
7401 return err;
7402
Nick Nunley1b507732010-04-27 13:10:27 +00007403 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7404 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007405 pci_using_dac = 1;
7406 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007407 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007408 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007409 err = dma_set_coherent_mask(&pdev->dev,
7410 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007411 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007412 dev_err(&pdev->dev,
7413 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007414 goto err_dma;
7415 }
7416 }
7417 pci_using_dac = 0;
7418 }
7419
gouji-new9ce77662009-05-06 10:44:45 +00007420 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007421 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007422 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007423 dev_err(&pdev->dev,
7424 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007425 goto err_pci_reg;
7426 }
7427
Frans Pop19d5afd2009-10-02 10:04:12 -07007428 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007429
Auke Kok9a799d72007-09-15 14:07:45 -07007430 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007431 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007432
John Fastabende901acd2011-04-26 07:26:08 +00007433#ifdef CONFIG_IXGBE_DCB
7434 indices *= MAX_TRAFFIC_CLASS;
7435#endif
7436
John Fastabendc85a2612010-02-25 23:15:21 +00007437 if (ii->mac == ixgbe_mac_82598EB)
7438 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7439 else
7440 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7441
John Fastabende901acd2011-04-26 07:26:08 +00007442#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007443 indices += min_t(unsigned int, num_possible_cpus(),
7444 IXGBE_MAX_FCOE_INDICES);
7445#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007446 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007447 if (!netdev) {
7448 err = -ENOMEM;
7449 goto err_alloc_etherdev;
7450 }
7451
Auke Kok9a799d72007-09-15 14:07:45 -07007452 SET_NETDEV_DEV(netdev, &pdev->dev);
7453
Auke Kok9a799d72007-09-15 14:07:45 -07007454 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007455 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007456
7457 adapter->netdev = netdev;
7458 adapter->pdev = pdev;
7459 hw = &adapter->hw;
7460 hw->back = adapter;
7461 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7462
Jeff Kirsher05857982008-09-11 19:57:00 -07007463 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007464 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007465 if (!hw->hw_addr) {
7466 err = -EIO;
7467 goto err_ioremap;
7468 }
7469
7470 for (i = 1; i <= 5; i++) {
7471 if (pci_resource_len(pdev, i) == 0)
7472 continue;
7473 }
7474
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007475 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007476 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007477 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007478 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007479
Auke Kok9a799d72007-09-15 14:07:45 -07007480 adapter->bd_number = cards_found;
7481
Auke Kok9a799d72007-09-15 14:07:45 -07007482 /* Setup hw api */
7483 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007484 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007485
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007486 /* EEPROM */
7487 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7488 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7489 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7490 if (!(eec & (1 << 8)))
7491 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7492
7493 /* PHY */
7494 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007495 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007496 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7497 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7498 hw->phy.mdio.mmds = 0;
7499 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7500 hw->phy.mdio.dev = netdev;
7501 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7502 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007503
Don Skidmore8ca783a2009-05-26 20:40:47 -07007504 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007505
7506 /* setup the private structure */
7507 err = ixgbe_sw_init(adapter);
7508 if (err)
7509 goto err_sw_init;
7510
Don Skidmoree86bff02010-02-11 04:14:08 +00007511 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007512 switch (adapter->hw.mac.type) {
7513 case ixgbe_mac_82599EB:
7514 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007515 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007516 break;
7517 default:
7518 break;
7519 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007520
Don Skidmorebf069c92009-05-07 10:39:54 +00007521 /*
7522 * If there is a fan on this device and it has failed log the
7523 * failure.
7524 */
7525 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7526 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7527 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007528 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007529 }
7530
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007531 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007532 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007533 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007534 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007535 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7536 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007537 err = 0;
7538 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007539 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007540 "module type was detected.\n");
7541 e_dev_err("Reload the driver after installing a supported "
7542 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007543 goto err_sw_init;
7544 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007545 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007546 goto err_sw_init;
7547 }
7548
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007549 ixgbe_probe_vf(adapter, ii);
7550
Emil Tantilov396e7992010-07-01 20:05:12 +00007551 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007552 NETIF_F_IP_CSUM |
Don Skidmore082757a2011-07-21 05:55:00 +00007553 NETIF_F_IPV6_CSUM |
Joe Perchese8e9f692010-09-07 21:34:53 +00007554 NETIF_F_HW_VLAN_TX |
7555 NETIF_F_HW_VLAN_RX |
Don Skidmore082757a2011-07-21 05:55:00 +00007556 NETIF_F_HW_VLAN_FILTER |
7557 NETIF_F_TSO |
7558 NETIF_F_TSO6 |
7559 NETIF_F_GRO |
7560 NETIF_F_RXHASH |
7561 NETIF_F_RXCSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007562
Don Skidmore082757a2011-07-21 05:55:00 +00007563 netdev->hw_features = netdev->features;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007564
Don Skidmore58be7662011-04-12 09:42:11 +00007565 switch (adapter->hw.mac.type) {
7566 case ixgbe_mac_82599EB:
7567 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007568 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore082757a2011-07-21 05:55:00 +00007569 netdev->hw_features |= NETIF_F_SCTP_CSUM |
7570 NETIF_F_NTUPLE;
Don Skidmore58be7662011-04-12 09:42:11 +00007571 break;
7572 default:
7573 break;
7574 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007575
Jeff Kirsherad31c402008-06-05 04:05:30 -07007576 netdev->vlan_features |= NETIF_F_TSO;
7577 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007578 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007579 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007580 netdev->vlan_features |= NETIF_F_SG;
7581
Jiri Pirko01789342011-08-16 06:29:00 +00007582 netdev->priv_flags |= IFF_UNICAST_FLT;
7583
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007584 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7585 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7586 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007587
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007588#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007589 netdev->dcbnl_ops = &dcbnl_ops;
7590#endif
7591
Yi Zoueacd73f2009-05-13 13:11:06 +00007592#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007593 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007594 if (hw->mac.ops.get_device_caps) {
7595 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007596 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7597 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007598 }
7599 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007600 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7601 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7602 netdev->vlan_features |= NETIF_F_FSO;
7603 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7604 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007605#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007606 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007607 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007608 netdev->vlan_features |= NETIF_F_HIGHDMA;
7609 }
Auke Kok9a799d72007-09-15 14:07:45 -07007610
Don Skidmore082757a2011-07-21 05:55:00 +00007611 if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE)
7612 netdev->hw_features |= NETIF_F_LRO;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007613 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007614 netdev->features |= NETIF_F_LRO;
7615
Auke Kok9a799d72007-09-15 14:07:45 -07007616 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007617 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007618 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007619 err = -EIO;
7620 goto err_eeprom;
7621 }
7622
7623 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7624 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7625
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007626 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007627 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007628 err = -EIO;
7629 goto err_eeprom;
7630 }
7631
Don Skidmorec6ecf392010-12-03 03:31:51 +00007632 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7633 if (hw->mac.ops.disable_tx_laser &&
7634 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007635 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007636 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007637 hw->mac.ops.disable_tx_laser(hw);
7638
Alexander Duyck70864002011-04-27 09:13:56 +00007639 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7640 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007641
Alexander Duyck70864002011-04-27 09:13:56 +00007642 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7643 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007644
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007645 err = ixgbe_init_interrupt_scheme(adapter);
7646 if (err)
7647 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007648
Don Skidmore082757a2011-07-21 05:55:00 +00007649 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
7650 netdev->hw_features &= ~NETIF_F_RXHASH;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007651 netdev->features &= ~NETIF_F_RXHASH;
Don Skidmore082757a2011-07-21 05:55:00 +00007652 }
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007653
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007654 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007655 case IXGBE_DEV_ID_82599_SFP:
7656 /* Only this subdevice supports WOL */
7657 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007658 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007659 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007660 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7661 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007662 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007663 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007664 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007665 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007666 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007667 break;
7668 default:
7669 adapter->wol = 0;
7670 break;
7671 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007672 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7673
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007674 /* pick up the PCI bus settings for reporting later */
7675 hw->mac.ops.get_bus_info(hw);
7676
Auke Kok9a799d72007-09-15 14:07:45 -07007677 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007678 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007679 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7680 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007681 "Unknown"),
7682 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7683 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7684 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7685 "Unknown"),
7686 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007687
7688 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7689 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007690 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007691 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007692 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007693 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007694 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007695 else
Don Skidmore289700db2010-12-03 03:32:58 +00007696 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7697 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007698
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007699 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007700 e_dev_warn("PCI-Express bandwidth available for this card is "
7701 "not sufficient for optimal performance.\n");
7702 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7703 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007704 }
7705
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007706 /* save off EEPROM version number */
7707 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7708
Auke Kok9a799d72007-09-15 14:07:45 -07007709 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007710 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007711
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007712 if (err == IXGBE_ERR_EEPROM_VERSION) {
7713 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007714 e_dev_warn("This device is a pre-production adapter/LOM. "
7715 "Please be aware there may be issues associated "
7716 "with your hardware. If you are experiencing "
7717 "problems please contact your Intel or hardware "
7718 "representative who provided you with this "
7719 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007720 }
Auke Kok9a799d72007-09-15 14:07:45 -07007721 strcpy(netdev->name, "eth%d");
7722 err = register_netdev(netdev);
7723 if (err)
7724 goto err_register;
7725
Jesse Brandeburg54386462009-04-17 20:44:27 +00007726 /* carrier off reporting is important to ethtool even BEFORE open */
7727 netif_carrier_off(netdev);
7728
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007729#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007730 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007731 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007732 ixgbe_setup_dca(adapter);
7733 }
7734#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007735 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007736 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007737 for (i = 0; i < adapter->num_vfs; i++)
7738 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7739 }
7740
Emil Tantilov9612de92011-05-07 07:40:20 +00007741 /* Inform firmware of driver version */
7742 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007743 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7744 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007745
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007746 /* add san mac addr to netdev */
7747 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007748
Emil Tantilov849c4542010-06-03 16:53:41 +00007749 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007750 cards_found++;
7751 return 0;
7752
7753err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007754 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007755 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007756err_sw_init:
7757err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007758 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7759 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007760 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007761 iounmap(hw->hw_addr);
7762err_ioremap:
7763 free_netdev(netdev);
7764err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007765 pci_release_selected_regions(pdev,
7766 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007767err_pci_reg:
7768err_dma:
7769 pci_disable_device(pdev);
7770 return err;
7771}
7772
7773/**
7774 * ixgbe_remove - Device Removal Routine
7775 * @pdev: PCI device information struct
7776 *
7777 * ixgbe_remove is called by the PCI subsystem to alert the driver
7778 * that it should release a PCI device. The could be caused by a
7779 * Hot-Plug event, or because the driver is going to be removed from
7780 * memory.
7781 **/
7782static void __devexit ixgbe_remove(struct pci_dev *pdev)
7783{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007784 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7785 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007786
7787 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007788 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007789
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007790#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007791 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7792 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7793 dca_remove_requester(&pdev->dev);
7794 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7795 }
7796
7797#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007798#ifdef IXGBE_FCOE
7799 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7800 ixgbe_cleanup_fcoe(adapter);
7801
7802#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007803
7804 /* remove the added san mac */
7805 ixgbe_del_sanmac_netdev(netdev);
7806
Donald Skidmorec4900be2008-11-20 21:11:42 -08007807 if (netdev->reg_state == NETREG_REGISTERED)
7808 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007809
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007810 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7811 ixgbe_disable_sriov(adapter);
7812
Alexander Duyck7a921c92009-05-06 10:43:28 +00007813 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007814
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007815 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007816
7817 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007818 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007819 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007820
Emil Tantilov849c4542010-06-03 16:53:41 +00007821 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007822
Auke Kok9a799d72007-09-15 14:07:45 -07007823 free_netdev(netdev);
7824
Frans Pop19d5afd2009-10-02 10:04:12 -07007825 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007826
Auke Kok9a799d72007-09-15 14:07:45 -07007827 pci_disable_device(pdev);
7828}
7829
7830/**
7831 * ixgbe_io_error_detected - called when PCI error is detected
7832 * @pdev: Pointer to PCI device
7833 * @state: The current pci connection state
7834 *
7835 * This function is called after a PCI bus error affecting
7836 * this device has been detected.
7837 */
7838static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007839 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007840{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007841 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7842 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007843
7844 netif_device_detach(netdev);
7845
Breno Leitao3044b8d2009-05-06 10:44:26 +00007846 if (state == pci_channel_io_perm_failure)
7847 return PCI_ERS_RESULT_DISCONNECT;
7848
Auke Kok9a799d72007-09-15 14:07:45 -07007849 if (netif_running(netdev))
7850 ixgbe_down(adapter);
7851 pci_disable_device(pdev);
7852
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007853 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007854 return PCI_ERS_RESULT_NEED_RESET;
7855}
7856
7857/**
7858 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7859 * @pdev: Pointer to PCI device
7860 *
7861 * Restart the card from scratch, as if from a cold-boot.
7862 */
7863static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7864{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007865 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007866 pci_ers_result_t result;
7867 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007868
gouji-new9ce77662009-05-06 10:44:45 +00007869 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007870 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007871 result = PCI_ERS_RESULT_DISCONNECT;
7872 } else {
7873 pci_set_master(pdev);
7874 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007875 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007876
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007877 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007878
7879 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007880 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007881 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007882 }
Auke Kok9a799d72007-09-15 14:07:45 -07007883
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007884 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7885 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007886 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7887 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007888 /* non-fatal, continue */
7889 }
Auke Kok9a799d72007-09-15 14:07:45 -07007890
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007891 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007892}
7893
7894/**
7895 * ixgbe_io_resume - called when traffic can start flowing again.
7896 * @pdev: Pointer to PCI device
7897 *
7898 * This callback is called when the error recovery driver tells us that
7899 * its OK to resume normal operation.
7900 */
7901static void ixgbe_io_resume(struct pci_dev *pdev)
7902{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007903 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7904 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007905
7906 if (netif_running(netdev)) {
7907 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007908 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007909 return;
7910 }
7911 }
7912
7913 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007914}
7915
7916static struct pci_error_handlers ixgbe_err_handler = {
7917 .error_detected = ixgbe_io_error_detected,
7918 .slot_reset = ixgbe_io_slot_reset,
7919 .resume = ixgbe_io_resume,
7920};
7921
7922static struct pci_driver ixgbe_driver = {
7923 .name = ixgbe_driver_name,
7924 .id_table = ixgbe_pci_tbl,
7925 .probe = ixgbe_probe,
7926 .remove = __devexit_p(ixgbe_remove),
7927#ifdef CONFIG_PM
7928 .suspend = ixgbe_suspend,
7929 .resume = ixgbe_resume,
7930#endif
7931 .shutdown = ixgbe_shutdown,
7932 .err_handler = &ixgbe_err_handler
7933};
7934
7935/**
7936 * ixgbe_init_module - Driver Registration Routine
7937 *
7938 * ixgbe_init_module is the first routine called when the driver is
7939 * loaded. All it does is register with the PCI subsystem.
7940 **/
7941static int __init ixgbe_init_module(void)
7942{
7943 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007944 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007945 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007946
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007947#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007948 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007949#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007950
Auke Kok9a799d72007-09-15 14:07:45 -07007951 ret = pci_register_driver(&ixgbe_driver);
7952 return ret;
7953}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007954
Auke Kok9a799d72007-09-15 14:07:45 -07007955module_init(ixgbe_init_module);
7956
7957/**
7958 * ixgbe_exit_module - Driver Exit Cleanup Routine
7959 *
7960 * ixgbe_exit_module is called just before the driver is removed
7961 * from memory.
7962 **/
7963static void __exit ixgbe_exit_module(void)
7964{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007965#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007966 dca_unregister_notify(&dca_notifier);
7967#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007968 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007969 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007970}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007971
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007972#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007973static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007974 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007975{
7976 int ret_val;
7977
7978 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007979 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007980
7981 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7982}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007983
Alexander Duyckb4533682009-03-31 21:32:42 +00007984#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007985
Auke Kok9a799d72007-09-15 14:07:45 -07007986module_exit(ixgbe_exit_module);
7987
7988/* ixgbe_main.c */