blob: c6fa9c7eb738c24f9e7febff1f3d5a5a432ae229 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
45#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040046#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000047#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048
49#include "ixgbe.h"
50#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000051#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000052#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070053
54char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070055static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000056 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000057#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000058#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000059#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000061 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070062const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000063static const char ixgbe_copyright[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070065
66static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070067 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000068 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080069 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070070};
71
72/* ixgbe_pci_tbl - PCI Device ID Table
73 *
74 * Wildcard entries (PCI_ANY_ID) should come last
75 * Last entry must be all 0s
76 *
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
79 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000080static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
82 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070086 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
88 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
90 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070092 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
94 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
96 board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
98 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
100 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
102 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
104 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
106 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
108 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
110 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
112 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
114 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
116 board_82599 },
Peter P Waskiewicz Jr8911184f2009-09-14 07:47:49 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
118 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
120 board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
122 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
124 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
126 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000128 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
130 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
132 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700133
134 /* required last entry */
135 {0, }
136};
137MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
138
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400139#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800140static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000141 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800142static struct notifier_block dca_notifier = {
143 .notifier_call = ixgbe_notify_dca,
144 .next = NULL,
145 .priority = 0
146};
147#endif
148
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000149#ifdef CONFIG_PCI_IOV
150static unsigned int max_vfs;
151module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000152MODULE_PARM_DESC(max_vfs,
153 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000154#endif /* CONFIG_PCI_IOV */
155
Auke Kok9a799d72007-09-15 14:07:45 -0700156MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
157MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
158MODULE_LICENSE("GPL");
159MODULE_VERSION(DRV_VERSION);
160
161#define DEFAULT_DEBUG_LEVEL_SHIFT 3
162
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000163static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
164{
165 struct ixgbe_hw *hw = &adapter->hw;
166 u32 gcr;
167 u32 gpie;
168 u32 vmdctl;
169
170#ifdef CONFIG_PCI_IOV
171 /* disable iov and allow time for transactions to clear */
172 pci_disable_sriov(adapter->pdev);
173#endif
174
175 /* turn off device IOV mode */
176 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
177 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
178 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
179 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
180 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
181 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
182
183 /* set default pool back to 0 */
184 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
185 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
186 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
187
188 /* take a breather then clean up driver data */
189 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000190
191 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000192 adapter->vfinfo = NULL;
193
194 adapter->num_vfs = 0;
195 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
196}
197
Alexander Duyck70864002011-04-27 09:13:56 +0000198static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
199{
200 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
201 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
202 schedule_work(&adapter->service_task);
203}
204
205static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
206{
207 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
208
209 /* flush memory to make sure state is correct before next watchog */
210 smp_mb__before_clear_bit();
211 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
212}
213
Taku Izumidcd79ae2010-04-27 14:39:53 +0000214struct ixgbe_reg_info {
215 u32 ofs;
216 char *name;
217};
218
219static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
220
221 /* General Registers */
222 {IXGBE_CTRL, "CTRL"},
223 {IXGBE_STATUS, "STATUS"},
224 {IXGBE_CTRL_EXT, "CTRL_EXT"},
225
226 /* Interrupt Registers */
227 {IXGBE_EICR, "EICR"},
228
229 /* RX Registers */
230 {IXGBE_SRRCTL(0), "SRRCTL"},
231 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
232 {IXGBE_RDLEN(0), "RDLEN"},
233 {IXGBE_RDH(0), "RDH"},
234 {IXGBE_RDT(0), "RDT"},
235 {IXGBE_RXDCTL(0), "RXDCTL"},
236 {IXGBE_RDBAL(0), "RDBAL"},
237 {IXGBE_RDBAH(0), "RDBAH"},
238
239 /* TX Registers */
240 {IXGBE_TDBAL(0), "TDBAL"},
241 {IXGBE_TDBAH(0), "TDBAH"},
242 {IXGBE_TDLEN(0), "TDLEN"},
243 {IXGBE_TDH(0), "TDH"},
244 {IXGBE_TDT(0), "TDT"},
245 {IXGBE_TXDCTL(0), "TXDCTL"},
246
247 /* List Terminator */
248 {}
249};
250
251
252/*
253 * ixgbe_regdump - register printout routine
254 */
255static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
256{
257 int i = 0, j = 0;
258 char rname[16];
259 u32 regs[64];
260
261 switch (reginfo->ofs) {
262 case IXGBE_SRRCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
265 break;
266 case IXGBE_DCA_RXCTRL(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
269 break;
270 case IXGBE_RDLEN(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
273 break;
274 case IXGBE_RDH(0):
275 for (i = 0; i < 64; i++)
276 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
277 break;
278 case IXGBE_RDT(0):
279 for (i = 0; i < 64; i++)
280 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
281 break;
282 case IXGBE_RXDCTL(0):
283 for (i = 0; i < 64; i++)
284 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
285 break;
286 case IXGBE_RDBAL(0):
287 for (i = 0; i < 64; i++)
288 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
289 break;
290 case IXGBE_RDBAH(0):
291 for (i = 0; i < 64; i++)
292 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
293 break;
294 case IXGBE_TDBAL(0):
295 for (i = 0; i < 64; i++)
296 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
297 break;
298 case IXGBE_TDBAH(0):
299 for (i = 0; i < 64; i++)
300 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
301 break;
302 case IXGBE_TDLEN(0):
303 for (i = 0; i < 64; i++)
304 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
305 break;
306 case IXGBE_TDH(0):
307 for (i = 0; i < 64; i++)
308 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
309 break;
310 case IXGBE_TDT(0):
311 for (i = 0; i < 64; i++)
312 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
313 break;
314 case IXGBE_TXDCTL(0):
315 for (i = 0; i < 64; i++)
316 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
317 break;
318 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000319 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000320 IXGBE_READ_REG(hw, reginfo->ofs));
321 return;
322 }
323
324 for (i = 0; i < 8; i++) {
325 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000326 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000327 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000328 pr_cont(" %08x", regs[i*8+j]);
329 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000330 }
331
332}
333
334/*
335 * ixgbe_dump - Print registers, tx-rings and rx-rings
336 */
337static void ixgbe_dump(struct ixgbe_adapter *adapter)
338{
339 struct net_device *netdev = adapter->netdev;
340 struct ixgbe_hw *hw = &adapter->hw;
341 struct ixgbe_reg_info *reginfo;
342 int n = 0;
343 struct ixgbe_ring *tx_ring;
344 struct ixgbe_tx_buffer *tx_buffer_info;
345 union ixgbe_adv_tx_desc *tx_desc;
346 struct my_u0 { u64 a; u64 b; } *u0;
347 struct ixgbe_ring *rx_ring;
348 union ixgbe_adv_rx_desc *rx_desc;
349 struct ixgbe_rx_buffer *rx_buffer_info;
350 u32 staterr;
351 int i = 0;
352
353 if (!netif_msg_hw(adapter))
354 return;
355
356 /* Print netdevice Info */
357 if (netdev) {
358 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000359 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000360 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("%-15s %016lX %016lX %016lX\n",
362 netdev->name,
363 netdev->state,
364 netdev->trans_start,
365 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000366 }
367
368 /* Print Registers */
369 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000370 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000371 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
372 reginfo->name; reginfo++) {
373 ixgbe_regdump(hw, reginfo);
374 }
375
376 /* Print TX Ring Summary */
377 if (!netdev || !netif_running(netdev))
378 goto exit;
379
380 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000381 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000382 for (n = 0; n < adapter->num_tx_queues; n++) {
383 tx_ring = adapter->tx_ring[n];
384 tx_buffer_info =
385 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000386 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000387 n, tx_ring->next_to_use, tx_ring->next_to_clean,
388 (u64)tx_buffer_info->dma,
389 tx_buffer_info->length,
390 tx_buffer_info->next_to_watch,
391 (u64)tx_buffer_info->time_stamp);
392 }
393
394 /* Print TX Rings */
395 if (!netif_msg_tx_done(adapter))
396 goto rx_ring_summary;
397
398 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
399
400 /* Transmit Descriptor Formats
401 *
402 * Advanced Transmit Descriptor
403 * +--------------------------------------------------------------+
404 * 0 | Buffer Address [63:0] |
405 * +--------------------------------------------------------------+
406 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
407 * +--------------------------------------------------------------+
408 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
409 */
410
411 for (n = 0; n < adapter->num_tx_queues; n++) {
412 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000413 pr_info("------------------------------------\n");
414 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
415 pr_info("------------------------------------\n");
416 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000417 "[PlPOIdStDDt Ln] [bi->dma ] "
418 "leng ntw timestamp bi->skb\n");
419
420 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000421 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000422 tx_buffer_info = &tx_ring->tx_buffer_info[i];
423 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000424 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000425 " %04X %3X %016llX %p", i,
426 le64_to_cpu(u0->a),
427 le64_to_cpu(u0->b),
428 (u64)tx_buffer_info->dma,
429 tx_buffer_info->length,
430 tx_buffer_info->next_to_watch,
431 (u64)tx_buffer_info->time_stamp,
432 tx_buffer_info->skb);
433 if (i == tx_ring->next_to_use &&
434 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000435 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000437 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000438 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000439 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000440 else
Joe Perchesc7689572010-09-07 21:35:17 +0000441 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000442
443 if (netif_msg_pktdata(adapter) &&
444 tx_buffer_info->dma != 0)
445 print_hex_dump(KERN_INFO, "",
446 DUMP_PREFIX_ADDRESS, 16, 1,
447 phys_to_virt(tx_buffer_info->dma),
448 tx_buffer_info->length, true);
449 }
450 }
451
452 /* Print RX Rings Summary */
453rx_ring_summary:
454 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000455 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 for (n = 0; n < adapter->num_rx_queues; n++) {
457 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000458 pr_info("%5d %5X %5X\n",
459 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000460 }
461
462 /* Print RX Rings */
463 if (!netif_msg_rx_status(adapter))
464 goto exit;
465
466 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
467
468 /* Advanced Receive Descriptor (Read) Format
469 * 63 1 0
470 * +-----------------------------------------------------+
471 * 0 | Packet Buffer Address [63:1] |A0/NSE|
472 * +----------------------------------------------+------+
473 * 8 | Header Buffer Address [63:1] | DD |
474 * +-----------------------------------------------------+
475 *
476 *
477 * Advanced Receive Descriptor (Write-Back) Format
478 *
479 * 63 48 47 32 31 30 21 20 16 15 4 3 0
480 * +------------------------------------------------------+
481 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
482 * | Checksum Ident | | | | Type | Type |
483 * +------------------------------------------------------+
484 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
485 * +------------------------------------------------------+
486 * 63 48 47 32 31 20 19 0
487 */
488 for (n = 0; n < adapter->num_rx_queues; n++) {
489 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000490 pr_info("------------------------------------\n");
491 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
492 pr_info("------------------------------------\n");
493 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000494 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
495 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000496 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000497 "[vl er S cks ln] ---------------- [bi->skb] "
498 "<-- Adv Rx Write-Back format\n");
499
500 for (i = 0; i < rx_ring->count; i++) {
501 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000502 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000503 u0 = (struct my_u0 *)rx_desc;
504 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
505 if (staterr & IXGBE_RXD_STAT_DD) {
506 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000507 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000508 "%016llX ---------------- %p", i,
509 le64_to_cpu(u0->a),
510 le64_to_cpu(u0->b),
511 rx_buffer_info->skb);
512 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000513 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000514 "%016llX %016llX %p", i,
515 le64_to_cpu(u0->a),
516 le64_to_cpu(u0->b),
517 (u64)rx_buffer_info->dma,
518 rx_buffer_info->skb);
519
520 if (netif_msg_pktdata(adapter)) {
521 print_hex_dump(KERN_INFO, "",
522 DUMP_PREFIX_ADDRESS, 16, 1,
523 phys_to_virt(rx_buffer_info->dma),
524 rx_ring->rx_buf_len, true);
525
526 if (rx_ring->rx_buf_len
527 < IXGBE_RXBUFFER_2048)
528 print_hex_dump(KERN_INFO, "",
529 DUMP_PREFIX_ADDRESS, 16, 1,
530 phys_to_virt(
531 rx_buffer_info->page_dma +
532 rx_buffer_info->page_offset
533 ),
534 PAGE_SIZE/2, true);
535 }
536 }
537
538 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000539 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000541 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000542 else
Joe Perchesc7689572010-09-07 21:35:17 +0000543 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000544
545 }
546 }
547
548exit:
549 return;
550}
551
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800552static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
553{
554 u32 ctrl_ext;
555
556 /* Let firmware take over control of h/w */
557 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
558 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000559 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800560}
561
562static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
563{
564 u32 ctrl_ext;
565
566 /* Let firmware know the driver has taken over */
567 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
568 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000569 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800570}
Auke Kok9a799d72007-09-15 14:07:45 -0700571
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000572/*
573 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
574 * @adapter: pointer to adapter struct
575 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
576 * @queue: queue to map the corresponding interrupt to
577 * @msix_vector: the vector to map to the corresponding queue
578 *
579 */
580static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000581 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700582{
583 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000584 struct ixgbe_hw *hw = &adapter->hw;
585 switch (hw->mac.type) {
586 case ixgbe_mac_82598EB:
587 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
588 if (direction == -1)
589 direction = 0;
590 index = (((direction * 64) + queue) >> 2) & 0x1F;
591 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
592 ivar &= ~(0xFF << (8 * (queue & 0x3)));
593 ivar |= (msix_vector << (8 * (queue & 0x3)));
594 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
595 break;
596 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800597 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000598 if (direction == -1) {
599 /* other causes */
600 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
601 index = ((queue & 1) * 8);
602 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
603 ivar &= ~(0xFF << index);
604 ivar |= (msix_vector << index);
605 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
606 break;
607 } else {
608 /* tx or rx causes */
609 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
610 index = ((16 * (queue & 1)) + (8 * direction));
611 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
612 ivar &= ~(0xFF << index);
613 ivar |= (msix_vector << index);
614 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
615 break;
616 }
617 default:
618 break;
619 }
Auke Kok9a799d72007-09-15 14:07:45 -0700620}
621
Alexander Duyckfe49f042009-06-04 16:00:09 +0000622static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000623 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000624{
625 u32 mask;
626
Alexander Duyckbd508172010-11-16 19:27:03 -0800627 switch (adapter->hw.mac.type) {
628 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000629 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
630 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800631 break;
632 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800633 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000634 mask = (qmask & 0xFFFFFFFF);
635 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
636 mask = (qmask >> 32);
637 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800638 break;
639 default:
640 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000641 }
642}
643
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800644void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
645 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700646{
Alexander Duycke5a43542009-12-02 16:46:56 +0000647 if (tx_buffer_info->dma) {
648 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800649 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000650 tx_buffer_info->dma,
651 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000652 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000653 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800654 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000655 tx_buffer_info->dma,
656 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000657 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000658 tx_buffer_info->dma = 0;
659 }
Auke Kok9a799d72007-09-15 14:07:45 -0700660 if (tx_buffer_info->skb) {
661 dev_kfree_skb_any(tx_buffer_info->skb);
662 tx_buffer_info->skb = NULL;
663 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000664 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700665 /* tx_buffer_info must be completely set up in the transmit path */
666}
667
John Fastabendc84d3242010-11-16 19:27:12 -0800668static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700669{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700670 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800671 struct ixgbe_hw_stats *hwstats = &adapter->stats;
672 u32 data = 0;
673 u32 xoff[8] = {0};
674 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700675
John Fastabendc84d3242010-11-16 19:27:12 -0800676 if ((hw->fc.current_mode == ixgbe_fc_full) ||
677 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
678 switch (hw->mac.type) {
679 case ixgbe_mac_82598EB:
680 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
681 break;
682 default:
683 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
684 }
685 hwstats->lxoffrxc += data;
686
687 /* refill credits (no tx hang) if we received xoff */
688 if (!data)
689 return;
690
691 for (i = 0; i < adapter->num_tx_queues; i++)
692 clear_bit(__IXGBE_HANG_CHECK_ARMED,
693 &adapter->tx_ring[i]->state);
694 return;
695 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
696 return;
697
698 /* update stats for each tc, only valid with PFC enabled */
699 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
700 switch (hw->mac.type) {
701 case ixgbe_mac_82598EB:
702 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
703 break;
704 default:
705 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
706 }
707 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700708 }
709
John Fastabendc84d3242010-11-16 19:27:12 -0800710 /* disarm tx queues that have received xoff frames */
711 for (i = 0; i < adapter->num_tx_queues; i++) {
712 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
John Fastabendfb5475f2011-04-26 07:26:36 +0000713 u8 tc = tx_ring->dcb_tc;
John Fastabendc84d3242010-11-16 19:27:12 -0800714
715 if (xoff[tc])
716 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
717 }
718}
719
720static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
721{
722 return ring->tx_stats.completed;
723}
724
725static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
726{
727 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
728 struct ixgbe_hw *hw = &adapter->hw;
729
730 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
731 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
732
733 if (head != tail)
734 return (head < tail) ?
735 tail - head : (tail + ring->count - head);
736
737 return 0;
738}
739
740static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
741{
742 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
743 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
744 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
745 bool ret = false;
746
747 clear_check_for_tx_hang(tx_ring);
748
749 /*
750 * Check for a hung queue, but be thorough. This verifies
751 * that a transmit has been completed since the previous
752 * check AND there is at least one packet pending. The
753 * ARMED bit is set to indicate a potential hang. The
754 * bit is cleared if a pause frame is received to remove
755 * false hang detection due to PFC or 802.3x frames. By
756 * requiring this to fail twice we avoid races with
757 * pfc clearing the ARMED bit and conditions where we
758 * run the check_tx_hang logic with a transmit completion
759 * pending but without time to complete it yet.
760 */
761 if ((tx_done_old == tx_done) && tx_pending) {
762 /* make sure it is true for two checks in a row */
763 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
764 &tx_ring->state);
765 } else {
766 /* update completed stats and continue */
767 tx_ring->tx_stats.tx_done_old = tx_done;
768 /* reset the countdown */
769 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
770 }
771
772 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700773}
774
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000775/**
776 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
777 * @adapter: driver private struct
778 **/
779static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
780{
781
782 /* Do the reset outside of interrupt context */
783 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
784 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
785 ixgbe_service_event_schedule(adapter);
786 }
787}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700788
Auke Kok9a799d72007-09-15 14:07:45 -0700789/**
790 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000791 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700792 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700793 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000794static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000795 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700796{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000797 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800798 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
799 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700800 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800801 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700802
803 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800804 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000805 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800806
807 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Alexander Duyckbd198052011-06-11 01:45:08 +0000808 (count < q_vector->tx.work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800809 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000810 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800811 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000812 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700813 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700814
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800815 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800816 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800817
Auke Kok9a799d72007-09-15 14:07:45 -0700818 i++;
819 if (i == tx_ring->count)
820 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800821
822 if (cleaned && tx_buffer_info->skb) {
823 total_bytes += tx_buffer_info->bytecount;
824 total_packets += tx_buffer_info->gso_segs;
825 }
826
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800827 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800828 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700829 }
830
John Fastabendc84d3242010-11-16 19:27:12 -0800831 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800832 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000833 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800834 }
835
Auke Kok9a799d72007-09-15 14:07:45 -0700836 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800837 tx_ring->stats.bytes += total_bytes;
Alexander Duyckbd198052011-06-11 01:45:08 +0000838 tx_ring->stats.packets += total_packets;
839 u64_stats_update_begin(&tx_ring->syncp);
840 q_vector->tx.total_bytes += total_bytes;
841 q_vector->tx.total_packets += total_packets;
Alexander Duyckb9537992010-11-16 19:26:58 -0800842 u64_stats_update_end(&tx_ring->syncp);
843
John Fastabendc84d3242010-11-16 19:27:12 -0800844 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800845 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800846 struct ixgbe_hw *hw = &adapter->hw;
847 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
848 e_err(drv, "Detected Tx Unit Hang\n"
849 " Tx Queue <%d>\n"
850 " TDH, TDT <%x>, <%x>\n"
851 " next_to_use <%x>\n"
852 " next_to_clean <%x>\n"
853 "tx_buffer_info[next_to_clean]\n"
854 " time_stamp <%lx>\n"
855 " jiffies <%lx>\n",
856 tx_ring->queue_index,
857 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
858 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
859 tx_ring->next_to_use, eop,
860 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
861
862 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
863
864 e_info(probe,
865 "tx hang %d detected on queue %d, resetting adapter\n",
866 adapter->tx_timeout_count + 1, tx_ring->queue_index);
867
868 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000869 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800870
871 /* the adapter is about to reset, no point in enabling stuff */
872 return true;
873 }
Auke Kok9a799d72007-09-15 14:07:45 -0700874
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800875#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800876 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000877 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800878 /* Make sure that anybody stopping the queue after this
879 * sees the new next_to_clean.
880 */
881 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800882 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800883 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800884 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800885 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800886 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800887 }
Auke Kok9a799d72007-09-15 14:07:45 -0700888
Alexander Duyckbd198052011-06-11 01:45:08 +0000889 return count < q_vector->tx.work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700890}
891
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400892#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800893static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800894 struct ixgbe_ring *rx_ring,
895 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800896{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800897 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800898 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800899 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800900
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800901 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
902 switch (hw->mac.type) {
903 case ixgbe_mac_82598EB:
904 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
905 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
906 break;
907 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800908 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800909 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
910 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
911 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
912 break;
913 default:
914 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800915 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800916 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
917 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
918 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800919 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800920}
921
922static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800923 struct ixgbe_ring *tx_ring,
924 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800925{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000926 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800927 u32 txctrl;
928 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800929
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800930 switch (hw->mac.type) {
931 case ixgbe_mac_82598EB:
932 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
933 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
934 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
935 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800936 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
937 break;
938 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800939 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800940 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
941 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
942 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
943 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
944 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800945 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
946 break;
947 default:
948 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800949 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800950}
951
952static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
953{
954 struct ixgbe_adapter *adapter = q_vector->adapter;
955 int cpu = get_cpu();
956 long r_idx;
957 int i;
958
959 if (q_vector->cpu == cpu)
960 goto out_no_update;
961
Alexander Duyck08c88332011-06-11 01:45:03 +0000962 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
963 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800964 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000965 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800966 r_idx + 1);
967 }
968
Alexander Duyck08c88332011-06-11 01:45:03 +0000969 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
970 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800971 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
Alexander Duyck08c88332011-06-11 01:45:03 +0000972 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800973 r_idx + 1);
974 }
975
976 q_vector->cpu = cpu;
977out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800978 put_cpu();
979}
980
981static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
982{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800983 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800984 int i;
985
986 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
987 return;
988
Alexander Duycke35ec122009-05-21 13:07:12 +0000989 /* always use CB2 mode, difference is masked in the CB driver */
990 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
991
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800992 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
993 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
994 else
995 num_q_vectors = 1;
996
997 for (i = 0; i < num_q_vectors; i++) {
998 adapter->q_vector[i]->cpu = -1;
999 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001000 }
1001}
1002
1003static int __ixgbe_notify_dca(struct device *dev, void *data)
1004{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001005 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001006 unsigned long event = *(unsigned long *)data;
1007
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001008 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1009 return 0;
1010
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001011 switch (event) {
1012 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001013 /* if we're already enabled, don't do it again */
1014 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1015 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001016 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001017 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001018 ixgbe_setup_dca(adapter);
1019 break;
1020 }
1021 /* Fall Through since DCA is disabled. */
1022 case DCA_PROVIDER_REMOVE:
1023 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1024 dca_remove_requester(dev);
1025 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1026 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1027 }
1028 break;
1029 }
1030
Denis V. Lunev652f0932008-03-27 14:39:17 +03001031 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001032}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001033#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001034
1035static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1036 struct sk_buff *skb)
1037{
1038 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1039}
1040
Auke Kok9a799d72007-09-15 14:07:45 -07001041/**
Alexander Duyckff886df2011-06-11 01:45:13 +00001042 * ixgbe_rx_is_fcoe - check the rx desc for incoming pkt type
1043 * @adapter: address of board private structure
1044 * @rx_desc: advanced rx descriptor
1045 *
1046 * Returns : true if it is FCoE pkt
1047 */
1048static inline bool ixgbe_rx_is_fcoe(struct ixgbe_adapter *adapter,
1049 union ixgbe_adv_rx_desc *rx_desc)
1050{
1051 __le16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1052
1053 return (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
1054 ((pkt_info & cpu_to_le16(IXGBE_RXDADV_PKTTYPE_ETQF_MASK)) ==
1055 (cpu_to_le16(IXGBE_ETQF_FILTER_FCOE <<
1056 IXGBE_RXDADV_PKTTYPE_ETQF_SHIFT)));
1057}
1058
1059/**
Auke Kok9a799d72007-09-15 14:07:45 -07001060 * ixgbe_receive_skb - Send a completed packet up the stack
1061 * @adapter: board private structure
1062 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001063 * @status: hardware indication of status of receive
1064 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1065 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001066 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001067static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001068 struct sk_buff *skb, u8 status,
1069 struct ixgbe_ring *ring,
1070 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001071{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001072 struct ixgbe_adapter *adapter = q_vector->adapter;
1073 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001074 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1075 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001076
Jesse Grossf62bbb52010-10-20 13:56:10 +00001077 if (is_vlan && (tag & VLAN_VID_MASK))
1078 __vlan_hwaccel_put_tag(skb, tag);
1079
1080 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1081 napi_gro_receive(napi, skb);
1082 else
1083 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001084}
1085
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001086/**
1087 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1088 * @adapter: address of board private structure
1089 * @status_err: hardware indication of status of receive
1090 * @skb: skb currently being received and modified
Alexander Duyckff886df2011-06-11 01:45:13 +00001091 * @status_err: status error value of last descriptor in packet
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001092 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001093static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001094 union ixgbe_adv_rx_desc *rx_desc,
Alexander Duyckff886df2011-06-11 01:45:13 +00001095 struct sk_buff *skb,
1096 u32 status_err)
Auke Kok9a799d72007-09-15 14:07:45 -07001097{
Alexander Duyckff886df2011-06-11 01:45:13 +00001098 skb->ip_summed = CHECKSUM_NONE;
Auke Kok9a799d72007-09-15 14:07:45 -07001099
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001100 /* Rx csum disabled */
1101 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001102 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001103
1104 /* if IP and error */
1105 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1106 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001107 adapter->hw_csum_rx_error++;
1108 return;
1109 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001110
1111 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1112 return;
1113
1114 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001115 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1116
1117 /*
1118 * 82599 errata, UDP frames with a 0 checksum can be marked as
1119 * checksum errors.
1120 */
1121 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1122 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1123 return;
1124
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001125 adapter->hw_csum_rx_error++;
1126 return;
1127 }
1128
Auke Kok9a799d72007-09-15 14:07:45 -07001129 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001130 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001131}
1132
Alexander Duyck84ea2592010-11-16 19:26:49 -08001133static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001134{
1135 /*
1136 * Force memory writes to complete before letting h/w
1137 * know there are new descriptors to fetch. (Only
1138 * applicable for weak-ordered memory model archs,
1139 * such as IA-64).
1140 */
1141 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001142 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001143}
1144
Auke Kok9a799d72007-09-15 14:07:45 -07001145/**
1146 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001147 * @rx_ring: ring to place buffers on
1148 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001149 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001150void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001151{
Auke Kok9a799d72007-09-15 14:07:45 -07001152 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001153 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001154 struct sk_buff *skb;
1155 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001156
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001157 /* do nothing if no valid netdev defined */
1158 if (!rx_ring->netdev)
1159 return;
1160
Auke Kok9a799d72007-09-15 14:07:45 -07001161 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001162 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001163 bi = &rx_ring->rx_buffer_info[i];
1164 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001165
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001166 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001167 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001168 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001169 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001170 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001171 goto no_buffers;
1172 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001173 /* initialize queue mapping */
1174 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001175 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001176 }
Auke Kok9a799d72007-09-15 14:07:45 -07001177
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001178 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001179 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001180 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001181 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001182 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001183 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001184 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001185 bi->dma = 0;
1186 goto no_buffers;
1187 }
Auke Kok9a799d72007-09-15 14:07:45 -07001188 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001189
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001190 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001191 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001192 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001193 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001194 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001195 goto no_buffers;
1196 }
1197 }
1198
1199 if (!bi->page_dma) {
1200 /* use a half page if we're re-using */
1201 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001202 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001203 bi->page,
1204 bi->page_offset,
1205 PAGE_SIZE / 2,
1206 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001207 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001208 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001209 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001210 bi->page_dma = 0;
1211 goto no_buffers;
1212 }
1213 }
1214
1215 /* Refresh the desc even if buffer_addrs didn't change
1216 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001217 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1218 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001219 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001220 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001221 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001222 }
1223
1224 i++;
1225 if (i == rx_ring->count)
1226 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001227 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001228
Auke Kok9a799d72007-09-15 14:07:45 -07001229no_buffers:
1230 if (rx_ring->next_to_use != i) {
1231 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001232 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001233 }
1234}
1235
Alexander Duyckc267fc12010-11-16 19:27:00 -08001236static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001237{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001238 /* HW will not DMA in data larger than the given buffer, even if it
1239 * parses the (NFS, of course) header to be larger. In that case, it
1240 * fills the header buffer and spills the rest into the page.
1241 */
1242 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1243 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1244 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1245 if (hlen > IXGBE_RX_HDR_SIZE)
1246 hlen = IXGBE_RX_HDR_SIZE;
1247 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001248}
1249
Alexander Duyckf8212f92009-04-27 22:42:37 +00001250/**
1251 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1252 * @skb: pointer to the last skb in the rsc queue
1253 *
1254 * This function changes a queue full of hw rsc buffers into a completed
1255 * packet. It uses the ->prev pointers to find the first packet and then
1256 * turns it into the frag list owner.
1257 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001258static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001259{
1260 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001261 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001262
1263 while (skb->prev) {
1264 struct sk_buff *prev = skb->prev;
1265 frag_list_size += skb->len;
1266 skb->prev = NULL;
1267 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001268 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001269 }
1270
1271 skb_shinfo(skb)->frag_list = skb->next;
1272 skb->next = NULL;
1273 skb->len += frag_list_size;
1274 skb->data_len += frag_list_size;
1275 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001276 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1277
Alexander Duyckf8212f92009-04-27 22:42:37 +00001278 return skb;
1279}
1280
Alexander Duyckaa801752010-11-16 19:27:02 -08001281static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1282{
1283 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1284 IXGBE_RXDADV_RSCCNT_MASK);
1285}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001286
Alexander Duyckc267fc12010-11-16 19:27:00 -08001287static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001288 struct ixgbe_ring *rx_ring,
1289 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001290{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001291 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001292 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1293 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1294 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001295 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001296 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001297#ifdef IXGBE_FCOE
1298 int ddp_bytes = 0;
1299#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001300 u32 staterr;
1301 u16 i;
1302 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001303 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001304
1305 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001306 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001307 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001308
1309 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001310 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001311
Milton Miller3c945e52010-02-19 17:44:42 +00001312 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001313
Alexander Duyckc267fc12010-11-16 19:27:00 -08001314 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1315
Auke Kok9a799d72007-09-15 14:07:45 -07001316 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001317 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001318 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001319
Alexander Duyckc267fc12010-11-16 19:27:00 -08001320 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001321 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001322
1323 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001324 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001325 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001326 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001327 !(staterr & IXGBE_RXD_STAT_EOP) &&
1328 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001329 /*
1330 * When HWRSC is enabled, delay unmapping
1331 * of the first packet. It carries the
1332 * header information, HW may still
1333 * access the header after the writeback.
1334 * Only unmap it when EOP is reached
1335 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001336 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001337 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001338 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001339 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001340 rx_buffer_info->dma,
1341 rx_ring->rx_buf_len,
1342 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001343 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001344 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001345
1346 if (ring_is_ps_enabled(rx_ring)) {
1347 hlen = ixgbe_get_hlen(rx_desc);
1348 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1349 } else {
1350 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1351 }
1352
1353 skb_put(skb, hlen);
1354 } else {
1355 /* assume packet split since header is unmapped */
1356 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001357 }
1358
1359 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001360 dma_unmap_page(rx_ring->dev,
1361 rx_buffer_info->page_dma,
1362 PAGE_SIZE / 2,
1363 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001364 rx_buffer_info->page_dma = 0;
1365 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001366 rx_buffer_info->page,
1367 rx_buffer_info->page_offset,
1368 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001369
Alexander Duyckc267fc12010-11-16 19:27:00 -08001370 if ((page_count(rx_buffer_info->page) == 1) &&
1371 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001372 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001373 else
1374 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001375
1376 skb->len += upper_len;
1377 skb->data_len += upper_len;
1378 skb->truesize += upper_len;
1379 }
1380
1381 i++;
1382 if (i == rx_ring->count)
1383 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001384
Alexander Duyck31f05a22010-08-19 13:40:31 +00001385 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001386 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001387 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001388
Alexander Duyckaa801752010-11-16 19:27:02 -08001389 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001390 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1391 IXGBE_RXDADV_NEXTP_SHIFT;
1392 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001393 } else {
1394 next_buffer = &rx_ring->rx_buffer_info[i];
1395 }
1396
Alexander Duyckc267fc12010-11-16 19:27:00 -08001397 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001398 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001399 rx_buffer_info->skb = next_buffer->skb;
1400 rx_buffer_info->dma = next_buffer->dma;
1401 next_buffer->skb = skb;
1402 next_buffer->dma = 0;
1403 } else {
1404 skb->next = next_buffer->skb;
1405 skb->next->prev = skb;
1406 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001407 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001408 goto next_desc;
1409 }
1410
Alexander Duyckaa801752010-11-16 19:27:02 -08001411 if (skb->prev) {
1412 skb = ixgbe_transform_rsc_queue(skb);
1413 /* if we got here without RSC the packet is invalid */
1414 if (!pkt_is_rsc) {
1415 __pskb_trim(skb, 0);
1416 rx_buffer_info->skb = skb;
1417 goto next_desc;
1418 }
1419 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001420
1421 if (ring_is_rsc_enabled(rx_ring)) {
1422 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1423 dma_unmap_single(rx_ring->dev,
1424 IXGBE_RSC_CB(skb)->dma,
1425 rx_ring->rx_buf_len,
1426 DMA_FROM_DEVICE);
1427 IXGBE_RSC_CB(skb)->dma = 0;
1428 IXGBE_RSC_CB(skb)->delay_unmap = false;
1429 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001430 }
1431 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001432 if (ring_is_ps_enabled(rx_ring))
1433 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001434 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001435 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001436 rx_ring->rx_stats.rsc_count +=
1437 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001438 rx_ring->rx_stats.rsc_flush++;
1439 }
1440
1441 /* ERR_MASK will only have valid bits if EOP set */
Alexander Duyckff886df2011-06-11 01:45:13 +00001442 if (unlikely(staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK)) {
1443 dev_kfree_skb_any(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001444 goto next_desc;
1445 }
1446
Alexander Duyckff886df2011-06-11 01:45:13 +00001447 ixgbe_rx_checksum(adapter, rx_desc, skb, staterr);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001448 if (adapter->netdev->features & NETIF_F_RXHASH)
1449 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001450
1451 /* probably a little skewed due to removing CRC */
1452 total_rx_bytes += skb->len;
1453 total_rx_packets++;
1454
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001455 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001456#ifdef IXGBE_FCOE
1457 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Alexander Duyckff886df2011-06-11 01:45:13 +00001458 if (ixgbe_rx_is_fcoe(adapter, rx_desc)) {
1459 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb,
1460 staterr);
Yi Zou3d8fd382009-06-08 14:38:44 +00001461 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001462 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001463 }
Yi Zou332d4a72009-05-13 13:11:53 +00001464#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001465 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001466
1467next_desc:
1468 rx_desc->wb.upper.status_error = 0;
1469
Alexander Duyckc267fc12010-11-16 19:27:00 -08001470 (*work_done)++;
1471 if (*work_done >= work_to_do)
1472 break;
1473
Auke Kok9a799d72007-09-15 14:07:45 -07001474 /* return some buffers to hardware, one at a time is too slow */
1475 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001476 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001477 cleaned_count = 0;
1478 }
1479
1480 /* use prefetched values */
1481 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001482 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001483 }
1484
Auke Kok9a799d72007-09-15 14:07:45 -07001485 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001486 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001487
1488 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001489 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001490
Yi Zou3d8fd382009-06-08 14:38:44 +00001491#ifdef IXGBE_FCOE
1492 /* include DDPed FCoE data */
1493 if (ddp_bytes > 0) {
1494 unsigned int mss;
1495
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001496 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001497 sizeof(struct fc_frame_header) -
1498 sizeof(struct fcoe_crc_eof);
1499 if (mss > 512)
1500 mss &= ~511;
1501 total_rx_bytes += ddp_bytes;
1502 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1503 }
1504#endif /* IXGBE_FCOE */
1505
Alexander Duyckc267fc12010-11-16 19:27:00 -08001506 u64_stats_update_begin(&rx_ring->syncp);
1507 rx_ring->stats.packets += total_rx_packets;
1508 rx_ring->stats.bytes += total_rx_bytes;
1509 u64_stats_update_end(&rx_ring->syncp);
Alexander Duyckbd198052011-06-11 01:45:08 +00001510 q_vector->rx.total_packets += total_rx_packets;
1511 q_vector->rx.total_bytes += total_rx_bytes;
Auke Kok9a799d72007-09-15 14:07:45 -07001512}
1513
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001514static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001515/**
1516 * ixgbe_configure_msix - Configure MSI-X hardware
1517 * @adapter: board private structure
1518 *
1519 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1520 * interrupts.
1521 **/
1522static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1523{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001524 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001525 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001526 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001527
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001528 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1529
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001530 /*
1531 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001532 * corresponding register.
1533 */
1534 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001535 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001536 /* XXX for_each_set_bit(...) */
Alexander Duyck08c88332011-06-11 01:45:03 +00001537 r_idx = find_first_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001538 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001539
Alexander Duyck08c88332011-06-11 01:45:03 +00001540 for (i = 0; i < q_vector->rx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001541 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1542 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001543 r_idx = find_next_bit(q_vector->rx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001544 adapter->num_rx_queues,
1545 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001546 }
Alexander Duyck08c88332011-06-11 01:45:03 +00001547 r_idx = find_first_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001548 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001549
Alexander Duyck08c88332011-06-11 01:45:03 +00001550 for (i = 0; i < q_vector->tx.count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001551 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1552 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Alexander Duyck08c88332011-06-11 01:45:03 +00001553 r_idx = find_next_bit(q_vector->tx.idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001554 adapter->num_tx_queues,
1555 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556 }
1557
Alexander Duyck08c88332011-06-11 01:45:03 +00001558 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001559 /* tx only */
1560 q_vector->eitr = adapter->tx_eitr_param;
Alexander Duyck08c88332011-06-11 01:45:03 +00001561 else if (q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001562 /* rx or mixed */
1563 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001564
Alexander Duyckfe49f042009-06-04 16:00:09 +00001565 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001566 /* If ATR is enabled, set interrupt affinity */
1567 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001568 /*
1569 * Allocate the affinity_hint cpumask, assign the mask
1570 * for this vector, and set our affinity_hint for
1571 * this irq.
1572 */
1573 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1574 GFP_KERNEL))
1575 return;
1576 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1577 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1578 q_vector->affinity_mask);
1579 }
Auke Kok9a799d72007-09-15 14:07:45 -07001580 }
1581
Alexander Duyckbd508172010-11-16 19:27:03 -08001582 switch (adapter->hw.mac.type) {
1583 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001584 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001585 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001586 break;
1587 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001588 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001589 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001590 break;
1591
1592 default:
1593 break;
1594 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001595 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001596
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001597 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001598 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001599 if (adapter->num_vfs)
1600 mask &= ~(IXGBE_EIMS_OTHER |
1601 IXGBE_EIMS_MAILBOX |
1602 IXGBE_EIMS_LSC);
1603 else
1604 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001605 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001606}
1607
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001608enum latency_range {
1609 lowest_latency = 0,
1610 low_latency = 1,
1611 bulk_latency = 2,
1612 latency_invalid = 255
1613};
1614
1615/**
1616 * ixgbe_update_itr - update the dynamic ITR value based on statistics
Alexander Duyckbd198052011-06-11 01:45:08 +00001617 * @q_vector: structure containing interrupt and ring information
1618 * @ring_container: structure containing ring performance data
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001619 *
1620 * Stores a new ITR value based on packets and byte
1621 * counts during the last interrupt. The advantage of per interrupt
1622 * computation is faster updates and more accurate ITR for the current
1623 * traffic pattern. Constants in this function were computed
1624 * based on theoretical maximum wire speed and thresholds were set based
1625 * on testing data as well as attempting to minimize response time
1626 * while increasing bulk throughput.
1627 * this functionality is controlled by the InterruptThrottleRate module
1628 * parameter (see ixgbe_param.c)
1629 **/
Alexander Duyckbd198052011-06-11 01:45:08 +00001630static void ixgbe_update_itr(struct ixgbe_q_vector *q_vector,
1631 struct ixgbe_ring_container *ring_container)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001632{
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001633 u64 bytes_perint;
Alexander Duyckbd198052011-06-11 01:45:08 +00001634 struct ixgbe_adapter *adapter = q_vector->adapter;
1635 int bytes = ring_container->total_bytes;
1636 int packets = ring_container->total_packets;
1637 u32 timepassed_us;
1638 u8 itr_setting = ring_container->itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001639
1640 if (packets == 0)
Alexander Duyckbd198052011-06-11 01:45:08 +00001641 return;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001642
1643 /* simple throttlerate management
1644 * 0-20MB/s lowest (100000 ints/s)
1645 * 20-100MB/s low (20000 ints/s)
1646 * 100-1249MB/s bulk (8000 ints/s)
1647 */
1648 /* what was last interrupt timeslice? */
Alexander Duyckbd198052011-06-11 01:45:08 +00001649 timepassed_us = 1000000/q_vector->eitr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001650 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1651
1652 switch (itr_setting) {
1653 case lowest_latency:
1654 if (bytes_perint > adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001655 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001656 break;
1657 case low_latency:
1658 if (bytes_perint > adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001659 itr_setting = bulk_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001660 else if (bytes_perint <= adapter->eitr_low)
Alexander Duyckbd198052011-06-11 01:45:08 +00001661 itr_setting = lowest_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001662 break;
1663 case bulk_latency:
1664 if (bytes_perint <= adapter->eitr_high)
Alexander Duyckbd198052011-06-11 01:45:08 +00001665 itr_setting = low_latency;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001666 break;
1667 }
1668
Alexander Duyckbd198052011-06-11 01:45:08 +00001669 /* clear work counters since we have the values we need */
1670 ring_container->total_bytes = 0;
1671 ring_container->total_packets = 0;
1672
1673 /* write updated itr to ring container */
1674 ring_container->itr = itr_setting;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001675}
1676
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001677/**
1678 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001679 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001680 *
1681 * This function is made to be called by ethtool and by the driver
1682 * when it needs to update EITR registers at runtime. Hardware
1683 * specific quirks/differences are taken care of here.
1684 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001685void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001686{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001687 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001688 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001689 int v_idx = q_vector->v_idx;
1690 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1691
Alexander Duyckbd508172010-11-16 19:27:03 -08001692 switch (adapter->hw.mac.type) {
1693 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001694 /* must write high and low 16 bits to reset counter */
1695 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001696 break;
1697 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001698 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001699 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001700 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001701 * max interrupt rate, but there is an errata where it can
1702 * not be zero with RSC
1703 */
1704 if (itr_reg == 8 &&
1705 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1706 itr_reg = 0;
1707
1708 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001709 * set the WDIS bit to not clear the timer bits and cause an
1710 * immediate assertion of the interrupt
1711 */
1712 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001713 break;
1714 default:
1715 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001716 }
1717 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1718}
1719
Alexander Duyckbd198052011-06-11 01:45:08 +00001720static void ixgbe_set_itr(struct ixgbe_q_vector *q_vector)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001721{
Alexander Duyckbd198052011-06-11 01:45:08 +00001722 u32 new_itr = q_vector->eitr;
1723 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001724
Alexander Duyckbd198052011-06-11 01:45:08 +00001725 ixgbe_update_itr(q_vector, &q_vector->tx);
1726 ixgbe_update_itr(q_vector, &q_vector->rx);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001727
Alexander Duyck08c88332011-06-11 01:45:03 +00001728 current_itr = max(q_vector->rx.itr, q_vector->tx.itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001729
1730 switch (current_itr) {
1731 /* counts and packets in update_itr are dependent on these numbers */
1732 case lowest_latency:
1733 new_itr = 100000;
1734 break;
1735 case low_latency:
1736 new_itr = 20000; /* aka hwitr = ~200 */
1737 break;
1738 case bulk_latency:
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001739 new_itr = 8000;
1740 break;
Alexander Duyckbd198052011-06-11 01:45:08 +00001741 default:
1742 break;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001743 }
1744
1745 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001746 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001747 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001748
Alexander Duyckbd198052011-06-11 01:45:08 +00001749 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001750 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001751
1752 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001753 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001754}
1755
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001756/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001757 * ixgbe_check_overtemp_subtask - check for over tempurature
1758 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001759 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001760static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001761{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001762 struct ixgbe_hw *hw = &adapter->hw;
1763 u32 eicr = adapter->interrupt_event;
1764
Alexander Duyckf0f97782011-04-22 04:08:09 +00001765 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001766 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001767
Alexander Duyckf0f97782011-04-22 04:08:09 +00001768 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1769 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1770 return;
1771
1772 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1773
Joe Perches7ca647b2010-09-07 21:35:40 +00001774 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001775 case IXGBE_DEV_ID_82599_T3_LOM:
1776 /*
1777 * Since the warning interrupt is for both ports
1778 * we don't have to check if:
1779 * - This interrupt wasn't for our port.
1780 * - We may have missed the interrupt so always have to
1781 * check if we got a LSC
1782 */
1783 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1784 !(eicr & IXGBE_EICR_LSC))
1785 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001786
Alexander Duyckf0f97782011-04-22 04:08:09 +00001787 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1788 u32 autoneg;
1789 bool link_up = false;
1790
Joe Perches7ca647b2010-09-07 21:35:40 +00001791 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1792
Alexander Duyckf0f97782011-04-22 04:08:09 +00001793 if (link_up)
1794 return;
1795 }
1796
1797 /* Check if this is not due to overtemp */
1798 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1799 return;
1800
1801 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001802 default:
1803 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1804 return;
1805 break;
1806 }
1807 e_crit(drv,
1808 "Network adapter has been stopped because it has over heated. "
1809 "Restart the computer. If the problem persists, "
1810 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001811
1812 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001813}
1814
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001815static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1816{
1817 struct ixgbe_hw *hw = &adapter->hw;
1818
1819 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1820 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001821 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001822 /* write to clear the interrupt */
1823 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1824 }
1825}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001826
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001827static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1828{
1829 struct ixgbe_hw *hw = &adapter->hw;
1830
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001831 if (eicr & IXGBE_EICR_GPI_SDP2) {
1832 /* Clear the interrupt */
1833 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001834 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1835 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1836 ixgbe_service_event_schedule(adapter);
1837 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001838 }
1839
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001840 if (eicr & IXGBE_EICR_GPI_SDP1) {
1841 /* Clear the interrupt */
1842 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001843 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1844 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1845 ixgbe_service_event_schedule(adapter);
1846 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001847 }
1848}
1849
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001850static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1851{
1852 struct ixgbe_hw *hw = &adapter->hw;
1853
1854 adapter->lsc_int++;
1855 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1856 adapter->link_check_timeout = jiffies;
1857 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1858 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001859 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001860 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001861 }
1862}
1863
Auke Kok9a799d72007-09-15 14:07:45 -07001864static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1865{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001866 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001867 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001868 u32 eicr;
1869
1870 /*
1871 * Workaround for Silicon errata. Use clear-by-write instead
1872 * of clear-by-read. Reading with EICS will return the
1873 * interrupt causes without clearing, which later be done
1874 * with the write to EICR.
1875 */
1876 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1877 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001878
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001879 if (eicr & IXGBE_EICR_LSC)
1880 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001881
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001882 if (eicr & IXGBE_EICR_MAILBOX)
1883 ixgbe_msg_task(adapter);
1884
Alexander Duyckbd508172010-11-16 19:27:03 -08001885 switch (hw->mac.type) {
1886 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001887 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001888 /* Handle Flow Director Full threshold interrupt */
1889 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001890 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001891 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001892 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001893 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001894 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001895 &ring->state))
1896 reinit_count++;
1897 }
1898 if (reinit_count) {
1899 /* no more flow director interrupts until after init */
1900 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1901 eicr &= ~IXGBE_EICR_FLOW_DIR;
1902 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1903 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001904 }
1905 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001906 ixgbe_check_sfp_event(adapter, eicr);
1907 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1908 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1909 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1910 adapter->interrupt_event = eicr;
1911 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1912 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001913 }
1914 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001915 break;
1916 default:
1917 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001918 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001919
1920 ixgbe_check_fan_failure(adapter, eicr);
1921
Alexander Duyck70864002011-04-27 09:13:56 +00001922 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001923 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001924 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1925 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001926
1927 return IRQ_HANDLED;
1928}
1929
Alexander Duyckfe49f042009-06-04 16:00:09 +00001930static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1931 u64 qmask)
1932{
1933 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001934 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001935
Alexander Duyckbd508172010-11-16 19:27:03 -08001936 switch (hw->mac.type) {
1937 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001938 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001939 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1940 break;
1941 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001942 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001943 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001944 if (mask)
1945 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001946 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001947 if (mask)
1948 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1949 break;
1950 default:
1951 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001952 }
1953 /* skip the flush */
1954}
1955
1956static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001957 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001958{
1959 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001960 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001961
Alexander Duyckbd508172010-11-16 19:27:03 -08001962 switch (hw->mac.type) {
1963 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001964 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001965 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1966 break;
1967 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001968 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001969 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001970 if (mask)
1971 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001972 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001973 if (mask)
1974 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1975 break;
1976 default:
1977 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001978 }
1979 /* skip the flush */
1980}
1981
Auke Kok9a799d72007-09-15 14:07:45 -07001982static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1983{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001984 struct ixgbe_q_vector *q_vector = data;
1985 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001986 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001987 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07001988
Alexander Duyck08c88332011-06-11 01:45:03 +00001989 if (!q_vector->tx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001990 return IRQ_HANDLED;
1991
Alexander Duyck08c88332011-06-11 01:45:03 +00001992 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
1993 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00001994 tx_ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00001995 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001996 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001997 }
1998
Jesse Brandeburg9b471442009-12-03 11:33:54 +00001999 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002000 napi_schedule(&q_vector->napi);
2001
Auke Kok9a799d72007-09-15 14:07:45 -07002002 return IRQ_HANDLED;
2003}
2004
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002005/**
2006 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2007 * @irq: unused
2008 * @data: pointer to our q_vector struct for this interrupt vector
2009 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002010static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2011{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002012 struct ixgbe_q_vector *q_vector = data;
2013 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002014 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002015 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002016 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002017
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002018#ifdef CONFIG_IXGBE_DCA
2019 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2020 ixgbe_update_dca(q_vector);
2021#endif
2022
Alexander Duyck08c88332011-06-11 01:45:03 +00002023 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2024 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002025 rx_ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002026 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002027 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002028 }
2029
Alexander Duyck08c88332011-06-11 01:45:03 +00002030 if (!q_vector->rx.count)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002031 return IRQ_HANDLED;
2032
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002033 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002034 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002035
Auke Kok9a799d72007-09-15 14:07:45 -07002036 return IRQ_HANDLED;
2037}
2038
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002039static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2040{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002041 struct ixgbe_q_vector *q_vector = data;
2042 struct ixgbe_adapter *adapter = q_vector->adapter;
2043 struct ixgbe_ring *ring;
2044 int r_idx;
2045 int i;
2046
Alexander Duyck08c88332011-06-11 01:45:03 +00002047 if (!q_vector->tx.count && !q_vector->rx.count)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002048 return IRQ_HANDLED;
2049
Alexander Duyck08c88332011-06-11 01:45:03 +00002050 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2051 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002052 ring = adapter->tx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002053 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002054 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002055 }
2056
Alexander Duyck08c88332011-06-11 01:45:03 +00002057 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2058 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002059 ring = adapter->rx_ring[r_idx];
Alexander Duyck08c88332011-06-11 01:45:03 +00002060 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002061 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002062 }
2063
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002064 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002065 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002066
2067 return IRQ_HANDLED;
2068}
2069
2070/**
2071 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2072 * @napi: napi struct with our devices info in it
2073 * @budget: amount of work driver is allowed to do this pass, in packets
2074 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002075 * This function is optimized for cleaning one queue only on a single
2076 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002077 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002078static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2079{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002080 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002081 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002082 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002083 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002084 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002085 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002086
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002087#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002088 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002089 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002090#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002091
Alexander Duyck08c88332011-06-11 01:45:03 +00002092 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002093 rx_ring = adapter->rx_ring[r_idx];
2094
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002095 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002096
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002097 /* If all Rx work done, exit the polling mode */
2098 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002099 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002100 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002101 ixgbe_set_itr(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002102 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002103 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002104 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002105 }
2106
2107 return work_done;
2108}
2109
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002110/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002111 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002112 * @napi: napi struct with our devices info in it
2113 * @budget: amount of work driver is allowed to do this pass, in packets
2114 *
2115 * This function will clean more than one rx queue associated with a
2116 * q_vector.
2117 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002118static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002119{
2120 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002121 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002122 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002123 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002124 int work_done = 0, i;
2125 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002126 bool tx_clean_complete = true;
2127
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002128#ifdef CONFIG_IXGBE_DCA
2129 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2130 ixgbe_update_dca(q_vector);
2131#endif
2132
Alexander Duyck08c88332011-06-11 01:45:03 +00002133 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
2134 for (i = 0; i < q_vector->tx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002135 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002136 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
Alexander Duyck08c88332011-06-11 01:45:03 +00002137 r_idx = find_next_bit(q_vector->tx.idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002138 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002139 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002140
2141 /* attempt to distribute budget to each queue fairly, but don't allow
2142 * the budget to go below 1 because we'll exit polling */
Alexander Duyck08c88332011-06-11 01:45:03 +00002143 budget /= (q_vector->rx.count ?: 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002144 budget = max(budget, 1);
Alexander Duyck08c88332011-06-11 01:45:03 +00002145 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
2146 for (i = 0; i < q_vector->rx.count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002147 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002148 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Alexander Duyck08c88332011-06-11 01:45:03 +00002149 r_idx = find_next_bit(q_vector->rx.idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002150 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002151 }
2152
Alexander Duyck08c88332011-06-11 01:45:03 +00002153 r_idx = find_first_bit(q_vector->rx.idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002154 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002155 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002156 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002157 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002158 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002159 ixgbe_set_itr(q_vector);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002160 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002161 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002162 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002163 return 0;
2164 }
2165
2166 return work_done;
2167}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002168
2169/**
2170 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2171 * @napi: napi struct with our devices info in it
2172 * @budget: amount of work driver is allowed to do this pass, in packets
2173 *
2174 * This function is optimized for cleaning one queue only on a single
2175 * q_vector!!!
2176 **/
2177static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2178{
2179 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002180 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002181 struct ixgbe_adapter *adapter = q_vector->adapter;
2182 struct ixgbe_ring *tx_ring = NULL;
2183 int work_done = 0;
2184 long r_idx;
2185
Alexander Duyck91281fd2009-06-04 16:00:27 +00002186#ifdef CONFIG_IXGBE_DCA
2187 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002188 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002189#endif
2190
Alexander Duyck08c88332011-06-11 01:45:03 +00002191 r_idx = find_first_bit(q_vector->tx.idx, adapter->num_tx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002192 tx_ring = adapter->tx_ring[r_idx];
2193
Alexander Duyck91281fd2009-06-04 16:00:27 +00002194 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2195 work_done = budget;
2196
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002197 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002198 if (work_done < budget) {
2199 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002200 if (adapter->tx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00002201 ixgbe_set_itr(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002202 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002203 ixgbe_irq_enable_queues(adapter,
2204 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002205 }
2206
2207 return work_done;
2208}
2209
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002210static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002211 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002212{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002213 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002214 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002215
Alexander Duyck08c88332011-06-11 01:45:03 +00002216 set_bit(r_idx, q_vector->rx.idx);
2217 q_vector->rx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002218 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002219}
Auke Kok9a799d72007-09-15 14:07:45 -07002220
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002221static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002222 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002223{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002224 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002225 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002226
Alexander Duyck08c88332011-06-11 01:45:03 +00002227 set_bit(t_idx, q_vector->tx.idx);
2228 q_vector->tx.count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002229 tx_ring->q_vector = q_vector;
Alexander Duyckbd198052011-06-11 01:45:08 +00002230 q_vector->tx.work_limit = a->tx_work_limit;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002231}
Auke Kok9a799d72007-09-15 14:07:45 -07002232
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002233/**
2234 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2235 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236 *
2237 * This function maps descriptor rings to the queue-specific vectors
2238 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2239 * one vector per ring/queue, but on a constrained vector budget, we
2240 * group the rings as "efficiently" as possible. You would add new
2241 * mapping configurations in here.
2242 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002243static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002244{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002245 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002246 int v_start = 0;
2247 int rxr_idx = 0, txr_idx = 0;
2248 int rxr_remaining = adapter->num_rx_queues;
2249 int txr_remaining = adapter->num_tx_queues;
2250 int i, j;
2251 int rqpv, tqpv;
2252 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002253
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254 /* No mapping required if MSI-X is disabled. */
2255 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002256 goto out;
2257
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002258 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2259
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002260 /*
2261 * The ideal configuration...
2262 * We have enough vectors to map one per queue.
2263 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002264 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002265 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2266 map_vector_to_rxq(adapter, v_start, rxr_idx);
2267
2268 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2269 map_vector_to_txq(adapter, v_start, txr_idx);
2270
2271 goto out;
2272 }
2273
2274 /*
2275 * If we don't have enough vectors for a 1-to-1
2276 * mapping, we'll have to group them so there are
2277 * multiple queues per vector.
2278 */
2279 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002280 for (i = v_start; i < q_vectors; i++) {
2281 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002282 for (j = 0; j < rqpv; j++) {
2283 map_vector_to_rxq(adapter, i, rxr_idx);
2284 rxr_idx++;
2285 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002286 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002287 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002288 for (j = 0; j < tqpv; j++) {
2289 map_vector_to_txq(adapter, i, txr_idx);
2290 txr_idx++;
2291 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002292 }
Auke Kok9a799d72007-09-15 14:07:45 -07002293 }
Auke Kok9a799d72007-09-15 14:07:45 -07002294out:
Auke Kok9a799d72007-09-15 14:07:45 -07002295 return err;
2296}
2297
2298/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002299 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2300 * @adapter: board private structure
2301 *
2302 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2303 * interrupts from the kernel.
2304 **/
2305static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2306{
2307 struct net_device *netdev = adapter->netdev;
2308 irqreturn_t (*handler)(int, void *);
2309 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002310 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002311
2312 /* Decrement for Other and TCP Timer vectors */
2313 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2314
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002315 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002316 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002317 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002318
Alexander Duyck08c88332011-06-11 01:45:03 +00002319#define SET_HANDLER(_v) (((_v)->rx.count && (_v)->tx.count) \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002320 ? &ixgbe_msix_clean_many : \
Alexander Duyck08c88332011-06-11 01:45:03 +00002321 (_v)->rx.count ? &ixgbe_msix_clean_rx : \
2322 (_v)->tx.count ? &ixgbe_msix_clean_tx : \
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002323 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002324 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002325 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2326 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002327
Joe Perchese8e9f692010-09-07 21:34:53 +00002328 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002329 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2330 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002331 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002332 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2333 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002334 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002335 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2336 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002337 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002338 } else {
2339 /* skip this unused q_vector */
2340 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002341 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002342 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002343 handler, 0, q_vector->name,
2344 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002345 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002346 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002347 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 goto free_queue_irqs;
2349 }
2350 }
2351
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002352 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002353 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002354 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002355 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002356 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002357 goto free_queue_irqs;
2358 }
2359
2360 return 0;
2361
2362free_queue_irqs:
2363 for (i = vector - 1; i >= 0; i--)
2364 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002365 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002366 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2367 pci_disable_msix(adapter->pdev);
2368 kfree(adapter->msix_entries);
2369 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002370 return err;
2371}
2372
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002373/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002374 * ixgbe_irq_enable - Enable default interrupt generation settings
2375 * @adapter: board private structure
2376 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002377static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2378 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002379{
2380 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002381
2382 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002383 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2384 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002385 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2386 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002387 switch (adapter->hw.mac.type) {
2388 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002389 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002390 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002391 mask |= IXGBE_EIMS_GPI_SDP1;
2392 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002393 if (adapter->num_vfs)
2394 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002395 break;
2396 default:
2397 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002398 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002399 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002400 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002401
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002402 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002403 if (queues)
2404 ixgbe_irq_enable_queues(adapter, ~0);
2405 if (flush)
2406 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002407
2408 if (adapter->num_vfs > 32) {
2409 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2410 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2411 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002412}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002413
2414/**
2415 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002416 * @irq: interrupt number
2417 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002418 **/
2419static irqreturn_t ixgbe_intr(int irq, void *data)
2420{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002421 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002422 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002423 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002424 u32 eicr;
2425
Don Skidmore54037502009-02-21 15:42:56 -08002426 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002427 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002428 * before the read of EICR.
2429 */
2430 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2431
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002432 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2433 * therefore no explict interrupt disable is necessary */
2434 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002435 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002436 /*
2437 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002438 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002439 * have disabled interrupts due to EIAM
2440 * finish the workaround of silicon errata on 82598. Unmask
2441 * the interrupt that we masked before the EICR read.
2442 */
2443 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2444 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002445 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002446 }
Auke Kok9a799d72007-09-15 14:07:45 -07002447
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002448 if (eicr & IXGBE_EICR_LSC)
2449 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002450
Alexander Duyckbd508172010-11-16 19:27:03 -08002451 switch (hw->mac.type) {
2452 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002453 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002454 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2455 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002456 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2457 adapter->interrupt_event = eicr;
2458 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2459 ixgbe_service_event_schedule(adapter);
2460 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002461 }
2462 break;
2463 default:
2464 break;
2465 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002466
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002467 ixgbe_check_fan_failure(adapter, eicr);
2468
Alexander Duyck7a921c92009-05-06 10:43:28 +00002469 if (napi_schedule_prep(&(q_vector->napi))) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002470 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002471 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002472 }
2473
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002474 /*
2475 * re-enable link(maybe) and non-queue interrupts, no flush.
2476 * ixgbe_poll will re-enable the queue interrupts
2477 */
2478
2479 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2480 ixgbe_irq_enable(adapter, false, false);
2481
Auke Kok9a799d72007-09-15 14:07:45 -07002482 return IRQ_HANDLED;
2483}
2484
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002485static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2486{
2487 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2488
2489 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002490 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00002491 bitmap_zero(q_vector->rx.idx, MAX_RX_QUEUES);
2492 bitmap_zero(q_vector->tx.idx, MAX_TX_QUEUES);
2493 q_vector->rx.count = 0;
2494 q_vector->tx.count = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002495 }
2496}
2497
Auke Kok9a799d72007-09-15 14:07:45 -07002498/**
2499 * ixgbe_request_irq - initialize interrupts
2500 * @adapter: board private structure
2501 *
2502 * Attempts to configure interrupts using the best available
2503 * capabilities of the hardware and kernel.
2504 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002505static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002506{
2507 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002508 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002509
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002510 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2511 err = ixgbe_request_msix_irqs(adapter);
2512 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002513 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002514 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002515 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002516 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002517 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002518 }
2519
Auke Kok9a799d72007-09-15 14:07:45 -07002520 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002521 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002522
Auke Kok9a799d72007-09-15 14:07:45 -07002523 return err;
2524}
2525
2526static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2527{
Auke Kok9a799d72007-09-15 14:07:45 -07002528 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002529 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002530
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002531 q_vectors = adapter->num_msix_vectors;
2532
2533 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002534 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002535
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002536 i--;
2537 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002538 /* free only the irqs that were actually requested */
Alexander Duyck08c88332011-06-11 01:45:03 +00002539 if (!adapter->q_vector[i]->rx.count &&
2540 !adapter->q_vector[i]->tx.count)
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002541 continue;
2542
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002543 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002544 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002545 }
2546
2547 ixgbe_reset_q_vectors(adapter);
2548 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002549 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002550 }
2551}
2552
2553/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002554 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2555 * @adapter: board private structure
2556 **/
2557static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2558{
Alexander Duyckbd508172010-11-16 19:27:03 -08002559 switch (adapter->hw.mac.type) {
2560 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002561 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002562 break;
2563 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002564 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002565 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2566 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002567 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002568 if (adapter->num_vfs > 32)
2569 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002570 break;
2571 default:
2572 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002573 }
2574 IXGBE_WRITE_FLUSH(&adapter->hw);
2575 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2576 int i;
2577 for (i = 0; i < adapter->num_msix_vectors; i++)
2578 synchronize_irq(adapter->msix_entries[i].vector);
2579 } else {
2580 synchronize_irq(adapter->pdev->irq);
2581 }
2582}
2583
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002584/**
Auke Kok9a799d72007-09-15 14:07:45 -07002585 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2586 *
2587 **/
2588static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2589{
Auke Kok9a799d72007-09-15 14:07:45 -07002590 struct ixgbe_hw *hw = &adapter->hw;
2591
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002592 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002593 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002594
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002595 ixgbe_set_ivar(adapter, 0, 0, 0);
2596 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002597
2598 map_vector_to_rxq(adapter, 0, 0);
2599 map_vector_to_txq(adapter, 0, 0);
2600
Emil Tantilov396e7992010-07-01 20:05:12 +00002601 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002602}
2603
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002604/**
2605 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2606 * @adapter: board private structure
2607 * @ring: structure containing ring specific data
2608 *
2609 * Configure the Tx descriptor ring after a reset.
2610 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002611void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2612 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002613{
2614 struct ixgbe_hw *hw = &adapter->hw;
2615 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002616 int wait_loop = 10;
2617 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002618 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002619
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002620 /* disable queue to avoid issues while updating state */
2621 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2622 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2623 txdctl & ~IXGBE_TXDCTL_ENABLE);
2624 IXGBE_WRITE_FLUSH(hw);
2625
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002626 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002627 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002628 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2629 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2630 ring->count * sizeof(union ixgbe_adv_tx_desc));
2631 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2632 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002633 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002634
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002635 /* configure fetching thresholds */
2636 if (adapter->rx_itr_setting == 0) {
2637 /* cannot set wthresh when itr==0 */
2638 txdctl &= ~0x007F0000;
2639 } else {
2640 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2641 txdctl |= (8 << 16);
2642 }
2643 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2644 /* PThresh workaround for Tx hang with DFP enabled. */
2645 txdctl |= 32;
2646 }
2647
2648 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002649 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2650 adapter->atr_sample_rate) {
2651 ring->atr_sample_rate = adapter->atr_sample_rate;
2652 ring->atr_count = 0;
2653 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2654 } else {
2655 ring->atr_sample_rate = 0;
2656 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002657
John Fastabendc84d3242010-11-16 19:27:12 -08002658 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2659
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002660 /* enable queue */
2661 txdctl |= IXGBE_TXDCTL_ENABLE;
2662 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2663
2664 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2665 if (hw->mac.type == ixgbe_mac_82598EB &&
2666 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2667 return;
2668
2669 /* poll to verify queue is enabled */
2670 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002671 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002672 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2673 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2674 if (!wait_loop)
2675 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002676}
2677
Alexander Duyck120ff942010-08-19 13:34:50 +00002678static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2679{
2680 struct ixgbe_hw *hw = &adapter->hw;
2681 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002682 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002683 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002684
2685 if (hw->mac.type == ixgbe_mac_82598EB)
2686 return;
2687
2688 /* disable the arbiter while setting MTQC */
2689 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2690 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2691 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2692
2693 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002694 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002695 case (IXGBE_FLAG_SRIOV_ENABLED):
2696 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2697 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2698 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002699 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002700 if (!tcs)
2701 reg = IXGBE_MTQC_64Q_1PB;
2702 else if (tcs <= 4)
2703 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2704 else
2705 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2706
2707 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2708
2709 /* Enable Security TX Buffer IFG for multiple pb */
2710 if (tcs) {
2711 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2712 reg |= IXGBE_SECTX_DCB;
2713 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2714 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002715 break;
2716 }
2717
2718 /* re-enable the arbiter */
2719 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2720 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2721}
2722
Auke Kok9a799d72007-09-15 14:07:45 -07002723/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002724 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002725 * @adapter: board private structure
2726 *
2727 * Configure the Tx unit of the MAC after a reset.
2728 **/
2729static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2730{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002731 struct ixgbe_hw *hw = &adapter->hw;
2732 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002733 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002734
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002735 ixgbe_setup_mtqc(adapter);
2736
2737 if (hw->mac.type != ixgbe_mac_82598EB) {
2738 /* DMATXCTL.EN must be before Tx queues are enabled */
2739 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2740 dmatxctl |= IXGBE_DMATXCTL_TE;
2741 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2742 }
2743
Auke Kok9a799d72007-09-15 14:07:45 -07002744 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002745 for (i = 0; i < adapter->num_tx_queues; i++)
2746 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002747}
2748
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002749#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002750
Yi Zoua6616b42009-08-06 13:05:23 +00002751static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002752 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002753{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002754 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002755 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002756
Alexander Duyckbd508172010-11-16 19:27:03 -08002757 switch (adapter->hw.mac.type) {
2758 case ixgbe_mac_82598EB: {
2759 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2760 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002761 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002762 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002763 break;
2764 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002765 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002766 default:
2767 break;
2768 }
2769
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002770 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002771
2772 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2773 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002774 if (adapter->num_vfs)
2775 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002776
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002777 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2778 IXGBE_SRRCTL_BSIZEHDR_MASK;
2779
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002780 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002781#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2782 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2783#else
2784 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2785#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002786 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002787 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002788 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2789 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002790 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002791 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002792
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002793 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002794}
2795
Alexander Duyck05abb122010-08-19 13:35:41 +00002796static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002797{
Alexander Duyck05abb122010-08-19 13:35:41 +00002798 struct ixgbe_hw *hw = &adapter->hw;
2799 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002800 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2801 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002802 u32 mrqc = 0, reta = 0;
2803 u32 rxcsum;
2804 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002805 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002806 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2807
2808 if (tcs)
2809 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002810
Alexander Duyck05abb122010-08-19 13:35:41 +00002811 /* Fill out hash function seeds */
2812 for (i = 0; i < 10; i++)
2813 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002814
Alexander Duyck05abb122010-08-19 13:35:41 +00002815 /* Fill out redirection table */
2816 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002817 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002818 j = 0;
2819 /* reta = 4-byte sliding window of
2820 * 0x00..(indices-1)(indices-1)00..etc. */
2821 reta = (reta << 8) | (j * 0x11);
2822 if ((i & 3) == 3)
2823 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2824 }
2825
2826 /* Disable indicating checksum in descriptor, enables RSS hash */
2827 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2828 rxcsum |= IXGBE_RXCSUM_PCSD;
2829 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2830
John Fastabend8b1c0b22011-05-03 02:26:48 +00002831 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2832 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002833 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002834 } else {
2835 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2836 | IXGBE_FLAG_SRIOV_ENABLED);
2837
2838 switch (mask) {
2839 case (IXGBE_FLAG_RSS_ENABLED):
2840 if (!tcs)
2841 mrqc = IXGBE_MRQC_RSSEN;
2842 else if (tcs <= 4)
2843 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2844 else
2845 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2846 break;
2847 case (IXGBE_FLAG_SRIOV_ENABLED):
2848 mrqc = IXGBE_MRQC_VMDQEN;
2849 break;
2850 default:
2851 break;
2852 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002853 }
2854
Alexander Duyck05abb122010-08-19 13:35:41 +00002855 /* Perform hash on these packet types */
2856 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2857 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2858 | IXGBE_MRQC_RSS_FIELD_IPV6
2859 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2860
2861 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002862}
2863
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002864/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002865 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2866 * @adapter: address of board private structure
2867 * @ring: structure containing ring specific data
2868 **/
2869void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2870 struct ixgbe_ring *ring)
2871{
2872 struct ixgbe_hw *hw = &adapter->hw;
2873 u32 rscctrl;
2874 u8 reg_idx = ring->reg_idx;
2875
2876 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2877 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
2878 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2879}
2880
2881/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002882 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2883 * @adapter: address of board private structure
2884 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002885 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08002886void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002887 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002888{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002889 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002890 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002891 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002892 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002893
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002894 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002895 return;
2896
2897 rx_buf_len = ring->rx_buf_len;
2898 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002899 rscctrl |= IXGBE_RSCCTL_RSCEN;
2900 /*
2901 * we must limit the number of descriptors so that the
2902 * total size of max desc * buf_len is not greater
2903 * than 65535
2904 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002905 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002906#if (MAX_SKB_FRAGS > 16)
2907 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2908#elif (MAX_SKB_FRAGS > 8)
2909 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2910#elif (MAX_SKB_FRAGS > 4)
2911 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2912#else
2913 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2914#endif
2915 } else {
2916 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2917 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2918 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2919 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2920 else
2921 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2922 }
Alexander Duyck73670962010-08-19 13:38:34 +00002923 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002924}
2925
Alexander Duyck9e10e042010-08-19 13:40:06 +00002926/**
2927 * ixgbe_set_uta - Set unicast filter table address
2928 * @adapter: board private structure
2929 *
2930 * The unicast table address is a register array of 32-bit registers.
2931 * The table is meant to be used in a way similar to how the MTA is used
2932 * however due to certain limitations in the hardware it is necessary to
2933 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
2934 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
2935 **/
2936static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
2937{
2938 struct ixgbe_hw *hw = &adapter->hw;
2939 int i;
2940
2941 /* The UTA table only exists on 82599 hardware and newer */
2942 if (hw->mac.type < ixgbe_mac_82599EB)
2943 return;
2944
2945 /* we only need to do this if VMDq is enabled */
2946 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
2947 return;
2948
2949 for (i = 0; i < 128; i++)
2950 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
2951}
2952
2953#define IXGBE_MAX_RX_DESC_POLL 10
2954static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
2955 struct ixgbe_ring *ring)
2956{
2957 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002958 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2959 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002960 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002961
2962 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2963 if (hw->mac.type == ixgbe_mac_82598EB &&
2964 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2965 return;
2966
2967 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002968 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00002969 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2970 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
2971
2972 if (!wait_loop) {
2973 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
2974 "the polling period\n", reg_idx);
2975 }
2976}
2977
Yi Zou2d39d572011-01-06 14:29:56 +00002978void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
2979 struct ixgbe_ring *ring)
2980{
2981 struct ixgbe_hw *hw = &adapter->hw;
2982 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
2983 u32 rxdctl;
2984 u8 reg_idx = ring->reg_idx;
2985
2986 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
2987 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
2988
2989 /* write value back with RXDCTL.ENABLE bit cleared */
2990 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
2991
2992 if (hw->mac.type == ixgbe_mac_82598EB &&
2993 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2994 return;
2995
2996 /* the hardware may take up to 100us to really disable the rx queue */
2997 do {
2998 udelay(10);
2999 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3000 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3001
3002 if (!wait_loop) {
3003 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3004 "the polling period\n", reg_idx);
3005 }
3006}
3007
Alexander Duyck84418e32010-08-19 13:40:54 +00003008void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3009 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003010{
3011 struct ixgbe_hw *hw = &adapter->hw;
3012 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003013 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003014 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003015
Alexander Duyck9e10e042010-08-19 13:40:06 +00003016 /* disable queue to avoid issues while updating state */
3017 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003018 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003019
Alexander Duyckacd37172010-08-19 13:36:05 +00003020 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3021 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3022 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3023 ring->count * sizeof(union ixgbe_adv_rx_desc));
3024 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3025 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003026 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003027
3028 ixgbe_configure_srrctl(adapter, ring);
3029 ixgbe_configure_rscctl(adapter, ring);
3030
Greg Rosee9f98072011-01-26 01:06:07 +00003031 /* If operating in IOV mode set RLPML for X540 */
3032 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3033 hw->mac.type == ixgbe_mac_X540) {
3034 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3035 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3036 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3037 }
3038
Alexander Duyck9e10e042010-08-19 13:40:06 +00003039 if (hw->mac.type == ixgbe_mac_82598EB) {
3040 /*
3041 * enable cache line friendly hardware writes:
3042 * PTHRESH=32 descriptors (half the internal cache),
3043 * this also removes ugly rx_no_buffer_count increment
3044 * HTHRESH=4 descriptors (to minimize latency on fetch)
3045 * WTHRESH=8 burst writeback up to two cache lines
3046 */
3047 rxdctl &= ~0x3FFFFF;
3048 rxdctl |= 0x080420;
3049 }
3050
3051 /* enable receive descriptor ring */
3052 rxdctl |= IXGBE_RXDCTL_ENABLE;
3053 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3054
3055 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003056 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003057}
3058
Alexander Duyck48654522010-08-19 13:36:27 +00003059static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3060{
3061 struct ixgbe_hw *hw = &adapter->hw;
3062 int p;
3063
3064 /* PSRTYPE must be initialized in non 82598 adapters */
3065 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003066 IXGBE_PSRTYPE_UDPHDR |
3067 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003068 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003069 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003070
3071 if (hw->mac.type == ixgbe_mac_82598EB)
3072 return;
3073
3074 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3075 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3076
3077 for (p = 0; p < adapter->num_rx_pools; p++)
3078 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3079 psrtype);
3080}
3081
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003082static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3083{
3084 struct ixgbe_hw *hw = &adapter->hw;
3085 u32 gcr_ext;
3086 u32 vt_reg_bits;
3087 u32 reg_offset, vf_shift;
3088 u32 vmdctl;
3089
3090 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3091 return;
3092
3093 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3094 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3095 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3096 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3097
3098 vf_shift = adapter->num_vfs % 32;
3099 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3100
3101 /* Enable only the PF's pool for Tx/Rx */
3102 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3103 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3104 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3105 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3106 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3107
3108 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3109 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3110
3111 /*
3112 * Set up VF register offsets for selected VT Mode,
3113 * i.e. 32 or 64 VFs for SR-IOV
3114 */
3115 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3116 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3117 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3118 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3119
3120 /* enable Tx loopback for VF/PF communication */
3121 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003122 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003123 hw->mac.ops.set_mac_anti_spoofing(hw,
3124 (adapter->antispoofing_enabled =
3125 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003126 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003127}
3128
Alexander Duyck477de6e2010-08-19 13:38:11 +00003129static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003130{
Auke Kok9a799d72007-09-15 14:07:45 -07003131 struct ixgbe_hw *hw = &adapter->hw;
3132 struct net_device *netdev = adapter->netdev;
3133 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003134 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003135 struct ixgbe_ring *rx_ring;
3136 int i;
3137 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003138
Auke Kok9a799d72007-09-15 14:07:45 -07003139 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003140 /* On by default */
3141 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3142
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003143 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003144 if (adapter->num_vfs)
3145 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3146
3147 /* Disable packet split due to 82599 erratum #45 */
3148 if (hw->mac.type == ixgbe_mac_82599EB)
3149 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003150
3151 /* Set the RX buffer length according to the mode */
3152 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003153 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003154 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003155 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003156 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003157 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003158 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003159 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3160 }
3161
3162#ifdef IXGBE_FCOE
3163 /* adjust max frame to be able to do baby jumbo for FCoE */
3164 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3165 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3166 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3167
3168#endif /* IXGBE_FCOE */
3169 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3170 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3171 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3172 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3173
3174 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003175 }
3176
Auke Kok9a799d72007-09-15 14:07:45 -07003177 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003178 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3179 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003180 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3181
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003182 /*
3183 * Setup the HW Rx Head and Tail Descriptor Pointers and
3184 * the Base and Length of the Rx Descriptor Ring
3185 */
Auke Kok9a799d72007-09-15 14:07:45 -07003186 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003187 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003188 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003189
Yi Zou6e455b892009-08-06 13:05:44 +00003190 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003191 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003192 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003193 clear_ring_ps_enabled(rx_ring);
3194
3195 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3196 set_ring_rsc_enabled(rx_ring);
3197 else
3198 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003199
Yi Zou63f39bd2009-05-17 12:34:35 +00003200#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003201 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003202 struct ixgbe_ring_feature *f;
3203 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003204 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003205 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003206 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3207 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003208 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003209 } else if (!ring_is_rsc_enabled(rx_ring) &&
3210 !ring_is_ps_enabled(rx_ring)) {
3211 rx_ring->rx_buf_len =
3212 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003213 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003214 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003215#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003216 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003217}
3218
Alexander Duyck73670962010-08-19 13:38:34 +00003219static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3220{
3221 struct ixgbe_hw *hw = &adapter->hw;
3222 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3223
3224 switch (hw->mac.type) {
3225 case ixgbe_mac_82598EB:
3226 /*
3227 * For VMDq support of different descriptor types or
3228 * buffer sizes through the use of multiple SRRCTL
3229 * registers, RDRXCTL.MVMEN must be set to 1
3230 *
3231 * also, the manual doesn't mention it clearly but DCA hints
3232 * will only use queue 0's tags unless this bit is set. Side
3233 * effects of setting this bit are only that SRRCTL must be
3234 * fully programmed [0..15]
3235 */
3236 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3237 break;
3238 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003239 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003240 /* Disable RSC for ACK packets */
3241 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3242 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3243 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3244 /* hardware requires some bits to be set by default */
3245 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3246 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3247 break;
3248 default:
3249 /* We should do nothing since we don't know this hardware */
3250 return;
3251 }
3252
3253 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3254}
3255
Alexander Duyck477de6e2010-08-19 13:38:11 +00003256/**
3257 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3258 * @adapter: board private structure
3259 *
3260 * Configure the Rx unit of the MAC after a reset.
3261 **/
3262static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3263{
3264 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003265 int i;
3266 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003267
3268 /* disable receives while setting up the descriptors */
3269 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3270 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3271
3272 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003273 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003274
Alexander Duyck9e10e042010-08-19 13:40:06 +00003275 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003276 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003277
Alexander Duyck9e10e042010-08-19 13:40:06 +00003278 ixgbe_set_uta(adapter);
3279
Alexander Duyck477de6e2010-08-19 13:38:11 +00003280 /* set_rx_buffer_len must be called before ring initialization */
3281 ixgbe_set_rx_buffer_len(adapter);
3282
3283 /*
3284 * Setup the HW Rx Head and Tail Descriptor Pointers and
3285 * the Base and Length of the Rx Descriptor Ring
3286 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003287 for (i = 0; i < adapter->num_rx_queues; i++)
3288 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003289
Alexander Duyck9e10e042010-08-19 13:40:06 +00003290 /* disable drop enable for 82598 parts */
3291 if (hw->mac.type == ixgbe_mac_82598EB)
3292 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3293
3294 /* enable all receives */
3295 rxctrl |= IXGBE_RXCTRL_RXEN;
3296 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003297}
3298
Auke Kok9a799d72007-09-15 14:07:45 -07003299static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3300{
3301 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003302 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003303 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003304
3305 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003306 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003307 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003308}
3309
3310static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3311{
3312 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003313 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003314 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003315
Auke Kok9a799d72007-09-15 14:07:45 -07003316 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003317 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003318 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003319}
3320
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003321/**
3322 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3323 * @adapter: driver data
3324 */
3325static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3326{
3327 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003328 u32 vlnctrl;
3329
3330 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3331 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3332 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3333}
3334
3335/**
3336 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3337 * @adapter: driver data
3338 */
3339static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3340{
3341 struct ixgbe_hw *hw = &adapter->hw;
3342 u32 vlnctrl;
3343
3344 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3345 vlnctrl |= IXGBE_VLNCTRL_VFE;
3346 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3347 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3348}
3349
3350/**
3351 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3352 * @adapter: driver data
3353 */
3354static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3355{
3356 struct ixgbe_hw *hw = &adapter->hw;
3357 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003358 int i, j;
3359
3360 switch (hw->mac.type) {
3361 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003362 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3363 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003364 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3365 break;
3366 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003367 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003368 for (i = 0; i < adapter->num_rx_queues; i++) {
3369 j = adapter->rx_ring[i]->reg_idx;
3370 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3371 vlnctrl &= ~IXGBE_RXDCTL_VME;
3372 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3373 }
3374 break;
3375 default:
3376 break;
3377 }
3378}
3379
3380/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003381 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003382 * @adapter: driver data
3383 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003384static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003385{
3386 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003387 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003388 int i, j;
3389
3390 switch (hw->mac.type) {
3391 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003392 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3393 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003394 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3395 break;
3396 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003397 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003398 for (i = 0; i < adapter->num_rx_queues; i++) {
3399 j = adapter->rx_ring[i]->reg_idx;
3400 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3401 vlnctrl |= IXGBE_RXDCTL_VME;
3402 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3403 }
3404 break;
3405 default:
3406 break;
3407 }
3408}
3409
Auke Kok9a799d72007-09-15 14:07:45 -07003410static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3411{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003412 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003413
Jesse Grossf62bbb52010-10-20 13:56:10 +00003414 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3415
3416 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3417 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003418}
3419
3420/**
Alexander Duyck28500622010-06-15 09:25:48 +00003421 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3422 * @netdev: network interface device structure
3423 *
3424 * Writes unicast address list to the RAR table.
3425 * Returns: -ENOMEM on failure/insufficient address space
3426 * 0 on no addresses written
3427 * X on writing X addresses to the RAR table
3428 **/
3429static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3430{
3431 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3432 struct ixgbe_hw *hw = &adapter->hw;
3433 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003434 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003435 int count = 0;
3436
3437 /* return ENOMEM indicating insufficient memory for addresses */
3438 if (netdev_uc_count(netdev) > rar_entries)
3439 return -ENOMEM;
3440
3441 if (!netdev_uc_empty(netdev) && rar_entries) {
3442 struct netdev_hw_addr *ha;
3443 /* return error if we do not support writing to RAR table */
3444 if (!hw->mac.ops.set_rar)
3445 return -ENOMEM;
3446
3447 netdev_for_each_uc_addr(ha, netdev) {
3448 if (!rar_entries)
3449 break;
3450 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3451 vfn, IXGBE_RAH_AV);
3452 count++;
3453 }
3454 }
3455 /* write the addresses in reverse order to avoid write combining */
3456 for (; rar_entries > 0 ; rar_entries--)
3457 hw->mac.ops.clear_rar(hw, rar_entries);
3458
3459 return count;
3460}
3461
3462/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003463 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003464 * @netdev: network interface device structure
3465 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003466 * The set_rx_method entry point is called whenever the unicast/multicast
3467 * address list or the network interface flags are updated. This routine is
3468 * responsible for configuring the hardware for proper unicast, multicast and
3469 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003470 **/
Greg Rose7f870472010-01-09 02:25:29 +00003471void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003472{
3473 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3474 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003475 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3476 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003477
3478 /* Check for Promiscuous and All Multicast modes */
3479
3480 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3481
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003482 /* set all bits that we expect to always be set */
3483 fctrl |= IXGBE_FCTRL_BAM;
3484 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3485 fctrl |= IXGBE_FCTRL_PMCF;
3486
Alexander Duyck28500622010-06-15 09:25:48 +00003487 /* clear the bits we are changing the status of */
3488 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3489
Auke Kok9a799d72007-09-15 14:07:45 -07003490 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003491 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003492 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003493 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003494 /* don't hardware filter vlans in promisc mode */
3495 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003496 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003497 if (netdev->flags & IFF_ALLMULTI) {
3498 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003499 vmolr |= IXGBE_VMOLR_MPE;
3500 } else {
3501 /*
3502 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003503 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003504 * that we can at least receive multicast traffic
3505 */
3506 hw->mac.ops.update_mc_addr_list(hw, netdev);
3507 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003508 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003509 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003510 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003511 /*
3512 * Write addresses to available RAR registers, if there is not
3513 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003514 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003515 */
3516 count = ixgbe_write_uc_addr_list(netdev);
3517 if (count < 0) {
3518 fctrl |= IXGBE_FCTRL_UPE;
3519 vmolr |= IXGBE_VMOLR_ROPE;
3520 }
3521 }
3522
3523 if (adapter->num_vfs) {
3524 ixgbe_restore_vf_multicasts(adapter);
3525 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3526 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3527 IXGBE_VMOLR_ROPE);
3528 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003529 }
3530
3531 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003532
3533 if (netdev->features & NETIF_F_HW_VLAN_RX)
3534 ixgbe_vlan_strip_enable(adapter);
3535 else
3536 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003537}
3538
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003539static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3540{
3541 int q_idx;
3542 struct ixgbe_q_vector *q_vector;
3543 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3544
3545 /* legacy and MSI only use one vector */
3546 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3547 q_vectors = 1;
3548
3549 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003550 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003551 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003552 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003553 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duyck08c88332011-06-11 01:45:03 +00003554 if (!q_vector->rx.count || !q_vector->tx.count) {
3555 if (q_vector->tx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003556 napi->poll = &ixgbe_clean_txonly;
Alexander Duyck08c88332011-06-11 01:45:03 +00003557 else if (q_vector->rx.count == 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00003558 napi->poll = &ixgbe_clean_rxonly;
3559 }
3560 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003561
3562 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003563 }
3564}
3565
3566static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3567{
3568 int q_idx;
3569 struct ixgbe_q_vector *q_vector;
3570 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3571
3572 /* legacy and MSI only use one vector */
3573 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3574 q_vectors = 1;
3575
3576 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003577 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003578 napi_disable(&q_vector->napi);
3579 }
3580}
3581
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003582#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003583/*
3584 * ixgbe_configure_dcb - Configure DCB hardware
3585 * @adapter: ixgbe adapter struct
3586 *
3587 * This is called by the driver on open to configure the DCB hardware.
3588 * This is also called by the gennetlink interface when reconfiguring
3589 * the DCB state.
3590 */
3591static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3592{
3593 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003594 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003595
Alexander Duyck67ebd792010-08-19 13:34:04 +00003596 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3597 if (hw->mac.type == ixgbe_mac_82598EB)
3598 netif_set_gso_max_size(adapter->netdev, 65536);
3599 return;
3600 }
3601
3602 if (hw->mac.type == ixgbe_mac_82598EB)
3603 netif_set_gso_max_size(adapter->netdev, 32768);
3604
Alexander Duyck2f90b862008-11-20 20:52:10 -08003605
Alexander Duyck2f90b862008-11-20 20:52:10 -08003606 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003607 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003608
Alexander Duyck2f90b862008-11-20 20:52:10 -08003609 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003610
3611 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003612 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003613#ifdef CONFIG_FCOE
3614 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3615 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3616#endif
3617 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3618 DCB_TX_CONFIG);
3619 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3620 DCB_RX_CONFIG);
3621 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3622 } else {
3623 struct net_device *dev = adapter->netdev;
3624
3625 if (adapter->ixgbe_ieee_ets)
3626 dev->dcbnl_ops->ieee_setets(dev,
3627 adapter->ixgbe_ieee_ets);
3628 if (adapter->ixgbe_ieee_pfc)
3629 dev->dcbnl_ops->ieee_setpfc(dev,
3630 adapter->ixgbe_ieee_pfc);
3631 }
John Fastabend8187cd42011-02-23 05:58:08 +00003632
3633 /* Enable RSS Hash per TC */
3634 if (hw->mac.type != ixgbe_mac_82598EB) {
3635 int i;
3636 u32 reg = 0;
3637
3638 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3639 u8 msb = 0;
3640 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3641
3642 while (cnt >>= 1)
3643 msb++;
3644
3645 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3646 }
3647 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3648 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003649}
3650
3651#endif
John Fastabend80605c652011-05-02 12:34:10 +00003652
3653static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3654{
3655 int hdrm = 0;
3656 int num_tc = netdev_get_num_tc(adapter->netdev);
3657 struct ixgbe_hw *hw = &adapter->hw;
3658
3659 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3660 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3661 hdrm = 64 << adapter->fdir_pballoc;
3662
3663 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3664}
3665
Alexander Duycke4911d52011-05-11 07:18:52 +00003666static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3667{
3668 struct ixgbe_hw *hw = &adapter->hw;
3669 struct hlist_node *node, *node2;
3670 struct ixgbe_fdir_filter *filter;
3671
3672 spin_lock(&adapter->fdir_perfect_lock);
3673
3674 if (!hlist_empty(&adapter->fdir_filter_list))
3675 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3676
3677 hlist_for_each_entry_safe(filter, node, node2,
3678 &adapter->fdir_filter_list, fdir_node) {
3679 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003680 &filter->filter,
3681 filter->sw_idx,
3682 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3683 IXGBE_FDIR_DROP_QUEUE :
3684 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003685 }
3686
3687 spin_unlock(&adapter->fdir_perfect_lock);
3688}
3689
Auke Kok9a799d72007-09-15 14:07:45 -07003690static void ixgbe_configure(struct ixgbe_adapter *adapter)
3691{
3692 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003693 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003694 int i;
3695
John Fastabend80605c652011-05-02 12:34:10 +00003696 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003697#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003698 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003699#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003700
Jesse Grossf62bbb52010-10-20 13:56:10 +00003701 ixgbe_set_rx_mode(netdev);
3702 ixgbe_restore_vlan(adapter);
3703
Yi Zoueacd73f2009-05-13 13:11:06 +00003704#ifdef IXGBE_FCOE
3705 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3706 ixgbe_configure_fcoe(adapter);
3707
3708#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003709 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3710 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003711 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003712 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003713 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003714 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3715 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3716 adapter->fdir_pballoc);
3717 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003718 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003719 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003720
Auke Kok9a799d72007-09-15 14:07:45 -07003721 ixgbe_configure_tx(adapter);
3722 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003723}
3724
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003725static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3726{
3727 switch (hw->phy.type) {
3728 case ixgbe_phy_sfp_avago:
3729 case ixgbe_phy_sfp_ftl:
3730 case ixgbe_phy_sfp_intel:
3731 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003732 case ixgbe_phy_sfp_passive_tyco:
3733 case ixgbe_phy_sfp_passive_unknown:
3734 case ixgbe_phy_sfp_active_unknown:
3735 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003736 return true;
3737 default:
3738 return false;
3739 }
3740}
3741
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003742/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003743 * ixgbe_sfp_link_config - set up SFP+ link
3744 * @adapter: pointer to private adapter struct
3745 **/
3746static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3747{
Alexander Duyck70864002011-04-27 09:13:56 +00003748 /*
3749 * We are assuming the worst case scenerio here, and that
3750 * is that an SFP was inserted/removed after the reset
3751 * but before SFP detection was enabled. As such the best
3752 * solution is to just start searching as soon as we start
3753 */
3754 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3755 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003756
Alexander Duyck70864002011-04-27 09:13:56 +00003757 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003758}
3759
3760/**
3761 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003762 * @hw: pointer to private hardware struct
3763 *
3764 * Returns 0 on success, negative on failure
3765 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003766static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003767{
3768 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003769 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003770 u32 ret = IXGBE_ERR_LINK_SETUP;
3771
3772 if (hw->mac.ops.check_link)
3773 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3774
3775 if (ret)
3776 goto link_cfg_out;
3777
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003778 autoneg = hw->phy.autoneg_advertised;
3779 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003780 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3781 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003782 if (ret)
3783 goto link_cfg_out;
3784
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003785 if (hw->mac.ops.setup_link)
3786 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003787link_cfg_out:
3788 return ret;
3789}
3790
Alexander Duycka34bcff2010-08-19 13:39:20 +00003791static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003792{
Auke Kok9a799d72007-09-15 14:07:45 -07003793 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003794 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003795
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003796 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003797 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3798 IXGBE_GPIE_OCD;
3799 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003800 /*
3801 * use EIAM to auto-mask when MSI-X interrupt is asserted
3802 * this saves a register write for every interrupt
3803 */
3804 switch (hw->mac.type) {
3805 case ixgbe_mac_82598EB:
3806 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3807 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003808 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003809 case ixgbe_mac_X540:
3810 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003811 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3812 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3813 break;
3814 }
3815 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003816 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3817 * specifically only auto mask tx and rx interrupts */
3818 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003819 }
3820
Alexander Duycka34bcff2010-08-19 13:39:20 +00003821 /* XXX: to interrupt immediately for EICS writes, enable this */
3822 /* gpie |= IXGBE_GPIE_EIMEN; */
3823
3824 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3825 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3826 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003827 }
3828
Alexander Duycka34bcff2010-08-19 13:39:20 +00003829 /* Enable fan failure interrupt */
3830 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003831 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003832
Don Skidmore2698b202011-04-13 07:01:52 +00003833 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003834 gpie |= IXGBE_SDP1_GPIEN;
3835 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003836 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003837
3838 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3839}
3840
3841static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3842{
3843 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003844 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003845 u32 ctrl_ext;
3846
3847 ixgbe_get_hw_control(adapter);
3848 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003849
Auke Kok9a799d72007-09-15 14:07:45 -07003850 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3851 ixgbe_configure_msix(adapter);
3852 else
3853 ixgbe_configure_msi_and_legacy(adapter);
3854
Don Skidmorec6ecf392010-12-03 03:31:51 +00003855 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3856 if (hw->mac.ops.enable_tx_laser &&
3857 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003858 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003859 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003860 hw->mac.ops.enable_tx_laser(hw);
3861
Auke Kok9a799d72007-09-15 14:07:45 -07003862 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003863 ixgbe_napi_enable_all(adapter);
3864
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003865 if (ixgbe_is_sfp(hw)) {
3866 ixgbe_sfp_link_config(adapter);
3867 } else {
3868 err = ixgbe_non_sfp_link_config(hw);
3869 if (err)
3870 e_err(probe, "link_config FAILED %d\n", err);
3871 }
3872
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003873 /* clear any pending interrupts, may auto mask */
3874 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003875 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003876
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003877 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003878 * If this adapter has a fan, check to see if we had a failure
3879 * before we enabled the interrupt.
3880 */
3881 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3882 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3883 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003884 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003885 }
3886
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003887 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003888 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003889
Auke Kok9a799d72007-09-15 14:07:45 -07003890 /* bring the link up in the watchdog, this could race with our first
3891 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003892 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3893 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003894 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003895
3896 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3897 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3898 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3899 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3900
Auke Kok9a799d72007-09-15 14:07:45 -07003901 return 0;
3902}
3903
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003904void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3905{
3906 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003907 /* put off any impending NetWatchDogTimeout */
3908 adapter->netdev->trans_start = jiffies;
3909
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003910 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003911 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003912 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003913 /*
3914 * If SR-IOV enabled then wait a bit before bringing the adapter
3915 * back up to give the VFs time to respond to the reset. The
3916 * two second wait is based upon the watchdog timer cycle in
3917 * the VF driver.
3918 */
3919 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3920 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003921 ixgbe_up(adapter);
3922 clear_bit(__IXGBE_RESETTING, &adapter->state);
3923}
3924
Auke Kok9a799d72007-09-15 14:07:45 -07003925int ixgbe_up(struct ixgbe_adapter *adapter)
3926{
3927 /* hardware has been reset, we need to reload some things */
3928 ixgbe_configure(adapter);
3929
3930 return ixgbe_up_complete(adapter);
3931}
3932
3933void ixgbe_reset(struct ixgbe_adapter *adapter)
3934{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003935 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003936 int err;
3937
Alexander Duyck70864002011-04-27 09:13:56 +00003938 /* lock SFP init bit to prevent race conditions with the watchdog */
3939 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3940 usleep_range(1000, 2000);
3941
3942 /* clear all SFP and link config related flags while holding SFP_INIT */
3943 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3944 IXGBE_FLAG2_SFP_NEEDS_RESET);
3945 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3946
Don Skidmore8ca783a2009-05-26 20:40:47 -07003947 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003948 switch (err) {
3949 case 0:
3950 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00003951 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003952 break;
3953 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003954 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003955 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003956 case IXGBE_ERR_EEPROM_VERSION:
3957 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003958 e_dev_warn("This device is a pre-production adapter/LOM. "
3959 "Please be aware there may be issuesassociated with "
3960 "your hardware. If you are experiencing problems "
3961 "please contact your Intel or hardware "
3962 "representative who provided you with this "
3963 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003964 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003965 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00003966 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003967 }
Auke Kok9a799d72007-09-15 14:07:45 -07003968
Alexander Duyck70864002011-04-27 09:13:56 +00003969 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
3970
Auke Kok9a799d72007-09-15 14:07:45 -07003971 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003972 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
3973 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07003974}
3975
Auke Kok9a799d72007-09-15 14:07:45 -07003976/**
3977 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07003978 * @rx_ring: ring to free buffers from
3979 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003980static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07003981{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003982 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07003983 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003984 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07003985
Alexander Duyck84418e32010-08-19 13:40:54 +00003986 /* ring already cleared, nothing to do */
3987 if (!rx_ring->rx_buffer_info)
3988 return;
Auke Kok9a799d72007-09-15 14:07:45 -07003989
Alexander Duyck84418e32010-08-19 13:40:54 +00003990 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07003991 for (i = 0; i < rx_ring->count; i++) {
3992 struct ixgbe_rx_buffer *rx_buffer_info;
3993
3994 rx_buffer_info = &rx_ring->rx_buffer_info[i];
3995 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08003996 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00003997 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00003998 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07003999 rx_buffer_info->dma = 0;
4000 }
4001 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004002 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004003 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004004 do {
4005 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004006 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004007 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004008 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004009 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004010 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004011 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004012 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004013 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004014 skb = skb->prev;
4015 dev_kfree_skb(this);
4016 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004017 }
4018 if (!rx_buffer_info->page)
4019 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004020 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004021 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004022 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004023 rx_buffer_info->page_dma = 0;
4024 }
Auke Kok9a799d72007-09-15 14:07:45 -07004025 put_page(rx_buffer_info->page);
4026 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004027 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004028 }
4029
4030 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4031 memset(rx_ring->rx_buffer_info, 0, size);
4032
4033 /* Zero out the descriptor ring */
4034 memset(rx_ring->desc, 0, rx_ring->size);
4035
4036 rx_ring->next_to_clean = 0;
4037 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004038}
4039
4040/**
4041 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004042 * @tx_ring: ring to be cleaned
4043 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004044static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004045{
4046 struct ixgbe_tx_buffer *tx_buffer_info;
4047 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004048 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004049
Alexander Duyck84418e32010-08-19 13:40:54 +00004050 /* ring already cleared, nothing to do */
4051 if (!tx_ring->tx_buffer_info)
4052 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004053
Alexander Duyck84418e32010-08-19 13:40:54 +00004054 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004055 for (i = 0; i < tx_ring->count; i++) {
4056 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004057 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004058 }
4059
4060 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4061 memset(tx_ring->tx_buffer_info, 0, size);
4062
4063 /* Zero out the descriptor ring */
4064 memset(tx_ring->desc, 0, tx_ring->size);
4065
4066 tx_ring->next_to_use = 0;
4067 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004068}
4069
4070/**
Auke Kok9a799d72007-09-15 14:07:45 -07004071 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4072 * @adapter: board private structure
4073 **/
4074static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4075{
4076 int i;
4077
4078 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004079 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004080}
4081
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004082/**
4083 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4084 * @adapter: board private structure
4085 **/
4086static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4087{
4088 int i;
4089
4090 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004091 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004092}
4093
Alexander Duycke4911d52011-05-11 07:18:52 +00004094static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4095{
4096 struct hlist_node *node, *node2;
4097 struct ixgbe_fdir_filter *filter;
4098
4099 spin_lock(&adapter->fdir_perfect_lock);
4100
4101 hlist_for_each_entry_safe(filter, node, node2,
4102 &adapter->fdir_filter_list, fdir_node) {
4103 hlist_del(&filter->fdir_node);
4104 kfree(filter);
4105 }
4106 adapter->fdir_filter_count = 0;
4107
4108 spin_unlock(&adapter->fdir_perfect_lock);
4109}
4110
Auke Kok9a799d72007-09-15 14:07:45 -07004111void ixgbe_down(struct ixgbe_adapter *adapter)
4112{
4113 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004114 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004115 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004116 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004117 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004118
4119 /* signal that we are down to the interrupt handler */
4120 set_bit(__IXGBE_DOWN, &adapter->state);
4121
4122 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004123 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4124 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004125
Yi Zou2d39d572011-01-06 14:29:56 +00004126 /* disable all enabled rx queues */
4127 for (i = 0; i < adapter->num_rx_queues; i++)
4128 /* this call also flushes the previous write */
4129 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4130
Don Skidmore032b4322011-03-18 09:32:53 +00004131 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004132
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004133 netif_tx_stop_all_queues(netdev);
4134
Alexander Duyck70864002011-04-27 09:13:56 +00004135 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004136 netif_carrier_off(netdev);
4137 netif_tx_disable(netdev);
4138
4139 ixgbe_irq_disable(adapter);
4140
4141 ixgbe_napi_disable_all(adapter);
4142
Alexander Duyckd034acf2011-04-27 09:25:34 +00004143 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4144 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004145 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4146
4147 del_timer_sync(&adapter->service_timer);
4148
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004149 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004150 if (adapter->num_vfs) {
4151 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004152 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004153
Auke Kok9a799d72007-09-15 14:07:45 -07004154 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004155 ixgbe_disable_tx_rx(adapter);
4156
4157 /* Mark all the VFs as inactive */
4158 for (i = 0 ; i < adapter->num_vfs; i++)
4159 adapter->vfinfo[i].clear_to_send = 0;
4160 }
4161
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004162 /* Cleanup the affinity_hint CPU mask memory and callback */
4163 for (i = 0; i < num_q_vectors; i++) {
4164 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4165 /* clear the affinity_mask in the IRQ descriptor */
4166 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4167 /* release the CPU mask memory */
4168 free_cpumask_var(q_vector->affinity_mask);
4169 }
4170
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004171 /* disable transmits in the hardware now that interrupts are off */
4172 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004173 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004174 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004175 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004176
4177 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004178 switch (hw->mac.type) {
4179 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004180 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004181 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004182 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4183 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004184 break;
4185 default:
4186 break;
4187 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004188
Paul Larson6f4a0e42008-06-24 17:00:56 -07004189 if (!pci_channel_offline(adapter->pdev))
4190 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004191
4192 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4193 if (hw->mac.ops.disable_tx_laser &&
4194 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004195 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004196 (hw->mac.type == ixgbe_mac_82599EB))))
4197 hw->mac.ops.disable_tx_laser(hw);
4198
Auke Kok9a799d72007-09-15 14:07:45 -07004199 ixgbe_clean_all_tx_rings(adapter);
4200 ixgbe_clean_all_rx_rings(adapter);
4201
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004202#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004203 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004204 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004205#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004206}
4207
Auke Kok9a799d72007-09-15 14:07:45 -07004208/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004209 * ixgbe_poll - NAPI Rx polling callback
4210 * @napi: structure for representing this polling device
4211 * @budget: how many packets driver is allowed to clean
4212 *
4213 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004214 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004215static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004216{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004217 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004218 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004219 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004220 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004221
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004222#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004223 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4224 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004225#endif
4226
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004227 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4228 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004229
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004230 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004231 work_done = budget;
4232
David S. Miller53e52c72008-01-07 21:06:12 -08004233 /* If budget not fully consumed, exit the polling mode */
4234 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004235 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004236 if (adapter->rx_itr_setting & 1)
Alexander Duyckbd198052011-06-11 01:45:08 +00004237 ixgbe_set_itr(q_vector);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004238 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004239 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004240 }
Auke Kok9a799d72007-09-15 14:07:45 -07004241 return work_done;
4242}
4243
4244/**
4245 * ixgbe_tx_timeout - Respond to a Tx Hang
4246 * @netdev: network interface device structure
4247 **/
4248static void ixgbe_tx_timeout(struct net_device *netdev)
4249{
4250 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4251
4252 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004253 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004254}
4255
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004256/**
4257 * ixgbe_set_rss_queues: Allocate queues for RSS
4258 * @adapter: board private structure to initialize
4259 *
4260 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4261 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4262 *
4263 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004264static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4265{
4266 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004267 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004268
4269 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004270 f->mask = 0xF;
4271 adapter->num_rx_queues = f->indices;
4272 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004273 ret = true;
4274 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004275 ret = false;
4276 }
4277
4278 return ret;
4279}
4280
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004281/**
4282 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4283 * @adapter: board private structure to initialize
4284 *
4285 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4286 * to the original CPU that initiated the Tx session. This runs in addition
4287 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4288 * Rx load across CPUs using RSS.
4289 *
4290 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004291static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004292{
4293 bool ret = false;
4294 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4295
4296 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4297 f_fdir->mask = 0;
4298
4299 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004300 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4301 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004302 adapter->num_tx_queues = f_fdir->indices;
4303 adapter->num_rx_queues = f_fdir->indices;
4304 ret = true;
4305 } else {
4306 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004307 }
4308 return ret;
4309}
4310
Yi Zou0331a832009-05-17 12:33:52 +00004311#ifdef IXGBE_FCOE
4312/**
4313 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4314 * @adapter: board private structure to initialize
4315 *
4316 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4317 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4318 * rx queues out of the max number of rx queues, instead, it is used as the
4319 * index of the first rx queue used by FCoE.
4320 *
4321 **/
4322static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4323{
Yi Zou0331a832009-05-17 12:33:52 +00004324 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4325
John Fastabende5b64632011-03-08 03:44:52 +00004326 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4327 return false;
4328
John Fastabende901acd2011-04-26 07:26:08 +00004329 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004330
John Fastabende901acd2011-04-26 07:26:08 +00004331 adapter->num_rx_queues = 1;
4332 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004333
John Fastabende901acd2011-04-26 07:26:08 +00004334 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4335 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004336 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004337 ixgbe_set_fdir_queues(adapter);
4338 else
4339 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004340 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004341
John Fastabende901acd2011-04-26 07:26:08 +00004342 /* adding FCoE rx rings to the end */
4343 f->mask = adapter->num_rx_queues;
4344 adapter->num_rx_queues += f->indices;
4345 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004346
John Fastabende5b64632011-03-08 03:44:52 +00004347 return true;
4348}
4349#endif /* IXGBE_FCOE */
4350
John Fastabende901acd2011-04-26 07:26:08 +00004351/* Artificial max queue cap per traffic class in DCB mode */
4352#define DCB_QUEUE_CAP 8
4353
John Fastabende5b64632011-03-08 03:44:52 +00004354#ifdef CONFIG_IXGBE_DCB
4355static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4356{
John Fastabende901acd2011-04-26 07:26:08 +00004357 int per_tc_q, q, i, offset = 0;
4358 struct net_device *dev = adapter->netdev;
4359 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004360
John Fastabende901acd2011-04-26 07:26:08 +00004361 if (!tcs)
4362 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004363
John Fastabende901acd2011-04-26 07:26:08 +00004364 /* Map queue offset and counts onto allocated tx queues */
4365 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4366 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004367
John Fastabend8b1c0b22011-05-03 02:26:48 +00004368 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004369 netdev_set_prio_tc_map(dev, i, i);
4370 netdev_set_tc_queue(dev, i, q, offset);
4371 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004372 }
4373
John Fastabende901acd2011-04-26 07:26:08 +00004374 adapter->num_tx_queues = q * tcs;
4375 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004376
4377#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004378 /* FCoE enabled queues require special configuration indexed
4379 * by feature specific indices and mask. Here we map FCoE
4380 * indices onto the DCB queue pairs allowing FCoE to own
4381 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004382 */
John Fastabende901acd2011-04-26 07:26:08 +00004383 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4384 int tc;
4385 struct ixgbe_ring_feature *f =
4386 &adapter->ring_feature[RING_F_FCOE];
4387
4388 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4389 f->indices = dev->tc_to_txq[tc].count;
4390 f->mask = dev->tc_to_txq[tc].offset;
4391 }
John Fastabende5b64632011-03-08 03:44:52 +00004392#endif
4393
John Fastabende901acd2011-04-26 07:26:08 +00004394 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004395}
John Fastabende5b64632011-03-08 03:44:52 +00004396#endif
Yi Zou0331a832009-05-17 12:33:52 +00004397
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004398/**
4399 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4400 * @adapter: board private structure to initialize
4401 *
4402 * IOV doesn't actually use anything, so just NAK the
4403 * request for now and let the other queue routines
4404 * figure out what to do.
4405 */
4406static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4407{
4408 return false;
4409}
4410
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004411/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004412 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004413 * @adapter: board private structure to initialize
4414 *
4415 * This is the top level queue allocation routine. The order here is very
4416 * important, starting with the "most" number of features turned on at once,
4417 * and ending with the smallest set of features. This way large combinations
4418 * can be allocated if they're turned on, and smaller combinations are the
4419 * fallthrough conditions.
4420 *
4421 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004422static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004423{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004424 /* Start with base case */
4425 adapter->num_rx_queues = 1;
4426 adapter->num_tx_queues = 1;
4427 adapter->num_rx_pools = adapter->num_rx_queues;
4428 adapter->num_rx_queues_per_pool = 1;
4429
4430 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004431 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004432
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004433#ifdef CONFIG_IXGBE_DCB
4434 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004435 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004436
4437#endif
John Fastabende5b64632011-03-08 03:44:52 +00004438#ifdef IXGBE_FCOE
4439 if (ixgbe_set_fcoe_queues(adapter))
4440 goto done;
4441
4442#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004443 if (ixgbe_set_fdir_queues(adapter))
4444 goto done;
4445
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004446 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004447 goto done;
4448
4449 /* fallback to base case */
4450 adapter->num_rx_queues = 1;
4451 adapter->num_tx_queues = 1;
4452
4453done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004454 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004455 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004456 return netif_set_real_num_rx_queues(adapter->netdev,
4457 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004458}
4459
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004460static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004461 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004462{
4463 int err, vector_threshold;
4464
4465 /* We'll want at least 3 (vector_threshold):
4466 * 1) TxQ[0] Cleanup
4467 * 2) RxQ[0] Cleanup
4468 * 3) Other (Link Status Change, etc.)
4469 * 4) TCP Timer (optional)
4470 */
4471 vector_threshold = MIN_MSIX_COUNT;
4472
4473 /* The more we get, the more we will assign to Tx/Rx Cleanup
4474 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4475 * Right now, we simply care about how many we'll get; we'll
4476 * set them up later while requesting irq's.
4477 */
4478 while (vectors >= vector_threshold) {
4479 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004480 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004481 if (!err) /* Success in acquiring all requested vectors. */
4482 break;
4483 else if (err < 0)
4484 vectors = 0; /* Nasty failure, quit now */
4485 else /* err == number of vectors we should try again with */
4486 vectors = err;
4487 }
4488
4489 if (vectors < vector_threshold) {
4490 /* Can't allocate enough MSI-X interrupts? Oh well.
4491 * This just means we'll go with either a single MSI
4492 * vector or fall back to legacy interrupts.
4493 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004494 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4495 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004496 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4497 kfree(adapter->msix_entries);
4498 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004499 } else {
4500 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004501 /*
4502 * Adjust for only the vectors we'll use, which is minimum
4503 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4504 * vectors we were allocated.
4505 */
4506 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004507 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004508 }
4509}
4510
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004511/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004512 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004513 * @adapter: board private structure to initialize
4514 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004515 * Cache the descriptor ring offsets for RSS to the assigned rings.
4516 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004517 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004518static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004519{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004520 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004521
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004522 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4523 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004524
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004525 for (i = 0; i < adapter->num_rx_queues; i++)
4526 adapter->rx_ring[i]->reg_idx = i;
4527 for (i = 0; i < adapter->num_tx_queues; i++)
4528 adapter->tx_ring[i]->reg_idx = i;
4529
4530 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004531}
4532
4533#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004534
4535/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004536static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4537 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004538{
4539 struct net_device *dev = adapter->netdev;
4540 struct ixgbe_hw *hw = &adapter->hw;
4541 u8 num_tcs = netdev_get_num_tc(dev);
4542
4543 *tx = 0;
4544 *rx = 0;
4545
4546 switch (hw->mac.type) {
4547 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004548 *tx = tc << 2;
4549 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004550 break;
4551 case ixgbe_mac_82599EB:
4552 case ixgbe_mac_X540:
4553 if (num_tcs == 8) {
4554 if (tc < 3) {
4555 *tx = tc << 5;
4556 *rx = tc << 4;
4557 } else if (tc < 5) {
4558 *tx = ((tc + 2) << 4);
4559 *rx = tc << 4;
4560 } else if (tc < num_tcs) {
4561 *tx = ((tc + 8) << 3);
4562 *rx = tc << 4;
4563 }
4564 } else if (num_tcs == 4) {
4565 *rx = tc << 5;
4566 switch (tc) {
4567 case 0:
4568 *tx = 0;
4569 break;
4570 case 1:
4571 *tx = 64;
4572 break;
4573 case 2:
4574 *tx = 96;
4575 break;
4576 case 3:
4577 *tx = 112;
4578 break;
4579 default:
4580 break;
4581 }
4582 }
4583 break;
4584 default:
4585 break;
4586 }
4587}
4588
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004589/**
4590 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4591 * @adapter: board private structure to initialize
4592 *
4593 * Cache the descriptor ring offsets for DCB to the assigned rings.
4594 *
4595 **/
4596static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4597{
John Fastabende5b64632011-03-08 03:44:52 +00004598 struct net_device *dev = adapter->netdev;
4599 int i, j, k;
4600 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004601
John Fastabend8b1c0b22011-05-03 02:26:48 +00004602 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004603 return false;
4604
John Fastabende5b64632011-03-08 03:44:52 +00004605 for (i = 0, k = 0; i < num_tcs; i++) {
4606 unsigned int tx_s, rx_s;
4607 u16 count = dev->tc_to_txq[i].count;
4608
4609 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4610 for (j = 0; j < count; j++, k++) {
4611 adapter->tx_ring[k]->reg_idx = tx_s + j;
4612 adapter->rx_ring[k]->reg_idx = rx_s + j;
4613 adapter->tx_ring[k]->dcb_tc = i;
4614 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004615 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004616 }
John Fastabende5b64632011-03-08 03:44:52 +00004617
4618 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004619}
4620#endif
4621
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004622/**
4623 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4624 * @adapter: board private structure to initialize
4625 *
4626 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4627 *
4628 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004629static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004630{
4631 int i;
4632 bool ret = false;
4633
Alexander Duyck03ecf912011-05-20 07:36:17 +00004634 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4635 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004636 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004637 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004638 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004639 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004640 ret = true;
4641 }
4642
4643 return ret;
4644}
4645
Yi Zou0331a832009-05-17 12:33:52 +00004646#ifdef IXGBE_FCOE
4647/**
4648 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4649 * @adapter: board private structure to initialize
4650 *
4651 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4652 *
4653 */
4654static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4655{
Yi Zou0331a832009-05-17 12:33:52 +00004656 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004657 int i;
4658 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004659
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004660 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4661 return false;
4662
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004663 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004664 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004665 ixgbe_cache_ring_fdir(adapter);
4666 else
4667 ixgbe_cache_ring_rss(adapter);
4668
4669 fcoe_rx_i = f->mask;
4670 fcoe_tx_i = f->mask;
4671 }
4672 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4673 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4674 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4675 }
4676 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004677}
4678
4679#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004680/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004681 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4682 * @adapter: board private structure to initialize
4683 *
4684 * SR-IOV doesn't use any descriptor rings but changes the default if
4685 * no other mapping is used.
4686 *
4687 */
4688static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4689{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004690 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4691 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004692 if (adapter->num_vfs)
4693 return true;
4694 else
4695 return false;
4696}
4697
4698/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004699 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4700 * @adapter: board private structure to initialize
4701 *
4702 * Once we know the feature-set enabled for the device, we'll cache
4703 * the register offset the descriptor ring is assigned to.
4704 *
4705 * Note, the order the various feature calls is important. It must start with
4706 * the "most" features enabled at the same time, then trickle down to the
4707 * least amount of features turned on at once.
4708 **/
4709static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4710{
4711 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004712 adapter->rx_ring[0]->reg_idx = 0;
4713 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004714
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004715 if (ixgbe_cache_ring_sriov(adapter))
4716 return;
4717
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004718#ifdef CONFIG_IXGBE_DCB
4719 if (ixgbe_cache_ring_dcb(adapter))
4720 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004721#endif
John Fastabende5b64632011-03-08 03:44:52 +00004722
4723#ifdef IXGBE_FCOE
4724 if (ixgbe_cache_ring_fcoe(adapter))
4725 return;
4726#endif /* IXGBE_FCOE */
4727
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004728 if (ixgbe_cache_ring_fdir(adapter))
4729 return;
4730
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004731 if (ixgbe_cache_ring_rss(adapter))
4732 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004733}
4734
Auke Kok9a799d72007-09-15 14:07:45 -07004735/**
4736 * ixgbe_alloc_queues - Allocate memory for all rings
4737 * @adapter: board private structure to initialize
4738 *
4739 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004740 * number of queues at compile-time. The polling_netdev array is
4741 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004742 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004743static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004744{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004745 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004746
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004747 if (nid < 0 || !node_online(nid))
4748 nid = first_online_node;
4749
4750 for (; tx < adapter->num_tx_queues; tx++) {
4751 struct ixgbe_ring *ring;
4752
4753 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004754 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004755 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004756 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004757 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004758 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004759 ring->queue_index = tx;
4760 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004761 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004762 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004763
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004764 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004765 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004766
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004767 for (; rx < adapter->num_rx_queues; rx++) {
4768 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004769
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004770 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004771 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004772 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004773 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004774 goto err_allocation;
4775 ring->count = adapter->rx_ring_count;
4776 ring->queue_index = rx;
4777 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004778 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004779 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004780
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004781 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004782 }
4783
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004784 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004785
4786 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004787
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004788err_allocation:
4789 while (tx)
4790 kfree(adapter->tx_ring[--tx]);
4791
4792 while (rx)
4793 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004794 return -ENOMEM;
4795}
4796
4797/**
4798 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4799 * @adapter: board private structure to initialize
4800 *
4801 * Attempt to configure the interrupts using the best available
4802 * capabilities of the hardware and the kernel.
4803 **/
Al Virofeea6a52008-11-27 15:34:07 -08004804static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004805{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004806 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004807 int err = 0;
4808 int vector, v_budget;
4809
4810 /*
4811 * It's easy to be greedy for MSI-X vectors, but it really
4812 * doesn't do us much good if we have a lot more vectors
4813 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004814 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004815 */
4816 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004817 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004818
4819 /*
4820 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004821 * hw.mac->max_msix_vectors vectors. With features
4822 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4823 * descriptor queues supported by our device. Thus, we cap it off in
4824 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004825 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004826 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004827
4828 /* A failure in MSI-X entry allocation isn't fatal, but it does
4829 * mean we disable MSI-X capabilities of the adapter. */
4830 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004831 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004832 if (adapter->msix_entries) {
4833 for (vector = 0; vector < v_budget; vector++)
4834 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004835
Alexander Duyck7a921c92009-05-06 10:43:28 +00004836 ixgbe_acquire_msix_vectors(adapter, v_budget);
4837
4838 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4839 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004840 }
David S. Miller26d27842010-05-03 15:18:22 -07004841
Alexander Duyck7a921c92009-05-06 10:43:28 +00004842 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4843 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004844 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004845 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004846 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004847 "queues are disabled. Disabling Flow Director\n");
4848 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004849 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004850 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004851 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4852 ixgbe_disable_sriov(adapter);
4853
Ben Hutchings847f53f2010-09-27 08:28:56 +00004854 err = ixgbe_set_num_queues(adapter);
4855 if (err)
4856 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004857
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004858 err = pci_enable_msi(adapter->pdev);
4859 if (!err) {
4860 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4861 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004862 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4863 "Unable to allocate MSI interrupt, "
4864 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004865 /* reset err */
4866 err = 0;
4867 }
4868
4869out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004870 return err;
4871}
4872
Alexander Duyck7a921c92009-05-06 10:43:28 +00004873/**
4874 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4875 * @adapter: board private structure to initialize
4876 *
4877 * We allocate one q_vector per queue interrupt. If allocation fails we
4878 * return -ENOMEM.
4879 **/
4880static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4881{
4882 int q_idx, num_q_vectors;
4883 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004884 int (*poll)(struct napi_struct *, int);
4885
4886 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4887 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004888 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004889 } else {
4890 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004891 poll = &ixgbe_poll;
4892 }
4893
4894 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004895 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004896 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004897 if (!q_vector)
4898 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004899 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004900 if (!q_vector)
4901 goto err_out;
4902 q_vector->adapter = adapter;
Alexander Duyck08c88332011-06-11 01:45:03 +00004903 if (q_vector->tx.count && !q_vector->rx.count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004904 q_vector->eitr = adapter->tx_eitr_param;
4905 else
4906 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004907 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004908 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004909 adapter->q_vector[q_idx] = q_vector;
4910 }
4911
4912 return 0;
4913
4914err_out:
4915 while (q_idx) {
4916 q_idx--;
4917 q_vector = adapter->q_vector[q_idx];
4918 netif_napi_del(&q_vector->napi);
4919 kfree(q_vector);
4920 adapter->q_vector[q_idx] = NULL;
4921 }
4922 return -ENOMEM;
4923}
4924
4925/**
4926 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
4927 * @adapter: board private structure to initialize
4928 *
4929 * This function frees the memory allocated to the q_vectors. In addition if
4930 * NAPI is enabled it will delete any references to the NAPI struct prior
4931 * to freeing the q_vector.
4932 **/
4933static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
4934{
4935 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004936
Alexander Duyck91281fd2009-06-04 16:00:27 +00004937 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00004938 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004939 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00004940 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004941
4942 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
4943 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00004944 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004945 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004946 kfree(q_vector);
4947 }
4948}
4949
Don Skidmore7b25cdb2009-08-25 04:47:32 +00004950static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004951{
4952 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4953 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4954 pci_disable_msix(adapter->pdev);
4955 kfree(adapter->msix_entries);
4956 adapter->msix_entries = NULL;
4957 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
4958 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
4959 pci_disable_msi(adapter->pdev);
4960 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004961}
4962
4963/**
4964 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
4965 * @adapter: board private structure to initialize
4966 *
4967 * We determine which interrupt scheme to use based on...
4968 * - Kernel support (MSI, MSI-X)
4969 * - which can be user-defined (via MODULE_PARAM)
4970 * - Hardware queue count (num_*_queues)
4971 * - defined by miscellaneous hardware support/features (RSS, etc.)
4972 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004973int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004974{
4975 int err;
4976
4977 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00004978 err = ixgbe_set_num_queues(adapter);
4979 if (err)
4980 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004981
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004982 err = ixgbe_set_interrupt_capability(adapter);
4983 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004984 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004985 goto err_set_interrupt;
4986 }
4987
Alexander Duyck7a921c92009-05-06 10:43:28 +00004988 err = ixgbe_alloc_q_vectors(adapter);
4989 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004990 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004991 goto err_alloc_q_vectors;
4992 }
4993
4994 err = ixgbe_alloc_queues(adapter);
4995 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00004996 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00004997 goto err_alloc_queues;
4998 }
4999
Emil Tantilov849c4542010-06-03 16:53:41 +00005000 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005001 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5002 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005003
5004 set_bit(__IXGBE_DOWN, &adapter->state);
5005
5006 return 0;
5007
Alexander Duyck7a921c92009-05-06 10:43:28 +00005008err_alloc_queues:
5009 ixgbe_free_q_vectors(adapter);
5010err_alloc_q_vectors:
5011 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005012err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005013 return err;
5014}
5015
5016/**
5017 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5018 * @adapter: board private structure to clear interrupt scheme on
5019 *
5020 * We go through and clear interrupt specific resources and reset the structure
5021 * to pre-load conditions
5022 **/
5023void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5024{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005025 int i;
5026
5027 for (i = 0; i < adapter->num_tx_queues; i++) {
5028 kfree(adapter->tx_ring[i]);
5029 adapter->tx_ring[i] = NULL;
5030 }
5031 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005032 struct ixgbe_ring *ring = adapter->rx_ring[i];
5033
5034 /* ixgbe_get_stats64() might access this ring, we must wait
5035 * a grace period before freeing it.
5036 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005037 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005038 adapter->rx_ring[i] = NULL;
5039 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005040
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005041 adapter->num_tx_queues = 0;
5042 adapter->num_rx_queues = 0;
5043
Alexander Duyck7a921c92009-05-06 10:43:28 +00005044 ixgbe_free_q_vectors(adapter);
5045 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005046}
5047
5048/**
5049 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5050 * @adapter: board private structure to initialize
5051 *
5052 * ixgbe_sw_init initializes the Adapter private data structure.
5053 * Fields are initialized based on PCI device information and
5054 * OS network device settings (MTU size).
5055 **/
5056static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5057{
5058 struct ixgbe_hw *hw = &adapter->hw;
5059 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005060 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005061 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005062#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005063 int j;
5064 struct tc_configuration *tc;
5065#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005066 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005067
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005068 /* PCI config space info */
5069
5070 hw->vendor_id = pdev->vendor;
5071 hw->device_id = pdev->device;
5072 hw->revision_id = pdev->revision;
5073 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5074 hw->subsystem_device_id = pdev->subsystem_device;
5075
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005076 /* Set capability flags */
5077 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5078 adapter->ring_feature[RING_F_RSS].indices = rss;
5079 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005080 switch (hw->mac.type) {
5081 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005082 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5083 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005084 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005085 break;
5086 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005087 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005088 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005089 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5090 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005091 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5092 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005093 /* Flow Director hash filters enabled */
5094 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5095 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005096 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005097 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005098 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005099#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005100 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5101 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5102 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005103#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005104 /* Default traffic class to use for FCoE */
John Fastabend56075a92010-07-26 20:41:31 +00005105 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005106#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005107#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005108 break;
5109 default:
5110 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005111 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005112
Alexander Duyck1fc5f032011-06-02 04:28:39 +00005113 /* n-tuple support exists, always init our spinlock */
5114 spin_lock_init(&adapter->fdir_perfect_lock);
5115
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005116#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005117 /* Configure DCB traffic classes */
5118 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5119 tc = &adapter->dcb_cfg.tc_config[j];
5120 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5121 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5122 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5123 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5124 tc->dcb_pfc = pfc_disabled;
5125 }
5126 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5127 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005128 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005129 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005130 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005131 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005132 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005133
5134#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005135
5136 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005137 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005138 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005139#ifdef CONFIG_DCB
5140 adapter->last_lfc_mode = hw->fc.current_mode;
5141#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005142 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5143 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005144 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5145 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005146 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005147
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005148 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005149 adapter->rx_itr_setting = 1;
5150 adapter->rx_eitr_param = 20000;
5151 adapter->tx_itr_setting = 1;
5152 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005153
5154 /* set defaults for eitr in MegaBytes */
5155 adapter->eitr_low = 10;
5156 adapter->eitr_high = 20;
5157
5158 /* set default ring sizes */
5159 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5160 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5161
Alexander Duyckbd198052011-06-11 01:45:08 +00005162 /* set default work limits */
5163 adapter->tx_work_limit = adapter->tx_ring_count;
5164
Auke Kok9a799d72007-09-15 14:07:45 -07005165 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005166 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005167 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005168 return -EIO;
5169 }
5170
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005171 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005172 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5173
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005174 /* get assigned NUMA node */
5175 adapter->node = dev_to_node(&pdev->dev);
5176
Auke Kok9a799d72007-09-15 14:07:45 -07005177 set_bit(__IXGBE_DOWN, &adapter->state);
5178
5179 return 0;
5180}
5181
5182/**
5183 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005184 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005185 *
5186 * Return 0 on success, negative on failure
5187 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005188int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005189{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005190 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005191 int size;
5192
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005193 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005194 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005195 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005196 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005197 if (!tx_ring->tx_buffer_info)
5198 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005199
5200 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005201 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005202 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005203
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005204 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005205 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005206 if (!tx_ring->desc)
5207 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005208
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005209 tx_ring->next_to_use = 0;
5210 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005211 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005212
5213err:
5214 vfree(tx_ring->tx_buffer_info);
5215 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005216 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005217 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005218}
5219
5220/**
Alexander Duyck69888672008-09-11 20:05:39 -07005221 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5222 * @adapter: board private structure
5223 *
5224 * If this function returns with an error, then it's possible one or
5225 * more of the rings is populated (while the rest are not). It is the
5226 * callers duty to clean those orphaned rings.
5227 *
5228 * Return 0 on success, negative on failure
5229 **/
5230static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5231{
5232 int i, err = 0;
5233
5234 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005235 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005236 if (!err)
5237 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005238 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005239 break;
5240 }
5241
5242 return err;
5243}
5244
5245/**
Auke Kok9a799d72007-09-15 14:07:45 -07005246 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005247 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005248 *
5249 * Returns 0 on success, negative on failure
5250 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005251int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005252{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005253 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005254 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005255
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005256 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005257 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005258 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005259 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005260 if (!rx_ring->rx_buffer_info)
5261 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005262
Auke Kok9a799d72007-09-15 14:07:45 -07005263 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005264 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5265 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005266
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005267 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005268 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005269
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005270 if (!rx_ring->desc)
5271 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005272
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005273 rx_ring->next_to_clean = 0;
5274 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005275
5276 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005277err:
5278 vfree(rx_ring->rx_buffer_info);
5279 rx_ring->rx_buffer_info = NULL;
5280 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005281 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005282}
5283
5284/**
Alexander Duyck69888672008-09-11 20:05:39 -07005285 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5286 * @adapter: board private structure
5287 *
5288 * If this function returns with an error, then it's possible one or
5289 * more of the rings is populated (while the rest are not). It is the
5290 * callers duty to clean those orphaned rings.
5291 *
5292 * Return 0 on success, negative on failure
5293 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005294static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5295{
5296 int i, err = 0;
5297
5298 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005299 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005300 if (!err)
5301 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005302 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005303 break;
5304 }
5305
5306 return err;
5307}
5308
5309/**
Auke Kok9a799d72007-09-15 14:07:45 -07005310 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005311 * @tx_ring: Tx descriptor ring for a specific queue
5312 *
5313 * Free all transmit software resources
5314 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005315void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005316{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005317 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005318
5319 vfree(tx_ring->tx_buffer_info);
5320 tx_ring->tx_buffer_info = NULL;
5321
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005322 /* if not set, then don't free */
5323 if (!tx_ring->desc)
5324 return;
5325
5326 dma_free_coherent(tx_ring->dev, tx_ring->size,
5327 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005328
5329 tx_ring->desc = NULL;
5330}
5331
5332/**
5333 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5334 * @adapter: board private structure
5335 *
5336 * Free all transmit software resources
5337 **/
5338static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5339{
5340 int i;
5341
5342 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005343 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005344 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005345}
5346
5347/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005348 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005349 * @rx_ring: ring to clean the resources from
5350 *
5351 * Free all receive software resources
5352 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005353void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005354{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005355 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005356
5357 vfree(rx_ring->rx_buffer_info);
5358 rx_ring->rx_buffer_info = NULL;
5359
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005360 /* if not set, then don't free */
5361 if (!rx_ring->desc)
5362 return;
5363
5364 dma_free_coherent(rx_ring->dev, rx_ring->size,
5365 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005366
5367 rx_ring->desc = NULL;
5368}
5369
5370/**
5371 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5372 * @adapter: board private structure
5373 *
5374 * Free all receive software resources
5375 **/
5376static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5377{
5378 int i;
5379
5380 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005381 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005382 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005383}
5384
5385/**
Auke Kok9a799d72007-09-15 14:07:45 -07005386 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5387 * @netdev: network interface device structure
5388 * @new_mtu: new value for maximum frame size
5389 *
5390 * Returns 0 on success, negative on failure
5391 **/
5392static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5393{
5394 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005395 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005396 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5397
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005398 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005399 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5400 hw->mac.type != ixgbe_mac_X540) {
5401 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5402 return -EINVAL;
5403 } else {
5404 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5405 return -EINVAL;
5406 }
Auke Kok9a799d72007-09-15 14:07:45 -07005407
Emil Tantilov396e7992010-07-01 20:05:12 +00005408 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005409 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005410 netdev->mtu = new_mtu;
5411
John Fastabend16b61be2010-11-16 19:26:44 -08005412 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5413 hw->fc.low_water = FC_LOW_WATER(max_frame);
5414
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005415 if (netif_running(netdev))
5416 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005417
5418 return 0;
5419}
5420
5421/**
5422 * ixgbe_open - Called when a network interface is made active
5423 * @netdev: network interface device structure
5424 *
5425 * Returns 0 on success, negative value on failure
5426 *
5427 * The open entry point is called when a network interface is made
5428 * active by the system (IFF_UP). At this point all resources needed
5429 * for transmit and receive operations are allocated, the interrupt
5430 * handler is registered with the OS, the watchdog timer is started,
5431 * and the stack is notified that the interface is ready.
5432 **/
5433static int ixgbe_open(struct net_device *netdev)
5434{
5435 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5436 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005437
Auke Kok4bebfaa2008-02-11 09:26:01 -08005438 /* disallow open during test */
5439 if (test_bit(__IXGBE_TESTING, &adapter->state))
5440 return -EBUSY;
5441
Jesse Brandeburg54386462009-04-17 20:44:27 +00005442 netif_carrier_off(netdev);
5443
Auke Kok9a799d72007-09-15 14:07:45 -07005444 /* allocate transmit descriptors */
5445 err = ixgbe_setup_all_tx_resources(adapter);
5446 if (err)
5447 goto err_setup_tx;
5448
Auke Kok9a799d72007-09-15 14:07:45 -07005449 /* allocate receive descriptors */
5450 err = ixgbe_setup_all_rx_resources(adapter);
5451 if (err)
5452 goto err_setup_rx;
5453
5454 ixgbe_configure(adapter);
5455
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005456 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005457 if (err)
5458 goto err_req_irq;
5459
Auke Kok9a799d72007-09-15 14:07:45 -07005460 err = ixgbe_up_complete(adapter);
5461 if (err)
5462 goto err_up;
5463
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005464 netif_tx_start_all_queues(netdev);
5465
Auke Kok9a799d72007-09-15 14:07:45 -07005466 return 0;
5467
5468err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005469 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005470 ixgbe_free_irq(adapter);
5471err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005472err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005473 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005474err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005475 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005476 ixgbe_reset(adapter);
5477
5478 return err;
5479}
5480
5481/**
5482 * ixgbe_close - Disables a network interface
5483 * @netdev: network interface device structure
5484 *
5485 * Returns 0, this is not allowed to fail
5486 *
5487 * The close entry point is called when an interface is de-activated
5488 * by the OS. The hardware is still under the drivers control, but
5489 * needs to be disabled. A global MAC reset is issued to stop the
5490 * hardware, and all transmit and receive resources are freed.
5491 **/
5492static int ixgbe_close(struct net_device *netdev)
5493{
5494 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005495
5496 ixgbe_down(adapter);
5497 ixgbe_free_irq(adapter);
5498
Alexander Duycke4911d52011-05-11 07:18:52 +00005499 ixgbe_fdir_filter_exit(adapter);
5500
Auke Kok9a799d72007-09-15 14:07:45 -07005501 ixgbe_free_all_tx_resources(adapter);
5502 ixgbe_free_all_rx_resources(adapter);
5503
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005504 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005505
5506 return 0;
5507}
5508
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005509#ifdef CONFIG_PM
5510static int ixgbe_resume(struct pci_dev *pdev)
5511{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005512 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5513 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005514 u32 err;
5515
5516 pci_set_power_state(pdev, PCI_D0);
5517 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005518 /*
5519 * pci_restore_state clears dev->state_saved so call
5520 * pci_save_state to restore it.
5521 */
5522 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005523
5524 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005525 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005526 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005527 return err;
5528 }
5529 pci_set_master(pdev);
5530
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005531 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005532
5533 err = ixgbe_init_interrupt_scheme(adapter);
5534 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005535 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005536 return err;
5537 }
5538
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005539 ixgbe_reset(adapter);
5540
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005541 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5542
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005543 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005544 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005545 if (err)
5546 return err;
5547 }
5548
5549 netif_device_attach(netdev);
5550
5551 return 0;
5552}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005553#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005554
5555static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005556{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005557 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5558 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005559 struct ixgbe_hw *hw = &adapter->hw;
5560 u32 ctrl, fctrl;
5561 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005562#ifdef CONFIG_PM
5563 int retval = 0;
5564#endif
5565
5566 netif_device_detach(netdev);
5567
5568 if (netif_running(netdev)) {
5569 ixgbe_down(adapter);
5570 ixgbe_free_irq(adapter);
5571 ixgbe_free_all_tx_resources(adapter);
5572 ixgbe_free_all_rx_resources(adapter);
5573 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005574
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005575 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005576#ifdef CONFIG_DCB
5577 kfree(adapter->ixgbe_ieee_pfc);
5578 kfree(adapter->ixgbe_ieee_ets);
5579#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005580
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005581#ifdef CONFIG_PM
5582 retval = pci_save_state(pdev);
5583 if (retval)
5584 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005585
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005586#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005587 if (wufc) {
5588 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005589
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005590 /* turn on all-multi mode if wake on multicast is enabled */
5591 if (wufc & IXGBE_WUFC_MC) {
5592 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5593 fctrl |= IXGBE_FCTRL_MPE;
5594 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5595 }
5596
5597 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5598 ctrl |= IXGBE_CTRL_GIO_DIS;
5599 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5600
5601 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5602 } else {
5603 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5604 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5605 }
5606
Alexander Duyckbd508172010-11-16 19:27:03 -08005607 switch (hw->mac.type) {
5608 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005609 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005610 break;
5611 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005612 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005613 pci_wake_from_d3(pdev, !!wufc);
5614 break;
5615 default:
5616 break;
5617 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005618
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005619 *enable_wake = !!wufc;
5620
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005621 ixgbe_release_hw_control(adapter);
5622
5623 pci_disable_device(pdev);
5624
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005625 return 0;
5626}
5627
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005628#ifdef CONFIG_PM
5629static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5630{
5631 int retval;
5632 bool wake;
5633
5634 retval = __ixgbe_shutdown(pdev, &wake);
5635 if (retval)
5636 return retval;
5637
5638 if (wake) {
5639 pci_prepare_to_sleep(pdev);
5640 } else {
5641 pci_wake_from_d3(pdev, false);
5642 pci_set_power_state(pdev, PCI_D3hot);
5643 }
5644
5645 return 0;
5646}
5647#endif /* CONFIG_PM */
5648
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005649static void ixgbe_shutdown(struct pci_dev *pdev)
5650{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005651 bool wake;
5652
5653 __ixgbe_shutdown(pdev, &wake);
5654
5655 if (system_state == SYSTEM_POWER_OFF) {
5656 pci_wake_from_d3(pdev, wake);
5657 pci_set_power_state(pdev, PCI_D3hot);
5658 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005659}
5660
5661/**
Auke Kok9a799d72007-09-15 14:07:45 -07005662 * ixgbe_update_stats - Update the board statistics counters.
5663 * @adapter: board private structure
5664 **/
5665void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5666{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005667 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005668 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005669 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005670 u64 total_mpc = 0;
5671 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005672 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5673 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5674 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005675
Don Skidmored08935c2010-06-11 13:20:29 +00005676 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5677 test_bit(__IXGBE_RESETTING, &adapter->state))
5678 return;
5679
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005680 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005681 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005682 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005683 for (i = 0; i < 16; i++)
5684 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005685 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005686 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005687 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5688 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005689 }
5690 adapter->rsc_total_count = rsc_count;
5691 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005692 }
5693
Alexander Duyck5b7da512010-11-16 19:26:50 -08005694 for (i = 0; i < adapter->num_rx_queues; i++) {
5695 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5696 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5697 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5698 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5699 bytes += rx_ring->stats.bytes;
5700 packets += rx_ring->stats.packets;
5701 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005702 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005703 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5704 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5705 netdev->stats.rx_bytes = bytes;
5706 netdev->stats.rx_packets = packets;
5707
5708 bytes = 0;
5709 packets = 0;
5710 /* gather some stats to the adapter struct that are per queue */
5711 for (i = 0; i < adapter->num_tx_queues; i++) {
5712 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5713 restart_queue += tx_ring->tx_stats.restart_queue;
5714 tx_busy += tx_ring->tx_stats.tx_busy;
5715 bytes += tx_ring->stats.bytes;
5716 packets += tx_ring->stats.packets;
5717 }
5718 adapter->restart_queue = restart_queue;
5719 adapter->tx_busy = tx_busy;
5720 netdev->stats.tx_bytes = bytes;
5721 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005722
Joe Perches7ca647b2010-09-07 21:35:40 +00005723 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005724 for (i = 0; i < 8; i++) {
5725 /* for packet buffers not used, the register should read 0 */
5726 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5727 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005728 hwstats->mpc[i] += mpc;
5729 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005730 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005731 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5732 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5733 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5734 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5735 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005736 switch (hw->mac.type) {
5737 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005738 hwstats->pxonrxc[i] +=
5739 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005740 break;
5741 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005742 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005743 hwstats->pxonrxc[i] +=
5744 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005745 break;
5746 default:
5747 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005748 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005749 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5750 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005751 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005752 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005753 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005754 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005755
John Fastabendc84d3242010-11-16 19:27:12 -08005756 ixgbe_update_xoff_received(adapter);
5757
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005758 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005759 switch (hw->mac.type) {
5760 case ixgbe_mac_82598EB:
5761 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005762 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5763 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5764 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5765 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005766 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005767 /* OS2BMC stats are X540 only*/
5768 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5769 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5770 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5771 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5772 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005773 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005774 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005775 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005776 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005777 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005778 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005779 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005780 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5781 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005782#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005783 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5784 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5785 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5786 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5787 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5788 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005789#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005790 break;
5791 default:
5792 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005793 }
Auke Kok9a799d72007-09-15 14:07:45 -07005794 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005795 hwstats->bprc += bprc;
5796 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005797 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005798 hwstats->mprc -= bprc;
5799 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5800 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5801 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5802 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5803 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5804 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5805 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5806 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005807 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005808 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005809 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005810 hwstats->lxofftxc += lxoff;
5811 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5812 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5813 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005814 /*
5815 * 82598 errata - tx of flow control packets is included in tx counters
5816 */
5817 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005818 hwstats->gptc -= xon_off_tot;
5819 hwstats->mptc -= xon_off_tot;
5820 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5821 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5822 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5823 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5824 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5825 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5826 hwstats->ptc64 -= xon_off_tot;
5827 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5828 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5829 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5830 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5831 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5832 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005833
5834 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005835 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005836
5837 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005838 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005839 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005840 netdev->stats.rx_length_errors = hwstats->rlec;
5841 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005842 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005843}
5844
5845/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005846 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5847 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005848 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005849static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005850{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005851 struct ixgbe_hw *hw = &adapter->hw;
5852 int i;
5853
Alexander Duyckd034acf2011-04-27 09:25:34 +00005854 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5855 return;
5856
5857 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5858
5859 /* if interface is down do nothing */
5860 if (test_bit(__IXGBE_DOWN, &adapter->state))
5861 return;
5862
5863 /* do nothing if we are not using signature filters */
5864 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5865 return;
5866
5867 adapter->fdir_overflow++;
5868
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005869 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5870 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005871 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005872 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005873 /* re-enable flow director interrupts */
5874 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005875 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005876 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005877 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005878 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005879}
5880
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005881/**
5882 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5883 * @adapter - pointer to the device adapter structure
5884 *
5885 * This function serves two purposes. First it strobes the interrupt lines
5886 * in order to make certain interrupts are occuring. Secondly it sets the
5887 * bits needed to check for TX hangs. As a result we should immediately
5888 * determine if a hang has occured.
5889 */
5890static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5891{
Auke Kok9a799d72007-09-15 14:07:45 -07005892 struct ixgbe_hw *hw = &adapter->hw;
5893 u64 eics = 0;
5894 int i;
5895
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005896 /* If we're down or resetting, just bail */
5897 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5898 test_bit(__IXGBE_RESETTING, &adapter->state))
5899 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005900
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005901 /* Force detection of hung controller */
5902 if (netif_carrier_ok(adapter->netdev)) {
5903 for (i = 0; i < adapter->num_tx_queues; i++)
5904 set_check_for_tx_hang(adapter->tx_ring[i]);
5905 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005906
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005907 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005908 /*
5909 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005910 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005911 * would set *both* EIMS and EICS for any bit in EIAM
5912 */
5913 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5914 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005915 } else {
5916 /* get one bit for every active tx/rx interrupt vector */
5917 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5918 struct ixgbe_q_vector *qv = adapter->q_vector[i];
Alexander Duyck08c88332011-06-11 01:45:03 +00005919 if (qv->rx.count || qv->tx.count)
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005920 eics |= ((u64)1 << i);
5921 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005922 }
5923
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005924 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005925 ixgbe_irq_rearm_queues(adapter, eics);
5926
Alexander Duyckfe49f042009-06-04 16:00:09 +00005927}
5928
5929/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005930 * ixgbe_watchdog_update_link - update the link status
5931 * @adapter - pointer to the device adapter structure
5932 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005933 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005934static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005935{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005936 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005937 u32 link_speed = adapter->link_speed;
5938 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005939 int i;
5940
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005941 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
5942 return;
5943
5944 if (hw->mac.ops.check_link) {
5945 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005946 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005947 /* always assume link is up, if no check link function */
5948 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
5949 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005950 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005951 if (link_up) {
5952 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
5953 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
5954 hw->mac.ops.fc_enable(hw, i);
5955 } else {
5956 hw->mac.ops.fc_enable(hw, 0);
5957 }
5958 }
5959
5960 if (link_up ||
5961 time_after(jiffies, (adapter->link_check_timeout +
5962 IXGBE_TRY_LINK_TIMEOUT))) {
5963 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
5964 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
5965 IXGBE_WRITE_FLUSH(hw);
5966 }
5967
5968 adapter->link_up = link_up;
5969 adapter->link_speed = link_speed;
5970}
5971
5972/**
5973 * ixgbe_watchdog_link_is_up - update netif_carrier status and
5974 * print link up message
5975 * @adapter - pointer to the device adapter structure
5976 **/
5977static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
5978{
5979 struct net_device *netdev = adapter->netdev;
5980 struct ixgbe_hw *hw = &adapter->hw;
5981 u32 link_speed = adapter->link_speed;
5982 bool flow_rx, flow_tx;
5983
5984 /* only continue if link was previously down */
5985 if (netif_carrier_ok(netdev))
5986 return;
5987
5988 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
5989
5990 switch (hw->mac.type) {
5991 case ixgbe_mac_82598EB: {
5992 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5993 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
5994 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
5995 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
5996 }
5997 break;
5998 case ixgbe_mac_X540:
5999 case ixgbe_mac_82599EB: {
6000 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6001 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6002 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6003 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6004 }
6005 break;
6006 default:
6007 flow_tx = false;
6008 flow_rx = false;
6009 break;
6010 }
6011 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6012 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6013 "10 Gbps" :
6014 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6015 "1 Gbps" :
6016 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6017 "100 Mbps" :
6018 "unknown speed"))),
6019 ((flow_rx && flow_tx) ? "RX/TX" :
6020 (flow_rx ? "RX" :
6021 (flow_tx ? "TX" : "None"))));
6022
6023 netif_carrier_on(netdev);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006024 ixgbe_check_vf_rate_limit(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006025}
6026
6027/**
6028 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6029 * print link down message
6030 * @adapter - pointer to the adapter structure
6031 **/
6032static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6033{
6034 struct net_device *netdev = adapter->netdev;
6035 struct ixgbe_hw *hw = &adapter->hw;
6036
6037 adapter->link_up = false;
6038 adapter->link_speed = 0;
6039
6040 /* only continue if link was up previously */
6041 if (!netif_carrier_ok(netdev))
6042 return;
6043
6044 /* poll for SFP+ cable when link is down */
6045 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6046 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6047
6048 e_info(drv, "NIC Link is Down\n");
6049 netif_carrier_off(netdev);
6050}
6051
6052/**
6053 * ixgbe_watchdog_flush_tx - flush queues on link down
6054 * @adapter - pointer to the device adapter structure
6055 **/
6056static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6057{
6058 int i;
6059 int some_tx_pending = 0;
6060
6061 if (!netif_carrier_ok(adapter->netdev)) {
6062 for (i = 0; i < adapter->num_tx_queues; i++) {
6063 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6064 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6065 some_tx_pending = 1;
6066 break;
6067 }
6068 }
6069
6070 if (some_tx_pending) {
6071 /* We've lost link, so the controller stops DMA,
6072 * but we've got queued Tx work that's never going
6073 * to get done, so reset controller to flush Tx.
6074 * (Do the reset outside of interrupt context).
6075 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006076 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006077 }
6078 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006079}
6080
Greg Rosea985b6c32010-11-18 03:02:52 +00006081static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6082{
6083 u32 ssvpc;
6084
6085 /* Do not perform spoof check for 82598 */
6086 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6087 return;
6088
6089 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6090
6091 /*
6092 * ssvpc register is cleared on read, if zero then no
6093 * spoofed packets in the last interval.
6094 */
6095 if (!ssvpc)
6096 return;
6097
6098 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6099}
6100
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006101/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006102 * ixgbe_watchdog_subtask - check and bring link up
6103 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006104 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006105static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006106{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006107 /* if interface is down do nothing */
6108 if (test_bit(__IXGBE_DOWN, &adapter->state))
6109 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006110
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006111 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006112
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006113 if (adapter->link_up)
6114 ixgbe_watchdog_link_is_up(adapter);
6115 else
6116 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006117
Greg Rosea985b6c32010-11-18 03:02:52 +00006118 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006119 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006120
6121 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006122}
6123
Alexander Duyck70864002011-04-27 09:13:56 +00006124/**
6125 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6126 * @adapter - the ixgbe adapter structure
6127 **/
6128static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6129{
6130 struct ixgbe_hw *hw = &adapter->hw;
6131 s32 err;
6132
6133 /* not searching for SFP so there is nothing to do here */
6134 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6135 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6136 return;
6137
6138 /* someone else is in init, wait until next service event */
6139 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6140 return;
6141
6142 err = hw->phy.ops.identify_sfp(hw);
6143 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6144 goto sfp_out;
6145
6146 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6147 /* If no cable is present, then we need to reset
6148 * the next time we find a good cable. */
6149 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6150 }
6151
6152 /* exit on error */
6153 if (err)
6154 goto sfp_out;
6155
6156 /* exit if reset not needed */
6157 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6158 goto sfp_out;
6159
6160 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6161
6162 /*
6163 * A module may be identified correctly, but the EEPROM may not have
6164 * support for that module. setup_sfp() will fail in that case, so
6165 * we should not allow that module to load.
6166 */
6167 if (hw->mac.type == ixgbe_mac_82598EB)
6168 err = hw->phy.ops.reset(hw);
6169 else
6170 err = hw->mac.ops.setup_sfp(hw);
6171
6172 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6173 goto sfp_out;
6174
6175 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6176 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6177
6178sfp_out:
6179 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6180
6181 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6182 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6183 e_dev_err("failed to initialize because an unsupported "
6184 "SFP+ module type was detected.\n");
6185 e_dev_err("Reload the driver after installing a "
6186 "supported module.\n");
6187 unregister_netdev(adapter->netdev);
6188 }
6189}
6190
6191/**
6192 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6193 * @adapter - the ixgbe adapter structure
6194 **/
6195static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6196{
6197 struct ixgbe_hw *hw = &adapter->hw;
6198 u32 autoneg;
6199 bool negotiation;
6200
6201 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6202 return;
6203
6204 /* someone else is in init, wait until next service event */
6205 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6206 return;
6207
6208 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6209
6210 autoneg = hw->phy.autoneg_advertised;
6211 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6212 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6213 hw->mac.autotry_restart = false;
6214 if (hw->mac.ops.setup_link)
6215 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6216
6217 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6218 adapter->link_check_timeout = jiffies;
6219 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6220}
6221
6222/**
6223 * ixgbe_service_timer - Timer Call-back
6224 * @data: pointer to adapter cast into an unsigned long
6225 **/
6226static void ixgbe_service_timer(unsigned long data)
6227{
6228 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6229 unsigned long next_event_offset;
6230
6231 /* poll faster when waiting for link */
6232 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6233 next_event_offset = HZ / 10;
6234 else
6235 next_event_offset = HZ * 2;
6236
6237 /* Reset the timer */
6238 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6239
6240 ixgbe_service_event_schedule(adapter);
6241}
6242
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006243static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6244{
6245 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6246 return;
6247
6248 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6249
6250 /* If we're already down or resetting, just bail */
6251 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6252 test_bit(__IXGBE_RESETTING, &adapter->state))
6253 return;
6254
6255 ixgbe_dump(adapter);
6256 netdev_err(adapter->netdev, "Reset adapter\n");
6257 adapter->tx_timeout_count++;
6258
6259 ixgbe_reinit_locked(adapter);
6260}
6261
Alexander Duyck70864002011-04-27 09:13:56 +00006262/**
6263 * ixgbe_service_task - manages and runs subtasks
6264 * @work: pointer to work_struct containing our data
6265 **/
6266static void ixgbe_service_task(struct work_struct *work)
6267{
6268 struct ixgbe_adapter *adapter = container_of(work,
6269 struct ixgbe_adapter,
6270 service_task);
6271
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006272 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006273 ixgbe_sfp_detection_subtask(adapter);
6274 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006275 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006276 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006277 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006278 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006279
6280 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006281}
6282
Alexander Duyck897ab152011-05-27 05:31:47 +00006283void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6284 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006285{
6286 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006287 u16 i = tx_ring->next_to_use;
6288
6289 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6290
6291 i++;
6292 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6293
6294 /* set bits to identify this as an advanced context descriptor */
6295 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6296
6297 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6298 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6299 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6300 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6301}
6302
6303static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6304 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6305{
Auke Kok9a799d72007-09-15 14:07:45 -07006306 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006307 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006308 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006309
Alexander Duyck897ab152011-05-27 05:31:47 +00006310 if (!skb_is_gso(skb))
6311 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006312
Alexander Duyck897ab152011-05-27 05:31:47 +00006313 if (skb_header_cloned(skb)) {
6314 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6315 if (err)
6316 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006317 }
6318
Alexander Duyck897ab152011-05-27 05:31:47 +00006319 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6320 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6321
6322 if (protocol == __constant_htons(ETH_P_IP)) {
6323 struct iphdr *iph = ip_hdr(skb);
6324 iph->tot_len = 0;
6325 iph->check = 0;
6326 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6327 iph->daddr, 0,
6328 IPPROTO_TCP,
6329 0);
6330 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6331 } else if (skb_is_gso_v6(skb)) {
6332 ipv6_hdr(skb)->payload_len = 0;
6333 tcp_hdr(skb)->check =
6334 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6335 &ipv6_hdr(skb)->daddr,
6336 0, IPPROTO_TCP, 0);
6337 }
6338
6339 l4len = tcp_hdrlen(skb);
6340 *hdr_len = skb_transport_offset(skb) + l4len;
6341
6342 /* mss_l4len_id: use 1 as index for TSO */
6343 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6344 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6345 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6346
6347 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6348 vlan_macip_lens = skb_network_header_len(skb);
6349 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6350 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6351
6352 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6353 mss_l4len_idx);
6354
6355 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006356}
6357
Alexander Duyck897ab152011-05-27 05:31:47 +00006358static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006359 struct sk_buff *skb, u32 tx_flags,
6360 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006361{
Alexander Duyck897ab152011-05-27 05:31:47 +00006362 u32 vlan_macip_lens = 0;
6363 u32 mss_l4len_idx = 0;
6364 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006365
Alexander Duyck897ab152011-05-27 05:31:47 +00006366 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6367 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6368 return false;
6369 } else {
6370 u8 l4_hdr = 0;
6371 switch (protocol) {
6372 case __constant_htons(ETH_P_IP):
6373 vlan_macip_lens |= skb_network_header_len(skb);
6374 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6375 l4_hdr = ip_hdr(skb)->protocol;
6376 break;
6377 case __constant_htons(ETH_P_IPV6):
6378 vlan_macip_lens |= skb_network_header_len(skb);
6379 l4_hdr = ipv6_hdr(skb)->nexthdr;
6380 break;
6381 default:
6382 if (unlikely(net_ratelimit())) {
6383 dev_warn(tx_ring->dev,
6384 "partial checksum but proto=%x!\n",
6385 skb->protocol);
6386 }
6387 break;
6388 }
Auke Kok9a799d72007-09-15 14:07:45 -07006389
Alexander Duyck897ab152011-05-27 05:31:47 +00006390 switch (l4_hdr) {
6391 case IPPROTO_TCP:
6392 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6393 mss_l4len_idx = tcp_hdrlen(skb) <<
6394 IXGBE_ADVTXD_L4LEN_SHIFT;
6395 break;
6396 case IPPROTO_SCTP:
6397 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6398 mss_l4len_idx = sizeof(struct sctphdr) <<
6399 IXGBE_ADVTXD_L4LEN_SHIFT;
6400 break;
6401 case IPPROTO_UDP:
6402 mss_l4len_idx = sizeof(struct udphdr) <<
6403 IXGBE_ADVTXD_L4LEN_SHIFT;
6404 break;
6405 default:
6406 if (unlikely(net_ratelimit())) {
6407 dev_warn(tx_ring->dev,
6408 "partial checksum but l4 proto=%x!\n",
6409 skb->protocol);
6410 }
6411 break;
6412 }
Auke Kok9a799d72007-09-15 14:07:45 -07006413 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006414
Alexander Duyck897ab152011-05-27 05:31:47 +00006415 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6416 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6417
6418 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6419 type_tucmd, mss_l4len_idx);
6420
6421 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006422}
6423
6424static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006425 struct ixgbe_ring *tx_ring,
6426 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006427 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006428{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006429 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006430 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006431 unsigned int len;
6432 unsigned int total = skb->len;
Alexander Duyck63544e92011-05-27 05:31:42 +00006433 unsigned int offset = 0, size, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006434 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6435 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006436 unsigned int bytecount = skb->len;
6437 u16 gso_segs = 1;
Alexander Duyck63544e92011-05-27 05:31:42 +00006438 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07006439
6440 i = tx_ring->next_to_use;
6441
Yi Zoueacd73f2009-05-13 13:11:06 +00006442 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6443 /* excluding fcoe_crc_eof for FCoE */
6444 total -= sizeof(struct fcoe_crc_eof);
6445
6446 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006447 while (len) {
6448 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6449 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6450
6451 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006452 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006453 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006454 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006455 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006456 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006457 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006458 tx_buffer_info->time_stamp = jiffies;
6459 tx_buffer_info->next_to_watch = i;
6460
6461 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006462 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006463 offset += size;
6464 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006465
6466 if (len) {
6467 i++;
6468 if (i == tx_ring->count)
6469 i = 0;
6470 }
Auke Kok9a799d72007-09-15 14:07:45 -07006471 }
6472
6473 for (f = 0; f < nr_frags; f++) {
6474 struct skb_frag_struct *frag;
6475
6476 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006477 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006478 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006479
6480 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006481 i++;
6482 if (i == tx_ring->count)
6483 i = 0;
6484
Auke Kok9a799d72007-09-15 14:07:45 -07006485 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6486 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6487
6488 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006489 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006490 frag->page,
6491 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006492 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006493 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006494 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006495 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006496 tx_buffer_info->time_stamp = jiffies;
6497 tx_buffer_info->next_to_watch = i;
6498
6499 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006500 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006501 offset += size;
6502 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006503 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006504 if (total == 0)
6505 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006506 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006507
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006508 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6509 gso_segs = skb_shinfo(skb)->gso_segs;
6510#ifdef IXGBE_FCOE
6511 /* adjust for FCoE Sequence Offload */
6512 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6513 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6514 skb_shinfo(skb)->gso_size);
6515#endif /* IXGBE_FCOE */
6516 bytecount += (gso_segs - 1) * hdr_len;
6517
6518 /* multiply data chunks by size of headers */
6519 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6520 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006521 tx_ring->tx_buffer_info[i].skb = skb;
6522 tx_ring->tx_buffer_info[first].next_to_watch = i;
6523
6524 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006525
6526dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006527 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006528
6529 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6530 tx_buffer_info->dma = 0;
6531 tx_buffer_info->time_stamp = 0;
6532 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006533 if (count)
6534 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006535
6536 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006537 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006538 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006539 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006540 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006541 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006542 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006543 }
6544
Anton Blancharde44d38e2010-02-03 13:12:51 +00006545 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006546}
6547
Alexander Duyck84ea2592010-11-16 19:26:49 -08006548static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006549 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006550{
6551 union ixgbe_adv_tx_desc *tx_desc = NULL;
6552 struct ixgbe_tx_buffer *tx_buffer_info;
6553 u32 olinfo_status = 0, cmd_type_len = 0;
6554 unsigned int i;
6555 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6556
6557 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6558
6559 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6560
6561 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6562 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6563
6564 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6565 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6566
6567 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006568 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006569
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006570 /* use index 1 context for tso */
6571 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006572 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6573 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006574 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006575
6576 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6577 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006578 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006579
Yi Zoueacd73f2009-05-13 13:11:06 +00006580 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6581 olinfo_status |= IXGBE_ADVTXD_CC;
6582 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6583 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6584 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6585 }
6586
Auke Kok9a799d72007-09-15 14:07:45 -07006587 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6588
6589 i = tx_ring->next_to_use;
6590 while (count--) {
6591 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006592 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006593 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6594 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006595 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006596 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006597 i++;
6598 if (i == tx_ring->count)
6599 i = 0;
6600 }
6601
6602 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6603
6604 /*
6605 * Force memory writes to complete before letting h/w
6606 * know there are new descriptors to fetch. (Only
6607 * applicable for weak-ordered memory model archs,
6608 * such as IA-64).
6609 */
6610 wmb();
6611
6612 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006613 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006614}
6615
Alexander Duyck69830522011-01-06 14:29:58 +00006616static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6617 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006618{
Alexander Duyck69830522011-01-06 14:29:58 +00006619 struct ixgbe_q_vector *q_vector = ring->q_vector;
6620 union ixgbe_atr_hash_dword input = { .dword = 0 };
6621 union ixgbe_atr_hash_dword common = { .dword = 0 };
6622 union {
6623 unsigned char *network;
6624 struct iphdr *ipv4;
6625 struct ipv6hdr *ipv6;
6626 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006627 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006628 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006629
Alexander Duyck69830522011-01-06 14:29:58 +00006630 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6631 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006632 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006633
Alexander Duyck69830522011-01-06 14:29:58 +00006634 /* do nothing if sampling is disabled */
6635 if (!ring->atr_sample_rate)
6636 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006637
Alexander Duyck69830522011-01-06 14:29:58 +00006638 ring->atr_count++;
6639
6640 /* snag network header to get L4 type and address */
6641 hdr.network = skb_network_header(skb);
6642
6643 /* Currently only IPv4/IPv6 with TCP is supported */
6644 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6645 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6646 (protocol != __constant_htons(ETH_P_IP) ||
6647 hdr.ipv4->protocol != IPPROTO_TCP))
6648 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006649
6650 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006651
Alexander Duyck69830522011-01-06 14:29:58 +00006652 /* skip this packet since the socket is closing */
6653 if (th->fin)
6654 return;
6655
6656 /* sample on all syn packets or once every atr sample count */
6657 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6658 return;
6659
6660 /* reset sample count */
6661 ring->atr_count = 0;
6662
6663 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6664
6665 /*
6666 * src and dst are inverted, think how the receiver sees them
6667 *
6668 * The input is broken into two sections, a non-compressed section
6669 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6670 * is XORed together and stored in the compressed dword.
6671 */
6672 input.formatted.vlan_id = vlan_id;
6673
6674 /*
6675 * since src port and flex bytes occupy the same word XOR them together
6676 * and write the value to source port portion of compressed dword
6677 */
6678 if (vlan_id)
6679 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6680 else
6681 common.port.src ^= th->dest ^ protocol;
6682 common.port.dst ^= th->source;
6683
6684 if (protocol == __constant_htons(ETH_P_IP)) {
6685 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6686 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6687 } else {
6688 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6689 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6690 hdr.ipv6->saddr.s6_addr32[1] ^
6691 hdr.ipv6->saddr.s6_addr32[2] ^
6692 hdr.ipv6->saddr.s6_addr32[3] ^
6693 hdr.ipv6->daddr.s6_addr32[0] ^
6694 hdr.ipv6->daddr.s6_addr32[1] ^
6695 hdr.ipv6->daddr.s6_addr32[2] ^
6696 hdr.ipv6->daddr.s6_addr32[3];
6697 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006698
6699 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006700 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6701 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006702}
6703
Alexander Duyck63544e92011-05-27 05:31:42 +00006704static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006705{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006706 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006707 /* Herbert's original patch had:
6708 * smp_mb__after_netif_stop_queue();
6709 * but since that doesn't exist yet, just open code it. */
6710 smp_mb();
6711
6712 /* We need to check again in a case another CPU has just
6713 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006714 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006715 return -EBUSY;
6716
6717 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006718 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006719 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006720 return 0;
6721}
6722
Alexander Duyck82d4e462011-06-11 01:44:58 +00006723static inline int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006724{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006725 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006726 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006727 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006728}
6729
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006730static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6731{
6732 struct ixgbe_adapter *adapter = netdev_priv(dev);
Alexander Duyck64407522011-06-11 01:44:53 +00006733 int txq = skb_rx_queue_recorded(skb) ? skb_get_rx_queue(skb) :
6734 smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006735#ifdef IXGBE_FCOE
Alexander Duyck64407522011-06-11 01:44:53 +00006736 __be16 protocol = vlan_get_protocol(skb);
Hao Zheng5e09a102010-11-11 13:47:59 +00006737
John Fastabende5b64632011-03-08 03:44:52 +00006738 if (((protocol == htons(ETH_P_FCOE)) ||
6739 (protocol == htons(ETH_P_FIP))) &&
6740 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6741 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6742 txq += adapter->ring_feature[RING_F_FCOE].mask;
6743 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006744 }
6745#endif
6746
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006747 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6748 while (unlikely(txq >= dev->real_num_tx_queues))
6749 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006750 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006751 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006752
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006753 return skb_tx_hash(dev, skb);
6754}
6755
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006756netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006757 struct ixgbe_adapter *adapter,
6758 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006759{
Yi Zou5f715822009-12-03 11:32:44 +00006760 int tso;
Alexander Duycka535c302011-05-27 05:31:52 +00006761 u32 tx_flags = 0;
6762#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6763 unsigned short f;
6764#endif
Alexander Duyck63544e92011-05-27 05:31:42 +00006765 u16 first;
Alexander Duycka535c302011-05-27 05:31:52 +00006766 u16 count = TXD_USE_COUNT(skb_headlen(skb));
Hao Zheng5e09a102010-11-11 13:47:59 +00006767 __be16 protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006768 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006769
Alexander Duycka535c302011-05-27 05:31:52 +00006770 /*
6771 * need: 1 descriptor per page * PAGE_SIZE/IXGBE_MAX_DATA_PER_TXD,
6772 * + 1 desc for skb_head_len/IXGBE_MAX_DATA_PER_TXD,
6773 * + 2 desc gap to keep tail from touching head,
6774 * + 1 desc for context descriptor,
6775 * otherwise try next time
6776 */
6777#if PAGE_SIZE > IXGBE_MAX_DATA_PER_TXD
6778 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
6779 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6780#else
6781 count += skb_shinfo(skb)->nr_frags;
6782#endif
6783 if (ixgbe_maybe_stop_tx(tx_ring, count + 3)) {
6784 tx_ring->tx_stats.tx_busy++;
6785 return NETDEV_TX_BUSY;
6786 }
6787
Hao Zheng5e09a102010-11-11 13:47:59 +00006788 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006789
Jesse Grosseab6d182010-10-20 13:56:03 +00006790 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006791 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006792 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6793 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006794 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006795 }
6796 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6797 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006798 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6799 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006800 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006801 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6802 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006803 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006804
Yi Zou09ad1cc2009-09-03 14:56:10 +00006805#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006806 /* for FCoE with DCB, we force the priority to what
6807 * was specified by the switch */
6808 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006809 (protocol == htons(ETH_P_FCOE)))
6810 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Alexander Duycka535c302011-05-27 05:31:52 +00006811
Robert Loveca77cd52010-03-24 12:45:00 +00006812#endif
Alexander Duycka535c302011-05-27 05:31:52 +00006813 /* record the location of the first descriptor for this packet */
Auke Kok9a799d72007-09-15 14:07:45 -07006814 first = tx_ring->next_to_use;
Alexander Duycka535c302011-05-27 05:31:52 +00006815
Yi Zoueacd73f2009-05-13 13:11:06 +00006816 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6817#ifdef IXGBE_FCOE
6818 /* setup tx offload for FCoE */
Alexander Duyck897ab152011-05-27 05:31:47 +00006819 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6820 if (tso < 0)
6821 goto out_drop;
6822 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006823 tx_flags |= IXGBE_TX_FLAGS_FSO;
6824#endif /* IXGBE_FCOE */
6825 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006826 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006827 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006828 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6829 if (tso < 0)
6830 goto out_drop;
6831 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006832 tx_flags |= IXGBE_TX_FLAGS_TSO;
Alexander Duyck897ab152011-05-27 05:31:47 +00006833 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
Yi Zoueacd73f2009-05-13 13:11:06 +00006834 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006835 }
6836
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006837 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006838 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006839 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006840 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6841 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006842 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006843 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006844
Alexander Duyck44df32c2009-03-31 21:34:23 +00006845 } else {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006846 tx_ring->tx_buffer_info[first].time_stamp = 0;
6847 tx_ring->next_to_use = first;
Alexander Duyck897ab152011-05-27 05:31:47 +00006848 goto out_drop;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006849 }
Auke Kok9a799d72007-09-15 14:07:45 -07006850
6851 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006852
6853out_drop:
6854 dev_kfree_skb_any(skb);
6855 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006856}
6857
Alexander Duyck84418e32010-08-19 13:40:54 +00006858static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6859{
6860 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6861 struct ixgbe_ring *tx_ring;
6862
6863 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006864 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006865}
6866
Auke Kok9a799d72007-09-15 14:07:45 -07006867/**
Auke Kok9a799d72007-09-15 14:07:45 -07006868 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6869 * @netdev: network interface device structure
6870 * @p: pointer to an address structure
6871 *
6872 * Returns 0 on success, negative on failure
6873 **/
6874static int ixgbe_set_mac(struct net_device *netdev, void *p)
6875{
6876 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006877 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006878 struct sockaddr *addr = p;
6879
6880 if (!is_valid_ether_addr(addr->sa_data))
6881 return -EADDRNOTAVAIL;
6882
6883 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006884 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006885
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006886 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6887 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006888
6889 return 0;
6890}
6891
Ben Hutchings6b73e102009-04-29 08:08:58 +00006892static int
6893ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6894{
6895 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6896 struct ixgbe_hw *hw = &adapter->hw;
6897 u16 value;
6898 int rc;
6899
6900 if (prtad != hw->phy.mdio.prtad)
6901 return -EINVAL;
6902 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6903 if (!rc)
6904 rc = value;
6905 return rc;
6906}
6907
6908static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6909 u16 addr, u16 value)
6910{
6911 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6912 struct ixgbe_hw *hw = &adapter->hw;
6913
6914 if (prtad != hw->phy.mdio.prtad)
6915 return -EINVAL;
6916 return hw->phy.ops.write_reg(hw, addr, devad, value);
6917}
6918
6919static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6920{
6921 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6922
6923 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6924}
6925
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006926/**
6927 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006928 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006929 * @netdev: network interface device structure
6930 *
6931 * Returns non-zero on failure
6932 **/
6933static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6934{
6935 int err = 0;
6936 struct ixgbe_adapter *adapter = netdev_priv(dev);
6937 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6938
6939 if (is_valid_ether_addr(mac->san_addr)) {
6940 rtnl_lock();
6941 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6942 rtnl_unlock();
6943 }
6944 return err;
6945}
6946
6947/**
6948 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006949 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006950 * @netdev: network interface device structure
6951 *
6952 * Returns non-zero on failure
6953 **/
6954static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6955{
6956 int err = 0;
6957 struct ixgbe_adapter *adapter = netdev_priv(dev);
6958 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6959
6960 if (is_valid_ether_addr(mac->san_addr)) {
6961 rtnl_lock();
6962 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6963 rtnl_unlock();
6964 }
6965 return err;
6966}
6967
Auke Kok9a799d72007-09-15 14:07:45 -07006968#ifdef CONFIG_NET_POLL_CONTROLLER
6969/*
6970 * Polling 'interrupt' - used by things like netconsole to send skbs
6971 * without having to re-enable interrupts. It's not called while
6972 * the interrupt routine is executing.
6973 */
6974static void ixgbe_netpoll(struct net_device *netdev)
6975{
6976 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006977 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006978
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006979 /* if interface is down do nothing */
6980 if (test_bit(__IXGBE_DOWN, &adapter->state))
6981 return;
6982
Auke Kok9a799d72007-09-15 14:07:45 -07006983 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006984 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
6985 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
6986 for (i = 0; i < num_q_vectors; i++) {
6987 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
6988 ixgbe_msix_clean_many(0, q_vector);
6989 }
6990 } else {
6991 ixgbe_intr(adapter->pdev->irq, netdev);
6992 }
Auke Kok9a799d72007-09-15 14:07:45 -07006993 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07006994}
6995#endif
6996
Eric Dumazetde1036b2010-10-20 23:00:04 +00006997static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
6998 struct rtnl_link_stats64 *stats)
6999{
7000 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7001 int i;
7002
Eric Dumazet1a515022010-11-16 19:26:42 -08007003 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007004 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007005 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007006 u64 bytes, packets;
7007 unsigned int start;
7008
Eric Dumazet1a515022010-11-16 19:26:42 -08007009 if (ring) {
7010 do {
7011 start = u64_stats_fetch_begin_bh(&ring->syncp);
7012 packets = ring->stats.packets;
7013 bytes = ring->stats.bytes;
7014 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7015 stats->rx_packets += packets;
7016 stats->rx_bytes += bytes;
7017 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007018 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007019
7020 for (i = 0; i < adapter->num_tx_queues; i++) {
7021 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7022 u64 bytes, packets;
7023 unsigned int start;
7024
7025 if (ring) {
7026 do {
7027 start = u64_stats_fetch_begin_bh(&ring->syncp);
7028 packets = ring->stats.packets;
7029 bytes = ring->stats.bytes;
7030 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7031 stats->tx_packets += packets;
7032 stats->tx_bytes += bytes;
7033 }
7034 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007035 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007036 /* following stats updated by ixgbe_watchdog_task() */
7037 stats->multicast = netdev->stats.multicast;
7038 stats->rx_errors = netdev->stats.rx_errors;
7039 stats->rx_length_errors = netdev->stats.rx_length_errors;
7040 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7041 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7042 return stats;
7043}
7044
John Fastabend8b1c0b22011-05-03 02:26:48 +00007045/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7046 * #adapter: pointer to ixgbe_adapter
7047 * @tc: number of traffic classes currently enabled
7048 *
7049 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7050 * 802.1Q priority maps to a packet buffer that exists.
7051 */
7052static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7053{
7054 struct ixgbe_hw *hw = &adapter->hw;
7055 u32 reg, rsave;
7056 int i;
7057
7058 /* 82598 have a static priority to TC mapping that can not
7059 * be changed so no validation is needed.
7060 */
7061 if (hw->mac.type == ixgbe_mac_82598EB)
7062 return;
7063
7064 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7065 rsave = reg;
7066
7067 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7068 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7069
7070 /* If up2tc is out of bounds default to zero */
7071 if (up2tc > tc)
7072 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7073 }
7074
7075 if (reg != rsave)
7076 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7077
7078 return;
7079}
7080
7081
7082/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7083 * classes.
7084 *
7085 * @netdev: net device to configure
7086 * @tc: number of traffic classes to enable
7087 */
7088int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7089{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007090 struct ixgbe_adapter *adapter = netdev_priv(dev);
7091 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007092
7093 /* If DCB is anabled do not remove traffic classes, multiple
7094 * traffic classes are required to implement DCB
7095 */
7096 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7097 return 0;
7098
7099 /* Hardware supports up to 8 traffic classes */
7100 if (tc > MAX_TRAFFIC_CLASS ||
7101 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7102 return -EINVAL;
7103
7104 /* Hardware has to reinitialize queues and interrupts to
7105 * match packet buffer alignment. Unfortunantly, the
7106 * hardware is not flexible enough to do this dynamically.
7107 */
7108 if (netif_running(dev))
7109 ixgbe_close(dev);
7110 ixgbe_clear_interrupt_scheme(adapter);
7111
7112 if (tc)
7113 netdev_set_num_tc(dev, tc);
7114 else
7115 netdev_reset_tc(dev);
7116
John Fastabend8b1c0b22011-05-03 02:26:48 +00007117 ixgbe_init_interrupt_scheme(adapter);
7118 ixgbe_validate_rtr(adapter, tc);
7119 if (netif_running(dev))
7120 ixgbe_open(dev);
7121
7122 return 0;
7123}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007124
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007125static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007126 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007127 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007128 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007129 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007130 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007131 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7132 .ndo_validate_addr = eth_validate_addr,
7133 .ndo_set_mac_address = ixgbe_set_mac,
7134 .ndo_change_mtu = ixgbe_change_mtu,
7135 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007136 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7137 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007138 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007139 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7140 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7141 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7142 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007143 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007144 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007145#ifdef CONFIG_NET_POLL_CONTROLLER
7146 .ndo_poll_controller = ixgbe_netpoll,
7147#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007148#ifdef IXGBE_FCOE
7149 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007150 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007151 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007152 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7153 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007154 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007155#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007156};
7157
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007158static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7159 const struct ixgbe_info *ii)
7160{
7161#ifdef CONFIG_PCI_IOV
7162 struct ixgbe_hw *hw = &adapter->hw;
7163 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007164 int num_vf_macvlans, i;
7165 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007166
Greg Rose3377eba792010-12-07 08:16:45 +00007167 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007168 return;
7169
7170 /* The 82599 supports up to 64 VFs per physical function
7171 * but this implementation limits allocation to 63 so that
7172 * basic networking resources are still available to the
7173 * physical function
7174 */
7175 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7176 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7177 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7178 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007179 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007180 goto err_novfs;
7181 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007182
7183 num_vf_macvlans = hw->mac.num_rar_entries -
7184 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7185
7186 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7187 sizeof(struct vf_macvlans),
7188 GFP_KERNEL);
7189 if (mv_list) {
7190 /* Initialize list of VF macvlans */
7191 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7192 for (i = 0; i < num_vf_macvlans; i++) {
7193 mv_list->vf = -1;
7194 mv_list->free = true;
7195 mv_list->rar_entry = hw->mac.num_rar_entries -
7196 (i + adapter->num_vfs + 1);
7197 list_add(&mv_list->l, &adapter->vf_mvs.l);
7198 mv_list++;
7199 }
7200 }
7201
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007202 /* If call to enable VFs succeeded then allocate memory
7203 * for per VF control structures.
7204 */
7205 adapter->vfinfo =
7206 kcalloc(adapter->num_vfs,
7207 sizeof(struct vf_data_storage), GFP_KERNEL);
7208 if (adapter->vfinfo) {
7209 /* Now that we're sure SR-IOV is enabled
7210 * and memory allocated set up the mailbox parameters
7211 */
7212 ixgbe_init_mbx_params_pf(hw);
7213 memcpy(&hw->mbx.ops, ii->mbx_ops,
7214 sizeof(hw->mbx.ops));
7215
7216 /* Disable RSC when in SR-IOV mode */
7217 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7218 IXGBE_FLAG2_RSC_ENABLED);
7219 return;
7220 }
7221
7222 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007223 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7224 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007225 pci_disable_sriov(adapter->pdev);
7226
7227err_novfs:
7228 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7229 adapter->num_vfs = 0;
7230#endif /* CONFIG_PCI_IOV */
7231}
7232
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007233/**
Auke Kok9a799d72007-09-15 14:07:45 -07007234 * ixgbe_probe - Device Initialization Routine
7235 * @pdev: PCI device information struct
7236 * @ent: entry in ixgbe_pci_tbl
7237 *
7238 * Returns 0 on success, negative on failure
7239 *
7240 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7241 * The OS initialization, configuring of the adapter private structure,
7242 * and a hardware reset occur.
7243 **/
7244static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007245 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007246{
7247 struct net_device *netdev;
7248 struct ixgbe_adapter *adapter = NULL;
7249 struct ixgbe_hw *hw;
7250 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007251 static int cards_found;
7252 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007253 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007254 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007255#ifdef IXGBE_FCOE
7256 u16 device_caps;
7257#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007258 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007259
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007260 /* Catch broken hardware that put the wrong VF device ID in
7261 * the PCIe SR-IOV capability.
7262 */
7263 if (pdev->is_virtfn) {
7264 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7265 pci_name(pdev), pdev->vendor, pdev->device);
7266 return -EINVAL;
7267 }
7268
gouji-new9ce77662009-05-06 10:44:45 +00007269 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007270 if (err)
7271 return err;
7272
Nick Nunley1b507732010-04-27 13:10:27 +00007273 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7274 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007275 pci_using_dac = 1;
7276 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007277 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007278 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007279 err = dma_set_coherent_mask(&pdev->dev,
7280 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007281 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007282 dev_err(&pdev->dev,
7283 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007284 goto err_dma;
7285 }
7286 }
7287 pci_using_dac = 0;
7288 }
7289
gouji-new9ce77662009-05-06 10:44:45 +00007290 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007291 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007292 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007293 dev_err(&pdev->dev,
7294 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007295 goto err_pci_reg;
7296 }
7297
Frans Pop19d5afd2009-10-02 10:04:12 -07007298 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007299
Auke Kok9a799d72007-09-15 14:07:45 -07007300 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007301 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007302
John Fastabende901acd2011-04-26 07:26:08 +00007303#ifdef CONFIG_IXGBE_DCB
7304 indices *= MAX_TRAFFIC_CLASS;
7305#endif
7306
John Fastabendc85a2612010-02-25 23:15:21 +00007307 if (ii->mac == ixgbe_mac_82598EB)
7308 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7309 else
7310 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7311
John Fastabende901acd2011-04-26 07:26:08 +00007312#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007313 indices += min_t(unsigned int, num_possible_cpus(),
7314 IXGBE_MAX_FCOE_INDICES);
7315#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007316 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007317 if (!netdev) {
7318 err = -ENOMEM;
7319 goto err_alloc_etherdev;
7320 }
7321
Auke Kok9a799d72007-09-15 14:07:45 -07007322 SET_NETDEV_DEV(netdev, &pdev->dev);
7323
Auke Kok9a799d72007-09-15 14:07:45 -07007324 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007325 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007326
7327 adapter->netdev = netdev;
7328 adapter->pdev = pdev;
7329 hw = &adapter->hw;
7330 hw->back = adapter;
7331 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7332
Jeff Kirsher05857982008-09-11 19:57:00 -07007333 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007334 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007335 if (!hw->hw_addr) {
7336 err = -EIO;
7337 goto err_ioremap;
7338 }
7339
7340 for (i = 1; i <= 5; i++) {
7341 if (pci_resource_len(pdev, i) == 0)
7342 continue;
7343 }
7344
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007345 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007346 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007347 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007348 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007349
Auke Kok9a799d72007-09-15 14:07:45 -07007350 adapter->bd_number = cards_found;
7351
Auke Kok9a799d72007-09-15 14:07:45 -07007352 /* Setup hw api */
7353 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007354 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007355
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007356 /* EEPROM */
7357 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7358 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7359 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7360 if (!(eec & (1 << 8)))
7361 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7362
7363 /* PHY */
7364 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007365 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007366 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7367 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7368 hw->phy.mdio.mmds = 0;
7369 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7370 hw->phy.mdio.dev = netdev;
7371 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7372 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007373
Don Skidmore8ca783a2009-05-26 20:40:47 -07007374 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007375
7376 /* setup the private structure */
7377 err = ixgbe_sw_init(adapter);
7378 if (err)
7379 goto err_sw_init;
7380
Don Skidmoree86bff02010-02-11 04:14:08 +00007381 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007382 switch (adapter->hw.mac.type) {
7383 case ixgbe_mac_82599EB:
7384 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007385 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007386 break;
7387 default:
7388 break;
7389 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007390
Don Skidmorebf069c92009-05-07 10:39:54 +00007391 /*
7392 * If there is a fan on this device and it has failed log the
7393 * failure.
7394 */
7395 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7396 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7397 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007398 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007399 }
7400
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007401 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007402 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007403 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007404 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007405 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7406 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007407 err = 0;
7408 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007409 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007410 "module type was detected.\n");
7411 e_dev_err("Reload the driver after installing a supported "
7412 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007413 goto err_sw_init;
7414 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007415 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007416 goto err_sw_init;
7417 }
7418
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007419 ixgbe_probe_vf(adapter, ii);
7420
Emil Tantilov396e7992010-07-01 20:05:12 +00007421 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007422 NETIF_F_IP_CSUM |
7423 NETIF_F_HW_VLAN_TX |
7424 NETIF_F_HW_VLAN_RX |
7425 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007426
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007427 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007428 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007429 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007430 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007431 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007432
Don Skidmore58be7662011-04-12 09:42:11 +00007433 switch (adapter->hw.mac.type) {
7434 case ixgbe_mac_82599EB:
7435 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007436 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007437 break;
7438 default:
7439 break;
7440 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007441
Jeff Kirsherad31c402008-06-05 04:05:30 -07007442 netdev->vlan_features |= NETIF_F_TSO;
7443 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007444 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007445 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007446 netdev->vlan_features |= NETIF_F_SG;
7447
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007448 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7449 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7450 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007451
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007452#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007453 netdev->dcbnl_ops = &dcbnl_ops;
7454#endif
7455
Yi Zoueacd73f2009-05-13 13:11:06 +00007456#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007457 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007458 if (hw->mac.ops.get_device_caps) {
7459 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007460 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7461 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007462 }
7463 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007464 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7465 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7466 netdev->vlan_features |= NETIF_F_FSO;
7467 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7468 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007469#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007470 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007471 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007472 netdev->vlan_features |= NETIF_F_HIGHDMA;
7473 }
Auke Kok9a799d72007-09-15 14:07:45 -07007474
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007475 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007476 netdev->features |= NETIF_F_LRO;
7477
Auke Kok9a799d72007-09-15 14:07:45 -07007478 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007479 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007480 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007481 err = -EIO;
7482 goto err_eeprom;
7483 }
7484
7485 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7486 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7487
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007488 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007489 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007490 err = -EIO;
7491 goto err_eeprom;
7492 }
7493
Don Skidmorec6ecf392010-12-03 03:31:51 +00007494 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7495 if (hw->mac.ops.disable_tx_laser &&
7496 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007497 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007498 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007499 hw->mac.ops.disable_tx_laser(hw);
7500
Alexander Duyck70864002011-04-27 09:13:56 +00007501 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7502 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007503
Alexander Duyck70864002011-04-27 09:13:56 +00007504 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7505 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007506
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007507 err = ixgbe_init_interrupt_scheme(adapter);
7508 if (err)
7509 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007510
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007511 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7512 netdev->features &= ~NETIF_F_RXHASH;
7513
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007514 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007515 case IXGBE_DEV_ID_82599_SFP:
7516 /* Only this subdevice supports WOL */
7517 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007518 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007519 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007520 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7521 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007522 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
Andy Gospodarek9417c462011-07-16 07:31:33 +00007523 adapter->wol = IXGBE_WUFC_MAG;
Don Skidmore0b077fe2010-12-03 03:32:13 +00007524 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007525 case IXGBE_DEV_ID_82599_KX4:
Andy Gospodarek9417c462011-07-16 07:31:33 +00007526 adapter->wol = IXGBE_WUFC_MAG;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007527 break;
7528 default:
7529 adapter->wol = 0;
7530 break;
7531 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007532 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7533
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007534 /* pick up the PCI bus settings for reporting later */
7535 hw->mac.ops.get_bus_info(hw);
7536
Auke Kok9a799d72007-09-15 14:07:45 -07007537 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007538 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007539 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7540 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007541 "Unknown"),
7542 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7543 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7544 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7545 "Unknown"),
7546 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007547
7548 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7549 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007550 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007551 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007552 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007553 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007554 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007555 else
Don Skidmore289700db2010-12-03 03:32:58 +00007556 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7557 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007558
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007559 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007560 e_dev_warn("PCI-Express bandwidth available for this card is "
7561 "not sufficient for optimal performance.\n");
7562 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7563 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007564 }
7565
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007566 /* save off EEPROM version number */
7567 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7568
Auke Kok9a799d72007-09-15 14:07:45 -07007569 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007570 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007571
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007572 if (err == IXGBE_ERR_EEPROM_VERSION) {
7573 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007574 e_dev_warn("This device is a pre-production adapter/LOM. "
7575 "Please be aware there may be issues associated "
7576 "with your hardware. If you are experiencing "
7577 "problems please contact your Intel or hardware "
7578 "representative who provided you with this "
7579 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007580 }
Auke Kok9a799d72007-09-15 14:07:45 -07007581 strcpy(netdev->name, "eth%d");
7582 err = register_netdev(netdev);
7583 if (err)
7584 goto err_register;
7585
Jesse Brandeburg54386462009-04-17 20:44:27 +00007586 /* carrier off reporting is important to ethtool even BEFORE open */
7587 netif_carrier_off(netdev);
7588
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007589#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007590 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007591 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007592 ixgbe_setup_dca(adapter);
7593 }
7594#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007595 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007596 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007597 for (i = 0; i < adapter->num_vfs; i++)
7598 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7599 }
7600
Emil Tantilov9612de92011-05-07 07:40:20 +00007601 /* Inform firmware of driver version */
7602 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007603 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7604 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007605
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007606 /* add san mac addr to netdev */
7607 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007608
Emil Tantilov849c4542010-06-03 16:53:41 +00007609 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007610 cards_found++;
7611 return 0;
7612
7613err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007614 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007615 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007616err_sw_init:
7617err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007618 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7619 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007620 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007621 iounmap(hw->hw_addr);
7622err_ioremap:
7623 free_netdev(netdev);
7624err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007625 pci_release_selected_regions(pdev,
7626 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007627err_pci_reg:
7628err_dma:
7629 pci_disable_device(pdev);
7630 return err;
7631}
7632
7633/**
7634 * ixgbe_remove - Device Removal Routine
7635 * @pdev: PCI device information struct
7636 *
7637 * ixgbe_remove is called by the PCI subsystem to alert the driver
7638 * that it should release a PCI device. The could be caused by a
7639 * Hot-Plug event, or because the driver is going to be removed from
7640 * memory.
7641 **/
7642static void __devexit ixgbe_remove(struct pci_dev *pdev)
7643{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007644 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7645 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007646
7647 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007648 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007649
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007650#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007651 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7652 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7653 dca_remove_requester(&pdev->dev);
7654 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7655 }
7656
7657#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007658#ifdef IXGBE_FCOE
7659 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7660 ixgbe_cleanup_fcoe(adapter);
7661
7662#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007663
7664 /* remove the added san mac */
7665 ixgbe_del_sanmac_netdev(netdev);
7666
Donald Skidmorec4900be2008-11-20 21:11:42 -08007667 if (netdev->reg_state == NETREG_REGISTERED)
7668 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007669
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007670 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7671 ixgbe_disable_sriov(adapter);
7672
Alexander Duyck7a921c92009-05-06 10:43:28 +00007673 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007674
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007675 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007676
7677 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007678 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007679 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007680
Emil Tantilov849c4542010-06-03 16:53:41 +00007681 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007682
Auke Kok9a799d72007-09-15 14:07:45 -07007683 free_netdev(netdev);
7684
Frans Pop19d5afd2009-10-02 10:04:12 -07007685 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007686
Auke Kok9a799d72007-09-15 14:07:45 -07007687 pci_disable_device(pdev);
7688}
7689
7690/**
7691 * ixgbe_io_error_detected - called when PCI error is detected
7692 * @pdev: Pointer to PCI device
7693 * @state: The current pci connection state
7694 *
7695 * This function is called after a PCI bus error affecting
7696 * this device has been detected.
7697 */
7698static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007699 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007700{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007701 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7702 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007703
7704 netif_device_detach(netdev);
7705
Breno Leitao3044b8d2009-05-06 10:44:26 +00007706 if (state == pci_channel_io_perm_failure)
7707 return PCI_ERS_RESULT_DISCONNECT;
7708
Auke Kok9a799d72007-09-15 14:07:45 -07007709 if (netif_running(netdev))
7710 ixgbe_down(adapter);
7711 pci_disable_device(pdev);
7712
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007713 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007714 return PCI_ERS_RESULT_NEED_RESET;
7715}
7716
7717/**
7718 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7719 * @pdev: Pointer to PCI device
7720 *
7721 * Restart the card from scratch, as if from a cold-boot.
7722 */
7723static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7724{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007725 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007726 pci_ers_result_t result;
7727 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007728
gouji-new9ce77662009-05-06 10:44:45 +00007729 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007730 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007731 result = PCI_ERS_RESULT_DISCONNECT;
7732 } else {
7733 pci_set_master(pdev);
7734 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007735 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007736
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007737 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007738
7739 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007740 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007741 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007742 }
Auke Kok9a799d72007-09-15 14:07:45 -07007743
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007744 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7745 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007746 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7747 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007748 /* non-fatal, continue */
7749 }
Auke Kok9a799d72007-09-15 14:07:45 -07007750
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007751 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007752}
7753
7754/**
7755 * ixgbe_io_resume - called when traffic can start flowing again.
7756 * @pdev: Pointer to PCI device
7757 *
7758 * This callback is called when the error recovery driver tells us that
7759 * its OK to resume normal operation.
7760 */
7761static void ixgbe_io_resume(struct pci_dev *pdev)
7762{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007763 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7764 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007765
7766 if (netif_running(netdev)) {
7767 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007768 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007769 return;
7770 }
7771 }
7772
7773 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007774}
7775
7776static struct pci_error_handlers ixgbe_err_handler = {
7777 .error_detected = ixgbe_io_error_detected,
7778 .slot_reset = ixgbe_io_slot_reset,
7779 .resume = ixgbe_io_resume,
7780};
7781
7782static struct pci_driver ixgbe_driver = {
7783 .name = ixgbe_driver_name,
7784 .id_table = ixgbe_pci_tbl,
7785 .probe = ixgbe_probe,
7786 .remove = __devexit_p(ixgbe_remove),
7787#ifdef CONFIG_PM
7788 .suspend = ixgbe_suspend,
7789 .resume = ixgbe_resume,
7790#endif
7791 .shutdown = ixgbe_shutdown,
7792 .err_handler = &ixgbe_err_handler
7793};
7794
7795/**
7796 * ixgbe_init_module - Driver Registration Routine
7797 *
7798 * ixgbe_init_module is the first routine called when the driver is
7799 * loaded. All it does is register with the PCI subsystem.
7800 **/
7801static int __init ixgbe_init_module(void)
7802{
7803 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007804 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007805 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007806
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007807#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007808 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007809#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007810
Auke Kok9a799d72007-09-15 14:07:45 -07007811 ret = pci_register_driver(&ixgbe_driver);
7812 return ret;
7813}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007814
Auke Kok9a799d72007-09-15 14:07:45 -07007815module_init(ixgbe_init_module);
7816
7817/**
7818 * ixgbe_exit_module - Driver Exit Cleanup Routine
7819 *
7820 * ixgbe_exit_module is called just before the driver is removed
7821 * from memory.
7822 **/
7823static void __exit ixgbe_exit_module(void)
7824{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007825#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007826 dca_unregister_notify(&dca_notifier);
7827#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007828 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007829 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007830}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007831
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007832#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007833static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007834 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007835{
7836 int ret_val;
7837
7838 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007839 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007840
7841 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7842}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007843
Alexander Duyckb4533682009-03-31 21:32:42 +00007844#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007845
Auke Kok9a799d72007-09-15 14:07:45 -07007846module_exit(ixgbe_exit_module);
7847
7848/* ixgbe_main.c */