blob: 00e60c5ab27fcc31b73dad0be89d152eabd8cb60 [file] [log] [blame]
Auke Kok9a799d72007-09-15 14:07:45 -07001/*******************************************************************************
2
3 Intel 10 Gigabit PCI Express Linux driver
Don Skidmorea52055e2011-02-23 09:58:39 +00004 Copyright(c) 1999 - 2011 Intel Corporation.
Auke Kok9a799d72007-09-15 14:07:45 -07005
6 This program is free software; you can redistribute it and/or modify it
7 under the terms and conditions of the GNU General Public License,
8 version 2, as published by the Free Software Foundation.
9
10 This program is distributed in the hope it will be useful, but WITHOUT
11 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 more details.
14
15 You should have received a copy of the GNU General Public License along with
16 this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
18
19 The full GNU General Public License is included in this distribution in
20 the file called "COPYING".
21
22 Contact Information:
Auke Kok9a799d72007-09-15 14:07:45 -070023 e1000-devel Mailing List <e1000-devel@lists.sourceforge.net>
24 Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25
26*******************************************************************************/
27
28#include <linux/types.h>
29#include <linux/module.h>
30#include <linux/pci.h>
31#include <linux/netdevice.h>
32#include <linux/vmalloc.h>
33#include <linux/string.h>
34#include <linux/in.h>
Alexey Dobriyana6b7a402011-06-06 10:43:46 +000035#include <linux/interrupt.h>
Auke Kok9a799d72007-09-15 14:07:45 -070036#include <linux/ip.h>
37#include <linux/tcp.h>
Alexander Duyck897ab152011-05-27 05:31:47 +000038#include <linux/sctp.h>
Lucy Liu60127862009-07-22 14:07:33 +000039#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090041#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070042#include <net/checksum.h>
43#include <net/ip6_checksum.h>
44#include <linux/ethtool.h>
45#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040046#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000047#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070048
49#include "ixgbe.h"
50#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000051#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000052#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070053
54char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070055static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000056 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000057#define MAJ 3
Don Skidmorea38a1042011-05-20 03:05:14 +000058#define MIN 4
Don Skidmorec89c7112011-04-14 07:40:11 +000059#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000060#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
Don Skidmorea38a1042011-05-20 03:05:14 +000061 __stringify(BUILD) "-k"
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070062const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000063static const char ixgbe_copyright[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070065
66static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070067 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000068 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e2010-11-16 19:27:16 -080069 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070070};
71
72/* ixgbe_pci_tbl - PCI Device ID Table
73 *
74 * Wildcard entries (PCI_ANY_ID) should come last
75 * Last entry must be all 0s
76 *
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
79 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000080static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
82 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070086 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
88 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
90 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070092 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
94 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
96 board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
98 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
100 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
102 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
104 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
106 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
108 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
110 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
112 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
114 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
116 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
118 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
120 board_82599 },
121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
122 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
124 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
126 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000128 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000129 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
130 board_82599 },
Don Skidmore4f6290c2011-05-14 06:36:35 +0000131 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_LS),
132 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700133
134 /* required last entry */
135 {0, }
136};
137MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
138
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400139#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800140static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000141 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800142static struct notifier_block dca_notifier = {
143 .notifier_call = ixgbe_notify_dca,
144 .next = NULL,
145 .priority = 0
146};
147#endif
148
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000149#ifdef CONFIG_PCI_IOV
150static unsigned int max_vfs;
151module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000152MODULE_PARM_DESC(max_vfs,
153 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000154#endif /* CONFIG_PCI_IOV */
155
Auke Kok9a799d72007-09-15 14:07:45 -0700156MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
157MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
158MODULE_LICENSE("GPL");
159MODULE_VERSION(DRV_VERSION);
160
161#define DEFAULT_DEBUG_LEVEL_SHIFT 3
162
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000163static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
164{
165 struct ixgbe_hw *hw = &adapter->hw;
166 u32 gcr;
167 u32 gpie;
168 u32 vmdctl;
169
170#ifdef CONFIG_PCI_IOV
171 /* disable iov and allow time for transactions to clear */
172 pci_disable_sriov(adapter->pdev);
173#endif
174
175 /* turn off device IOV mode */
176 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
177 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
178 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
179 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
180 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
181 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
182
183 /* set default pool back to 0 */
184 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
185 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
186 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
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
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700775#define IXGBE_MAX_TXD_PWR 14
776#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800777
778/* Tx Descriptors needed, worst case */
779#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
780 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
781#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700782 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800783
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000784/**
785 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
786 * @adapter: driver private struct
787 **/
788static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
789{
790
791 /* Do the reset outside of interrupt context */
792 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
793 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
794 ixgbe_service_event_schedule(adapter);
795 }
796}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700797
Auke Kok9a799d72007-09-15 14:07:45 -0700798/**
799 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000800 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700801 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700802 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000803static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000804 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700805{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000806 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800807 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
808 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700809 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800810 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700811
812 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800813 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000814 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800815
816 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000817 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800818 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000819 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800820 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000821 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700822 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700823
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800824 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800825 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800826
Auke Kok9a799d72007-09-15 14:07:45 -0700827 i++;
828 if (i == tx_ring->count)
829 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800830
831 if (cleaned && tx_buffer_info->skb) {
832 total_bytes += tx_buffer_info->bytecount;
833 total_packets += tx_buffer_info->gso_segs;
834 }
835
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800836 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800837 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700838 }
839
John Fastabendc84d3242010-11-16 19:27:12 -0800840 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800841 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000842 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800843 }
844
Auke Kok9a799d72007-09-15 14:07:45 -0700845 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800846 tx_ring->total_bytes += total_bytes;
847 tx_ring->total_packets += total_packets;
848 u64_stats_update_begin(&tx_ring->syncp);
849 tx_ring->stats.packets += total_packets;
850 tx_ring->stats.bytes += total_bytes;
851 u64_stats_update_end(&tx_ring->syncp);
852
John Fastabendc84d3242010-11-16 19:27:12 -0800853 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800854 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800855 struct ixgbe_hw *hw = &adapter->hw;
856 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
857 e_err(drv, "Detected Tx Unit Hang\n"
858 " Tx Queue <%d>\n"
859 " TDH, TDT <%x>, <%x>\n"
860 " next_to_use <%x>\n"
861 " next_to_clean <%x>\n"
862 "tx_buffer_info[next_to_clean]\n"
863 " time_stamp <%lx>\n"
864 " jiffies <%lx>\n",
865 tx_ring->queue_index,
866 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
867 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
868 tx_ring->next_to_use, eop,
869 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
870
871 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
872
873 e_info(probe,
874 "tx hang %d detected on queue %d, resetting adapter\n",
875 adapter->tx_timeout_count + 1, tx_ring->queue_index);
876
877 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000878 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800879
880 /* the adapter is about to reset, no point in enabling stuff */
881 return true;
882 }
Auke Kok9a799d72007-09-15 14:07:45 -0700883
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800884#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800885 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Alexander Duyck7d4987d2011-05-27 05:31:37 +0000886 (ixgbe_desc_unused(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800887 /* Make sure that anybody stopping the queue after this
888 * sees the new next_to_clean.
889 */
890 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800891 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800892 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800893 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800894 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800895 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800896 }
Auke Kok9a799d72007-09-15 14:07:45 -0700897
Eric Dumazet807540b2010-09-23 05:40:09 +0000898 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700899}
900
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400901#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800902static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800903 struct ixgbe_ring *rx_ring,
904 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800905{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800906 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800907 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800908 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800909
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800910 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
911 switch (hw->mac.type) {
912 case ixgbe_mac_82598EB:
913 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
914 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
915 break;
916 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800917 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800918 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
919 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
920 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
921 break;
922 default:
923 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800924 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800925 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
926 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
927 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800928 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800929}
930
931static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932 struct ixgbe_ring *tx_ring,
933 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800934{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000935 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800936 u32 txctrl;
937 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800938
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800939 switch (hw->mac.type) {
940 case ixgbe_mac_82598EB:
941 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
942 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
943 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
944 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800945 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
946 break;
947 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800948 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
950 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
951 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
952 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
953 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800954 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
955 break;
956 default:
957 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800958 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800959}
960
961static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
962{
963 struct ixgbe_adapter *adapter = q_vector->adapter;
964 int cpu = get_cpu();
965 long r_idx;
966 int i;
967
968 if (q_vector->cpu == cpu)
969 goto out_no_update;
970
971 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
972 for (i = 0; i < q_vector->txr_count; i++) {
973 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
974 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
975 r_idx + 1);
976 }
977
978 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
979 for (i = 0; i < q_vector->rxr_count; i++) {
980 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
981 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
982 r_idx + 1);
983 }
984
985 q_vector->cpu = cpu;
986out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800987 put_cpu();
988}
989
990static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
991{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800992 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800993 int i;
994
995 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
996 return;
997
Alexander Duycke35ec122009-05-21 13:07:12 +0000998 /* always use CB2 mode, difference is masked in the CB driver */
999 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1000
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001001 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1002 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1003 else
1004 num_q_vectors = 1;
1005
1006 for (i = 0; i < num_q_vectors; i++) {
1007 adapter->q_vector[i]->cpu = -1;
1008 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001009 }
1010}
1011
1012static int __ixgbe_notify_dca(struct device *dev, void *data)
1013{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001014 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001015 unsigned long event = *(unsigned long *)data;
1016
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001017 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1018 return 0;
1019
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001020 switch (event) {
1021 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001022 /* if we're already enabled, don't do it again */
1023 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1024 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001025 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001026 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001027 ixgbe_setup_dca(adapter);
1028 break;
1029 }
1030 /* Fall Through since DCA is disabled. */
1031 case DCA_PROVIDER_REMOVE:
1032 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1033 dca_remove_requester(dev);
1034 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1035 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1036 }
1037 break;
1038 }
1039
Denis V. Lunev652f0932008-03-27 14:39:17 +03001040 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001041}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001042#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001043
1044static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1045 struct sk_buff *skb)
1046{
1047 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1048}
1049
Auke Kok9a799d72007-09-15 14:07:45 -07001050/**
1051 * ixgbe_receive_skb - Send a completed packet up the stack
1052 * @adapter: board private structure
1053 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001054 * @status: hardware indication of status of receive
1055 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1056 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001057 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001058static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001059 struct sk_buff *skb, u8 status,
1060 struct ixgbe_ring *ring,
1061 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001062{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001063 struct ixgbe_adapter *adapter = q_vector->adapter;
1064 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001065 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1066 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001067
Jesse Grossf62bbb52010-10-20 13:56:10 +00001068 if (is_vlan && (tag & VLAN_VID_MASK))
1069 __vlan_hwaccel_put_tag(skb, tag);
1070
1071 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1072 napi_gro_receive(napi, skb);
1073 else
1074 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001075}
1076
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001077/**
1078 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1079 * @adapter: address of board private structure
1080 * @status_err: hardware indication of status of receive
1081 * @skb: skb currently being received and modified
1082 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001083static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001084 union ixgbe_adv_rx_desc *rx_desc,
1085 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001086{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001087 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1088
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001089 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001090
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001091 /* Rx csum disabled */
1092 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001093 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001094
1095 /* if IP and error */
1096 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1097 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001098 adapter->hw_csum_rx_error++;
1099 return;
1100 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001101
1102 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1103 return;
1104
1105 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001106 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1107
1108 /*
1109 * 82599 errata, UDP frames with a 0 checksum can be marked as
1110 * checksum errors.
1111 */
1112 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1113 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1114 return;
1115
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001116 adapter->hw_csum_rx_error++;
1117 return;
1118 }
1119
Auke Kok9a799d72007-09-15 14:07:45 -07001120 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001121 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001122}
1123
Alexander Duyck84ea2592010-11-16 19:26:49 -08001124static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001125{
1126 /*
1127 * Force memory writes to complete before letting h/w
1128 * know there are new descriptors to fetch. (Only
1129 * applicable for weak-ordered memory model archs,
1130 * such as IA-64).
1131 */
1132 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001133 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001134}
1135
Auke Kok9a799d72007-09-15 14:07:45 -07001136/**
1137 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001138 * @rx_ring: ring to place buffers on
1139 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001140 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001141void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001142{
Auke Kok9a799d72007-09-15 14:07:45 -07001143 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001144 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001145 struct sk_buff *skb;
1146 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001147
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001148 /* do nothing if no valid netdev defined */
1149 if (!rx_ring->netdev)
1150 return;
1151
Auke Kok9a799d72007-09-15 14:07:45 -07001152 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001153 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001154 bi = &rx_ring->rx_buffer_info[i];
1155 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001156
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001157 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001158 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001159 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001160 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001161 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001162 goto no_buffers;
1163 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001164 /* initialize queue mapping */
1165 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001166 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001167 }
Auke Kok9a799d72007-09-15 14:07:45 -07001168
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001169 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001170 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001171 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001172 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001173 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001174 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001175 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001176 bi->dma = 0;
1177 goto no_buffers;
1178 }
Auke Kok9a799d72007-09-15 14:07:45 -07001179 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001180
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001181 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001182 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001183 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001184 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001185 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001186 goto no_buffers;
1187 }
1188 }
1189
1190 if (!bi->page_dma) {
1191 /* use a half page if we're re-using */
1192 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001193 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001194 bi->page,
1195 bi->page_offset,
1196 PAGE_SIZE / 2,
1197 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001198 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001199 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001200 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001201 bi->page_dma = 0;
1202 goto no_buffers;
1203 }
1204 }
1205
1206 /* Refresh the desc even if buffer_addrs didn't change
1207 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001208 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1209 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001210 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001211 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001212 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001213 }
1214
1215 i++;
1216 if (i == rx_ring->count)
1217 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001218 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001219
Auke Kok9a799d72007-09-15 14:07:45 -07001220no_buffers:
1221 if (rx_ring->next_to_use != i) {
1222 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001223 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001224 }
1225}
1226
Alexander Duyckc267fc12010-11-16 19:27:00 -08001227static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001228{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001229 /* HW will not DMA in data larger than the given buffer, even if it
1230 * parses the (NFS, of course) header to be larger. In that case, it
1231 * fills the header buffer and spills the rest into the page.
1232 */
1233 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1234 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1235 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1236 if (hlen > IXGBE_RX_HDR_SIZE)
1237 hlen = IXGBE_RX_HDR_SIZE;
1238 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001239}
1240
Alexander Duyckf8212f92009-04-27 22:42:37 +00001241/**
1242 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1243 * @skb: pointer to the last skb in the rsc queue
1244 *
1245 * This function changes a queue full of hw rsc buffers into a completed
1246 * packet. It uses the ->prev pointers to find the first packet and then
1247 * turns it into the frag list owner.
1248 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001249static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001250{
1251 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001252 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001253
1254 while (skb->prev) {
1255 struct sk_buff *prev = skb->prev;
1256 frag_list_size += skb->len;
1257 skb->prev = NULL;
1258 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001259 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001260 }
1261
1262 skb_shinfo(skb)->frag_list = skb->next;
1263 skb->next = NULL;
1264 skb->len += frag_list_size;
1265 skb->data_len += frag_list_size;
1266 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001267 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1268
Alexander Duyckf8212f92009-04-27 22:42:37 +00001269 return skb;
1270}
1271
Alexander Duyckaa801752010-11-16 19:27:02 -08001272static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1273{
1274 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1275 IXGBE_RXDADV_RSCCNT_MASK);
1276}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001277
Alexander Duyckc267fc12010-11-16 19:27:00 -08001278static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001279 struct ixgbe_ring *rx_ring,
1280 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001281{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001282 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001283 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1284 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1285 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001286 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001287 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001288#ifdef IXGBE_FCOE
1289 int ddp_bytes = 0;
1290#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001291 u32 staterr;
1292 u16 i;
1293 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001294 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001295
1296 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001297 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001298 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001299
1300 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001301 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001302
Milton Miller3c945e52010-02-19 17:44:42 +00001303 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001304
Alexander Duyckc267fc12010-11-16 19:27:00 -08001305 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1306
Auke Kok9a799d72007-09-15 14:07:45 -07001307 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001308 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001309 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001310
Alexander Duyckc267fc12010-11-16 19:27:00 -08001311 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001312 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001313
1314 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001315 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001316 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001317 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001318 !(staterr & IXGBE_RXD_STAT_EOP) &&
1319 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001320 /*
1321 * When HWRSC is enabled, delay unmapping
1322 * of the first packet. It carries the
1323 * header information, HW may still
1324 * access the header after the writeback.
1325 * Only unmap it when EOP is reached
1326 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001327 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001328 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001329 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001330 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001331 rx_buffer_info->dma,
1332 rx_ring->rx_buf_len,
1333 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001334 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001335 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001336
1337 if (ring_is_ps_enabled(rx_ring)) {
1338 hlen = ixgbe_get_hlen(rx_desc);
1339 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1340 } else {
1341 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1342 }
1343
1344 skb_put(skb, hlen);
1345 } else {
1346 /* assume packet split since header is unmapped */
1347 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001348 }
1349
1350 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001351 dma_unmap_page(rx_ring->dev,
1352 rx_buffer_info->page_dma,
1353 PAGE_SIZE / 2,
1354 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001355 rx_buffer_info->page_dma = 0;
1356 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001357 rx_buffer_info->page,
1358 rx_buffer_info->page_offset,
1359 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001360
Alexander Duyckc267fc12010-11-16 19:27:00 -08001361 if ((page_count(rx_buffer_info->page) == 1) &&
1362 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001363 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001364 else
1365 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001366
1367 skb->len += upper_len;
1368 skb->data_len += upper_len;
1369 skb->truesize += upper_len;
1370 }
1371
1372 i++;
1373 if (i == rx_ring->count)
1374 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001375
Alexander Duyck31f05a22010-08-19 13:40:31 +00001376 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001377 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001378 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001379
Alexander Duyckaa801752010-11-16 19:27:02 -08001380 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001381 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1382 IXGBE_RXDADV_NEXTP_SHIFT;
1383 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001384 } else {
1385 next_buffer = &rx_ring->rx_buffer_info[i];
1386 }
1387
Alexander Duyckc267fc12010-11-16 19:27:00 -08001388 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001389 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001390 rx_buffer_info->skb = next_buffer->skb;
1391 rx_buffer_info->dma = next_buffer->dma;
1392 next_buffer->skb = skb;
1393 next_buffer->dma = 0;
1394 } else {
1395 skb->next = next_buffer->skb;
1396 skb->next->prev = skb;
1397 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001398 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001399 goto next_desc;
1400 }
1401
Alexander Duyckaa801752010-11-16 19:27:02 -08001402 if (skb->prev) {
1403 skb = ixgbe_transform_rsc_queue(skb);
1404 /* if we got here without RSC the packet is invalid */
1405 if (!pkt_is_rsc) {
1406 __pskb_trim(skb, 0);
1407 rx_buffer_info->skb = skb;
1408 goto next_desc;
1409 }
1410 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001411
1412 if (ring_is_rsc_enabled(rx_ring)) {
1413 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1414 dma_unmap_single(rx_ring->dev,
1415 IXGBE_RSC_CB(skb)->dma,
1416 rx_ring->rx_buf_len,
1417 DMA_FROM_DEVICE);
1418 IXGBE_RSC_CB(skb)->dma = 0;
1419 IXGBE_RSC_CB(skb)->delay_unmap = false;
1420 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001421 }
1422 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001423 if (ring_is_ps_enabled(rx_ring))
1424 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001425 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001426 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001427 rx_ring->rx_stats.rsc_count +=
1428 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001429 rx_ring->rx_stats.rsc_flush++;
1430 }
1431
1432 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001433 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001434 /* trim packet back to size 0 and recycle it */
1435 __pskb_trim(skb, 0);
1436 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001437 goto next_desc;
1438 }
1439
Don Skidmore8bae1b22009-07-23 18:00:39 +00001440 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001441 if (adapter->netdev->features & NETIF_F_RXHASH)
1442 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001443
1444 /* probably a little skewed due to removing CRC */
1445 total_rx_bytes += skb->len;
1446 total_rx_packets++;
1447
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001448 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001449#ifdef IXGBE_FCOE
1450 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001451 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1452 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1453 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001454 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001455 }
Yi Zou332d4a72009-05-13 13:11:53 +00001456#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001457 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001458
1459next_desc:
1460 rx_desc->wb.upper.status_error = 0;
1461
Alexander Duyckc267fc12010-11-16 19:27:00 -08001462 (*work_done)++;
1463 if (*work_done >= work_to_do)
1464 break;
1465
Auke Kok9a799d72007-09-15 14:07:45 -07001466 /* return some buffers to hardware, one at a time is too slow */
1467 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001468 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001469 cleaned_count = 0;
1470 }
1471
1472 /* use prefetched values */
1473 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001474 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001475 }
1476
Auke Kok9a799d72007-09-15 14:07:45 -07001477 rx_ring->next_to_clean = i;
Alexander Duyck7d4987d2011-05-27 05:31:37 +00001478 cleaned_count = ixgbe_desc_unused(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07001479
1480 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001481 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001482
Yi Zou3d8fd382009-06-08 14:38:44 +00001483#ifdef IXGBE_FCOE
1484 /* include DDPed FCoE data */
1485 if (ddp_bytes > 0) {
1486 unsigned int mss;
1487
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001488 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001489 sizeof(struct fc_frame_header) -
1490 sizeof(struct fcoe_crc_eof);
1491 if (mss > 512)
1492 mss &= ~511;
1493 total_rx_bytes += ddp_bytes;
1494 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1495 }
1496#endif /* IXGBE_FCOE */
1497
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001498 rx_ring->total_packets += total_rx_packets;
1499 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001500 u64_stats_update_begin(&rx_ring->syncp);
1501 rx_ring->stats.packets += total_rx_packets;
1502 rx_ring->stats.bytes += total_rx_bytes;
1503 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001504}
1505
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001506static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001507/**
1508 * ixgbe_configure_msix - Configure MSI-X hardware
1509 * @adapter: board private structure
1510 *
1511 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1512 * interrupts.
1513 **/
1514static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1515{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001516 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001517 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001518 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001519
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001520 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1521
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001522 /*
1523 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001524 * corresponding register.
1525 */
1526 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001527 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001528 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001529 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001530 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001531
1532 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001533 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1534 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001535 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001536 adapter->num_rx_queues,
1537 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001538 }
1539 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001540 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001541
1542 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001543 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1544 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001545 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001546 adapter->num_tx_queues,
1547 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 }
1549
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001550 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001551 /* tx only */
1552 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001553 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001554 /* rx or mixed */
1555 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556
Alexander Duyckfe49f042009-06-04 16:00:09 +00001557 ixgbe_write_eitr(q_vector);
Alexander Duyck03ecf912011-05-20 07:36:17 +00001558 /* If ATR is enabled, set interrupt affinity */
1559 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001560 /*
1561 * Allocate the affinity_hint cpumask, assign the mask
1562 * for this vector, and set our affinity_hint for
1563 * this irq.
1564 */
1565 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1566 GFP_KERNEL))
1567 return;
1568 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1569 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1570 q_vector->affinity_mask);
1571 }
Auke Kok9a799d72007-09-15 14:07:45 -07001572 }
1573
Alexander Duyckbd508172010-11-16 19:27:03 -08001574 switch (adapter->hw.mac.type) {
1575 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001576 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001577 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001578 break;
1579 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001580 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001581 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001582 break;
1583
1584 default:
1585 break;
1586 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001588
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001589 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001590 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001591 if (adapter->num_vfs)
1592 mask &= ~(IXGBE_EIMS_OTHER |
1593 IXGBE_EIMS_MAILBOX |
1594 IXGBE_EIMS_LSC);
1595 else
1596 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001597 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001598}
1599
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001600enum latency_range {
1601 lowest_latency = 0,
1602 low_latency = 1,
1603 bulk_latency = 2,
1604 latency_invalid = 255
1605};
1606
1607/**
1608 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1609 * @adapter: pointer to adapter
1610 * @eitr: eitr setting (ints per sec) to give last timeslice
1611 * @itr_setting: current throttle rate in ints/second
1612 * @packets: the number of packets during this measurement interval
1613 * @bytes: the number of bytes during this measurement interval
1614 *
1615 * Stores a new ITR value based on packets and byte
1616 * counts during the last interrupt. The advantage of per interrupt
1617 * computation is faster updates and more accurate ITR for the current
1618 * traffic pattern. Constants in this function were computed
1619 * based on theoretical maximum wire speed and thresholds were set based
1620 * on testing data as well as attempting to minimize response time
1621 * while increasing bulk throughput.
1622 * this functionality is controlled by the InterruptThrottleRate module
1623 * parameter (see ixgbe_param.c)
1624 **/
1625static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001626 u32 eitr, u8 itr_setting,
1627 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001628{
1629 unsigned int retval = itr_setting;
1630 u32 timepassed_us;
1631 u64 bytes_perint;
1632
1633 if (packets == 0)
1634 goto update_itr_done;
1635
1636
1637 /* simple throttlerate management
1638 * 0-20MB/s lowest (100000 ints/s)
1639 * 20-100MB/s low (20000 ints/s)
1640 * 100-1249MB/s bulk (8000 ints/s)
1641 */
1642 /* what was last interrupt timeslice? */
1643 timepassed_us = 1000000/eitr;
1644 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1645
1646 switch (itr_setting) {
1647 case lowest_latency:
1648 if (bytes_perint > adapter->eitr_low)
1649 retval = low_latency;
1650 break;
1651 case low_latency:
1652 if (bytes_perint > adapter->eitr_high)
1653 retval = bulk_latency;
1654 else if (bytes_perint <= adapter->eitr_low)
1655 retval = lowest_latency;
1656 break;
1657 case bulk_latency:
1658 if (bytes_perint <= adapter->eitr_high)
1659 retval = low_latency;
1660 break;
1661 }
1662
1663update_itr_done:
1664 return retval;
1665}
1666
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001667/**
1668 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001669 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001670 *
1671 * This function is made to be called by ethtool and by the driver
1672 * when it needs to update EITR registers at runtime. Hardware
1673 * specific quirks/differences are taken care of here.
1674 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001675void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001676{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001677 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001678 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001679 int v_idx = q_vector->v_idx;
1680 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1681
Alexander Duyckbd508172010-11-16 19:27:03 -08001682 switch (adapter->hw.mac.type) {
1683 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001684 /* must write high and low 16 bits to reset counter */
1685 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001686 break;
1687 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001688 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001689 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001690 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001691 * max interrupt rate, but there is an errata where it can
1692 * not be zero with RSC
1693 */
1694 if (itr_reg == 8 &&
1695 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1696 itr_reg = 0;
1697
1698 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001699 * set the WDIS bit to not clear the timer bits and cause an
1700 * immediate assertion of the interrupt
1701 */
1702 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001703 break;
1704 default:
1705 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001706 }
1707 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1708}
1709
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001710static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1711{
1712 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001713 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001714 u32 new_itr;
1715 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001716
1717 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1718 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001719 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001720 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001721 q_vector->tx_itr,
1722 tx_ring->total_packets,
1723 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001724 /* if the result for this queue would decrease interrupt
1725 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001726 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001727 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001728 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001729 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001730 }
1731
1732 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1733 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001734 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001735 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001736 q_vector->rx_itr,
1737 rx_ring->total_packets,
1738 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001739 /* if the result for this queue would decrease interrupt
1740 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001741 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001742 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001743 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001744 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001745 }
1746
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001747 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001748
1749 switch (current_itr) {
1750 /* counts and packets in update_itr are dependent on these numbers */
1751 case lowest_latency:
1752 new_itr = 100000;
1753 break;
1754 case low_latency:
1755 new_itr = 20000; /* aka hwitr = ~200 */
1756 break;
1757 case bulk_latency:
1758 default:
1759 new_itr = 8000;
1760 break;
1761 }
1762
1763 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001764 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001765 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001766
1767 /* save the algorithm value here, not the smoothed one */
1768 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001769
1770 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001772}
1773
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001774/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001775 * ixgbe_check_overtemp_subtask - check for over tempurature
1776 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001777 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001778static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001779{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001780 struct ixgbe_hw *hw = &adapter->hw;
1781 u32 eicr = adapter->interrupt_event;
1782
Alexander Duyckf0f97782011-04-22 04:08:09 +00001783 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001784 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001785
Alexander Duyckf0f97782011-04-22 04:08:09 +00001786 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1787 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1788 return;
1789
1790 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1791
Joe Perches7ca647b2010-09-07 21:35:40 +00001792 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001793 case IXGBE_DEV_ID_82599_T3_LOM:
1794 /*
1795 * Since the warning interrupt is for both ports
1796 * we don't have to check if:
1797 * - This interrupt wasn't for our port.
1798 * - We may have missed the interrupt so always have to
1799 * check if we got a LSC
1800 */
1801 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1802 !(eicr & IXGBE_EICR_LSC))
1803 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001804
Alexander Duyckf0f97782011-04-22 04:08:09 +00001805 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1806 u32 autoneg;
1807 bool link_up = false;
1808
Joe Perches7ca647b2010-09-07 21:35:40 +00001809 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1810
Alexander Duyckf0f97782011-04-22 04:08:09 +00001811 if (link_up)
1812 return;
1813 }
1814
1815 /* Check if this is not due to overtemp */
1816 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1817 return;
1818
1819 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001820 default:
1821 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1822 return;
1823 break;
1824 }
1825 e_crit(drv,
1826 "Network adapter has been stopped because it has over heated. "
1827 "Restart the computer. If the problem persists, "
1828 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001829
1830 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001831}
1832
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001833static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1834{
1835 struct ixgbe_hw *hw = &adapter->hw;
1836
1837 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1838 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001839 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001840 /* write to clear the interrupt */
1841 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1842 }
1843}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001844
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001845static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1846{
1847 struct ixgbe_hw *hw = &adapter->hw;
1848
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001849 if (eicr & IXGBE_EICR_GPI_SDP2) {
1850 /* Clear the interrupt */
1851 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001852 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1853 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1854 ixgbe_service_event_schedule(adapter);
1855 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001856 }
1857
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001858 if (eicr & IXGBE_EICR_GPI_SDP1) {
1859 /* Clear the interrupt */
1860 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001861 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1862 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1863 ixgbe_service_event_schedule(adapter);
1864 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001865 }
1866}
1867
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001868static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1869{
1870 struct ixgbe_hw *hw = &adapter->hw;
1871
1872 adapter->lsc_int++;
1873 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1874 adapter->link_check_timeout = jiffies;
1875 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1876 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001877 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001878 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001879 }
1880}
1881
Auke Kok9a799d72007-09-15 14:07:45 -07001882static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1883{
Alexander Duycka65151ba22011-05-27 05:31:32 +00001884 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07001885 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001886 u32 eicr;
1887
1888 /*
1889 * Workaround for Silicon errata. Use clear-by-write instead
1890 * of clear-by-read. Reading with EICS will return the
1891 * interrupt causes without clearing, which later be done
1892 * with the write to EICR.
1893 */
1894 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1895 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001896
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001897 if (eicr & IXGBE_EICR_LSC)
1898 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001899
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001900 if (eicr & IXGBE_EICR_MAILBOX)
1901 ixgbe_msg_task(adapter);
1902
Alexander Duyckbd508172010-11-16 19:27:03 -08001903 switch (hw->mac.type) {
1904 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001905 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001906 /* Handle Flow Director Full threshold interrupt */
1907 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001908 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001909 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001910 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001911 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001912 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001913 &ring->state))
1914 reinit_count++;
1915 }
1916 if (reinit_count) {
1917 /* no more flow director interrupts until after init */
1918 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1919 eicr &= ~IXGBE_EICR_FLOW_DIR;
1920 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1921 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001922 }
1923 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001924 ixgbe_check_sfp_event(adapter, eicr);
1925 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1926 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1927 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1928 adapter->interrupt_event = eicr;
1929 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1930 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001931 }
1932 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001933 break;
1934 default:
1935 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001936 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001937
1938 ixgbe_check_fan_failure(adapter, eicr);
1939
Alexander Duyck70864002011-04-27 09:13:56 +00001940 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001941 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001942 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1943 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001944
1945 return IRQ_HANDLED;
1946}
1947
Alexander Duyckfe49f042009-06-04 16:00:09 +00001948static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1949 u64 qmask)
1950{
1951 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001952 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001953
Alexander Duyckbd508172010-11-16 19:27:03 -08001954 switch (hw->mac.type) {
1955 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001956 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001957 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1958 break;
1959 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001960 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001961 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001962 if (mask)
1963 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001964 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001965 if (mask)
1966 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1967 break;
1968 default:
1969 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001970 }
1971 /* skip the flush */
1972}
1973
1974static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001975 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001976{
1977 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001978 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001979
Alexander Duyckbd508172010-11-16 19:27:03 -08001980 switch (hw->mac.type) {
1981 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001982 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001983 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1984 break;
1985 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001986 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001987 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001988 if (mask)
1989 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001990 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001991 if (mask)
1992 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1993 break;
1994 default:
1995 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001996 }
1997 /* skip the flush */
1998}
1999
Auke Kok9a799d72007-09-15 14:07:45 -07002000static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2001{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002002 struct ixgbe_q_vector *q_vector = data;
2003 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002004 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002005 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002006
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002007 if (!q_vector->txr_count)
2008 return IRQ_HANDLED;
2009
2010 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2011 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002012 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002013 tx_ring->total_bytes = 0;
2014 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002015 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002016 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002017 }
2018
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002019 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002020 napi_schedule(&q_vector->napi);
2021
Auke Kok9a799d72007-09-15 14:07:45 -07002022 return IRQ_HANDLED;
2023}
2024
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002025/**
2026 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2027 * @irq: unused
2028 * @data: pointer to our q_vector struct for this interrupt vector
2029 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002030static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2031{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002032 struct ixgbe_q_vector *q_vector = data;
2033 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002034 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002035 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002036 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002037
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002038#ifdef CONFIG_IXGBE_DCA
2039 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2040 ixgbe_update_dca(q_vector);
2041#endif
2042
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002043 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002044 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002045 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002046 rx_ring->total_bytes = 0;
2047 rx_ring->total_packets = 0;
2048 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002049 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002050 }
2051
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002052 if (!q_vector->rxr_count)
2053 return IRQ_HANDLED;
2054
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002055 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002056 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002057
Auke Kok9a799d72007-09-15 14:07:45 -07002058 return IRQ_HANDLED;
2059}
2060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002061static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2062{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002063 struct ixgbe_q_vector *q_vector = data;
2064 struct ixgbe_adapter *adapter = q_vector->adapter;
2065 struct ixgbe_ring *ring;
2066 int r_idx;
2067 int i;
2068
2069 if (!q_vector->txr_count && !q_vector->rxr_count)
2070 return IRQ_HANDLED;
2071
2072 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2073 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002074 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002075 ring->total_bytes = 0;
2076 ring->total_packets = 0;
2077 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002078 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002079 }
2080
2081 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2082 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002083 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002084 ring->total_bytes = 0;
2085 ring->total_packets = 0;
2086 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002087 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002088 }
2089
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002090 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002091 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002092
2093 return IRQ_HANDLED;
2094}
2095
2096/**
2097 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2098 * @napi: napi struct with our devices info in it
2099 * @budget: amount of work driver is allowed to do this pass, in packets
2100 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002101 * This function is optimized for cleaning one queue only on a single
2102 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002103 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002104static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2105{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002106 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002107 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002108 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002109 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002110 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002111 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002112
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002113#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002114 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002115 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002116#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002117
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002118 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2119 rx_ring = adapter->rx_ring[r_idx];
2120
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002121 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002122
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002123 /* If all Rx work done, exit the polling mode */
2124 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002125 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002126 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002127 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002128 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002129 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002130 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002131 }
2132
2133 return work_done;
2134}
2135
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002136/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002137 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002138 * @napi: napi struct with our devices info in it
2139 * @budget: amount of work driver is allowed to do this pass, in packets
2140 *
2141 * This function will clean more than one rx queue associated with a
2142 * q_vector.
2143 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002144static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002145{
2146 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002147 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002148 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002149 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002150 int work_done = 0, i;
2151 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002152 bool tx_clean_complete = true;
2153
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002154#ifdef CONFIG_IXGBE_DCA
2155 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2156 ixgbe_update_dca(q_vector);
2157#endif
2158
Alexander Duyck91281fd2009-06-04 16:00:27 +00002159 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2160 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002161 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002162 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2163 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002164 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002165 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002166
2167 /* attempt to distribute budget to each queue fairly, but don't allow
2168 * the budget to go below 1 because we'll exit polling */
2169 budget /= (q_vector->rxr_count ?: 1);
2170 budget = max(budget, 1);
2171 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2172 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002173 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002174 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002175 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002176 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002177 }
2178
2179 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002180 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002181 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002182 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002183 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002184 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002185 ixgbe_set_itr_msix(q_vector);
2186 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002187 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002188 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002189 return 0;
2190 }
2191
2192 return work_done;
2193}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002194
2195/**
2196 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2197 * @napi: napi struct with our devices info in it
2198 * @budget: amount of work driver is allowed to do this pass, in packets
2199 *
2200 * This function is optimized for cleaning one queue only on a single
2201 * q_vector!!!
2202 **/
2203static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2204{
2205 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002206 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002207 struct ixgbe_adapter *adapter = q_vector->adapter;
2208 struct ixgbe_ring *tx_ring = NULL;
2209 int work_done = 0;
2210 long r_idx;
2211
Alexander Duyck91281fd2009-06-04 16:00:27 +00002212#ifdef CONFIG_IXGBE_DCA
2213 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002214 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002215#endif
2216
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002217 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2218 tx_ring = adapter->tx_ring[r_idx];
2219
Alexander Duyck91281fd2009-06-04 16:00:27 +00002220 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2221 work_done = budget;
2222
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002223 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002224 if (work_done < budget) {
2225 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002226 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002227 ixgbe_set_itr_msix(q_vector);
2228 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002229 ixgbe_irq_enable_queues(adapter,
2230 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002231 }
2232
2233 return work_done;
2234}
2235
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002236static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002237 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002238{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002239 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002240 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002241
2242 set_bit(r_idx, q_vector->rxr_idx);
2243 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002244 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245}
Auke Kok9a799d72007-09-15 14:07:45 -07002246
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002248 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002249{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002250 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002251 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002252
2253 set_bit(t_idx, q_vector->txr_idx);
2254 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002255 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256}
Auke Kok9a799d72007-09-15 14:07:45 -07002257
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002258/**
2259 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2260 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002261 *
2262 * This function maps descriptor rings to the queue-specific vectors
2263 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2264 * one vector per ring/queue, but on a constrained vector budget, we
2265 * group the rings as "efficiently" as possible. You would add new
2266 * mapping configurations in here.
2267 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002268static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002270 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002271 int v_start = 0;
2272 int rxr_idx = 0, txr_idx = 0;
2273 int rxr_remaining = adapter->num_rx_queues;
2274 int txr_remaining = adapter->num_tx_queues;
2275 int i, j;
2276 int rqpv, tqpv;
2277 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002278
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002279 /* No mapping required if MSI-X is disabled. */
2280 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002281 goto out;
2282
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002283 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2284
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002285 /*
2286 * The ideal configuration...
2287 * We have enough vectors to map one per queue.
2288 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002289 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002290 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2291 map_vector_to_rxq(adapter, v_start, rxr_idx);
2292
2293 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2294 map_vector_to_txq(adapter, v_start, txr_idx);
2295
2296 goto out;
2297 }
2298
2299 /*
2300 * If we don't have enough vectors for a 1-to-1
2301 * mapping, we'll have to group them so there are
2302 * multiple queues per vector.
2303 */
2304 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002305 for (i = v_start; i < q_vectors; i++) {
2306 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002307 for (j = 0; j < rqpv; j++) {
2308 map_vector_to_rxq(adapter, i, rxr_idx);
2309 rxr_idx++;
2310 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002311 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002312 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002313 for (j = 0; j < tqpv; j++) {
2314 map_vector_to_txq(adapter, i, txr_idx);
2315 txr_idx++;
2316 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002317 }
Auke Kok9a799d72007-09-15 14:07:45 -07002318 }
Auke Kok9a799d72007-09-15 14:07:45 -07002319out:
Auke Kok9a799d72007-09-15 14:07:45 -07002320 return err;
2321}
2322
2323/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002324 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2325 * @adapter: board private structure
2326 *
2327 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2328 * interrupts from the kernel.
2329 **/
2330static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2331{
2332 struct net_device *netdev = adapter->netdev;
2333 irqreturn_t (*handler)(int, void *);
2334 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002335 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002336
2337 /* Decrement for Other and TCP Timer vectors */
2338 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2339
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002340 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002342 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002344#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2345 ? &ixgbe_msix_clean_many : \
2346 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2347 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2348 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002349 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002350 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2351 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002352
Joe Perchese8e9f692010-09-07 21:34:53 +00002353 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002354 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2355 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002356 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002357 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2358 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002359 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002360 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2361 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002362 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002363 } else {
2364 /* skip this unused q_vector */
2365 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002366 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002368 handler, 0, q_vector->name,
2369 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002370 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002371 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002372 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002373 goto free_queue_irqs;
2374 }
2375 }
2376
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002377 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002378 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002379 ixgbe_msix_lsc, 0, adapter->lsc_int_name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002380 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002381 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002382 goto free_queue_irqs;
2383 }
2384
2385 return 0;
2386
2387free_queue_irqs:
2388 for (i = vector - 1; i >= 0; i--)
2389 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002390 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002391 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2392 pci_disable_msix(adapter->pdev);
2393 kfree(adapter->msix_entries);
2394 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002395 return err;
2396}
2397
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002398static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2399{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002400 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002401 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2402 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002403 u32 new_itr = q_vector->eitr;
2404 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002405
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002406 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002407 q_vector->tx_itr,
2408 tx_ring->total_packets,
2409 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002410 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002411 q_vector->rx_itr,
2412 rx_ring->total_packets,
2413 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002414
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002415 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002416
2417 switch (current_itr) {
2418 /* counts and packets in update_itr are dependent on these numbers */
2419 case lowest_latency:
2420 new_itr = 100000;
2421 break;
2422 case low_latency:
2423 new_itr = 20000; /* aka hwitr = ~200 */
2424 break;
2425 case bulk_latency:
2426 new_itr = 8000;
2427 break;
2428 default:
2429 break;
2430 }
2431
2432 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002433 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002434 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002435
Alexander Duyck125601b2010-11-16 19:27:08 -08002436 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002437 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002438
2439 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002440 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002441}
2442
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002443/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002444 * ixgbe_irq_enable - Enable default interrupt generation settings
2445 * @adapter: board private structure
2446 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002447static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2448 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002449{
2450 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002451
2452 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002453 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2454 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002455 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2456 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002457 switch (adapter->hw.mac.type) {
2458 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002459 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002460 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002461 mask |= IXGBE_EIMS_GPI_SDP1;
2462 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002463 if (adapter->num_vfs)
2464 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002465 break;
2466 default:
2467 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002468 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00002469 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002470 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002471
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002472 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002473 if (queues)
2474 ixgbe_irq_enable_queues(adapter, ~0);
2475 if (flush)
2476 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002477
2478 if (adapter->num_vfs > 32) {
2479 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2480 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2481 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002482}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002483
2484/**
2485 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002486 * @irq: interrupt number
2487 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002488 **/
2489static irqreturn_t ixgbe_intr(int irq, void *data)
2490{
Alexander Duycka65151ba22011-05-27 05:31:32 +00002491 struct ixgbe_adapter *adapter = data;
Auke Kok9a799d72007-09-15 14:07:45 -07002492 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002493 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002494 u32 eicr;
2495
Don Skidmore54037502009-02-21 15:42:56 -08002496 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002497 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002498 * before the read of EICR.
2499 */
2500 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2501
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2503 * therefore no explict interrupt disable is necessary */
2504 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002505 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002506 /*
2507 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002508 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002509 * have disabled interrupts due to EIAM
2510 * finish the workaround of silicon errata on 82598. Unmask
2511 * the interrupt that we masked before the EICR read.
2512 */
2513 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2514 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002515 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002516 }
Auke Kok9a799d72007-09-15 14:07:45 -07002517
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002518 if (eicr & IXGBE_EICR_LSC)
2519 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520
Alexander Duyckbd508172010-11-16 19:27:03 -08002521 switch (hw->mac.type) {
2522 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002523 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002524 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2525 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002526 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2527 adapter->interrupt_event = eicr;
2528 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2529 ixgbe_service_event_schedule(adapter);
2530 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002531 }
2532 break;
2533 default:
2534 break;
2535 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002536
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002537 ixgbe_check_fan_failure(adapter, eicr);
2538
Alexander Duyck7a921c92009-05-06 10:43:28 +00002539 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002540 adapter->tx_ring[0]->total_packets = 0;
2541 adapter->tx_ring[0]->total_bytes = 0;
2542 adapter->rx_ring[0]->total_packets = 0;
2543 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002544 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002545 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002546 }
2547
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002548 /*
2549 * re-enable link(maybe) and non-queue interrupts, no flush.
2550 * ixgbe_poll will re-enable the queue interrupts
2551 */
2552
2553 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2554 ixgbe_irq_enable(adapter, false, false);
2555
Auke Kok9a799d72007-09-15 14:07:45 -07002556 return IRQ_HANDLED;
2557}
2558
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002559static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2560{
2561 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2562
2563 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002564 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002565 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2566 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2567 q_vector->rxr_count = 0;
2568 q_vector->txr_count = 0;
2569 }
2570}
2571
Auke Kok9a799d72007-09-15 14:07:45 -07002572/**
2573 * ixgbe_request_irq - initialize interrupts
2574 * @adapter: board private structure
2575 *
2576 * Attempts to configure interrupts using the best available
2577 * capabilities of the hardware and kernel.
2578 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002579static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002580{
2581 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002582 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002583
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2585 err = ixgbe_request_msix_irqs(adapter);
2586 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002587 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002588 netdev->name, adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002589 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002590 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Alexander Duycka65151ba22011-05-27 05:31:32 +00002591 netdev->name, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002592 }
2593
Auke Kok9a799d72007-09-15 14:07:45 -07002594 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002595 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002596
Auke Kok9a799d72007-09-15 14:07:45 -07002597 return err;
2598}
2599
2600static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2601{
Auke Kok9a799d72007-09-15 14:07:45 -07002602 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002603 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002604
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002605 q_vectors = adapter->num_msix_vectors;
2606
2607 i = q_vectors - 1;
Alexander Duycka65151ba22011-05-27 05:31:32 +00002608 free_irq(adapter->msix_entries[i].vector, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002609
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002610 i--;
2611 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002612 /* free only the irqs that were actually requested */
2613 if (!adapter->q_vector[i]->rxr_count &&
2614 !adapter->q_vector[i]->txr_count)
2615 continue;
2616
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002617 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002618 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002619 }
2620
2621 ixgbe_reset_q_vectors(adapter);
2622 } else {
Alexander Duycka65151ba22011-05-27 05:31:32 +00002623 free_irq(adapter->pdev->irq, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07002624 }
2625}
2626
2627/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002628 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2629 * @adapter: board private structure
2630 **/
2631static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2632{
Alexander Duyckbd508172010-11-16 19:27:03 -08002633 switch (adapter->hw.mac.type) {
2634 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002635 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002636 break;
2637 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002638 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002641 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002642 if (adapter->num_vfs > 32)
2643 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002644 break;
2645 default:
2646 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002647 }
2648 IXGBE_WRITE_FLUSH(&adapter->hw);
2649 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2650 int i;
2651 for (i = 0; i < adapter->num_msix_vectors; i++)
2652 synchronize_irq(adapter->msix_entries[i].vector);
2653 } else {
2654 synchronize_irq(adapter->pdev->irq);
2655 }
2656}
2657
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002658/**
Auke Kok9a799d72007-09-15 14:07:45 -07002659 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2660 *
2661 **/
2662static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2663{
Auke Kok9a799d72007-09-15 14:07:45 -07002664 struct ixgbe_hw *hw = &adapter->hw;
2665
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002666 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002667 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002668
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002669 ixgbe_set_ivar(adapter, 0, 0, 0);
2670 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002671
2672 map_vector_to_rxq(adapter, 0, 0);
2673 map_vector_to_txq(adapter, 0, 0);
2674
Emil Tantilov396e7992010-07-01 20:05:12 +00002675 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002676}
2677
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002678/**
2679 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2680 * @adapter: board private structure
2681 * @ring: structure containing ring specific data
2682 *
2683 * Configure the Tx descriptor ring after a reset.
2684 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002685void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2686 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002687{
2688 struct ixgbe_hw *hw = &adapter->hw;
2689 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002690 int wait_loop = 10;
2691 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002692 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002693
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002694 /* disable queue to avoid issues while updating state */
2695 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2696 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2697 txdctl & ~IXGBE_TXDCTL_ENABLE);
2698 IXGBE_WRITE_FLUSH(hw);
2699
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002700 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002701 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002702 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2703 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2704 ring->count * sizeof(union ixgbe_adv_tx_desc));
2705 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2706 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002707 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002708
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002709 /* configure fetching thresholds */
2710 if (adapter->rx_itr_setting == 0) {
2711 /* cannot set wthresh when itr==0 */
2712 txdctl &= ~0x007F0000;
2713 } else {
2714 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2715 txdctl |= (8 << 16);
2716 }
2717 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2718 /* PThresh workaround for Tx hang with DFP enabled. */
2719 txdctl |= 32;
2720 }
2721
2722 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002723 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2724 adapter->atr_sample_rate) {
2725 ring->atr_sample_rate = adapter->atr_sample_rate;
2726 ring->atr_count = 0;
2727 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2728 } else {
2729 ring->atr_sample_rate = 0;
2730 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002731
John Fastabendc84d3242010-11-16 19:27:12 -08002732 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2733
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002734 /* enable queue */
2735 txdctl |= IXGBE_TXDCTL_ENABLE;
2736 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2737
2738 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2739 if (hw->mac.type == ixgbe_mac_82598EB &&
2740 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2741 return;
2742
2743 /* poll to verify queue is enabled */
2744 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002745 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002746 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2747 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2748 if (!wait_loop)
2749 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002750}
2751
Alexander Duyck120ff942010-08-19 13:34:50 +00002752static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2753{
2754 struct ixgbe_hw *hw = &adapter->hw;
2755 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002756 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002757 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002758
2759 if (hw->mac.type == ixgbe_mac_82598EB)
2760 return;
2761
2762 /* disable the arbiter while setting MTQC */
2763 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2764 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2765 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2766
2767 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002768 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002769 case (IXGBE_FLAG_SRIOV_ENABLED):
2770 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2771 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2772 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002773 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002774 if (!tcs)
2775 reg = IXGBE_MTQC_64Q_1PB;
2776 else if (tcs <= 4)
2777 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2778 else
2779 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2780
2781 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2782
2783 /* Enable Security TX Buffer IFG for multiple pb */
2784 if (tcs) {
2785 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2786 reg |= IXGBE_SECTX_DCB;
2787 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2788 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002789 break;
2790 }
2791
2792 /* re-enable the arbiter */
2793 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2794 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2795}
2796
Auke Kok9a799d72007-09-15 14:07:45 -07002797/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002798 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002799 * @adapter: board private structure
2800 *
2801 * Configure the Tx unit of the MAC after a reset.
2802 **/
2803static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2804{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002805 struct ixgbe_hw *hw = &adapter->hw;
2806 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002807 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002808
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002809 ixgbe_setup_mtqc(adapter);
2810
2811 if (hw->mac.type != ixgbe_mac_82598EB) {
2812 /* DMATXCTL.EN must be before Tx queues are enabled */
2813 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2814 dmatxctl |= IXGBE_DMATXCTL_TE;
2815 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2816 }
2817
Auke Kok9a799d72007-09-15 14:07:45 -07002818 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002819 for (i = 0; i < adapter->num_tx_queues; i++)
2820 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002821}
2822
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002823#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002824
Yi Zoua6616b42009-08-06 13:05:23 +00002825static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002826 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002827{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002828 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002829 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002830
Alexander Duyckbd508172010-11-16 19:27:03 -08002831 switch (adapter->hw.mac.type) {
2832 case ixgbe_mac_82598EB: {
2833 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2834 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002835 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002836 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002837 break;
2838 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002839 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002840 default:
2841 break;
2842 }
2843
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002844 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002845
2846 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2847 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002848 if (adapter->num_vfs)
2849 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002850
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002851 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2852 IXGBE_SRRCTL_BSIZEHDR_MASK;
2853
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002854 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002855#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2856 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2857#else
2858 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2859#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002860 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002861 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002862 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2863 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002864 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002865 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002866
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002867 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002868}
2869
Alexander Duyck05abb122010-08-19 13:35:41 +00002870static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002871{
Alexander Duyck05abb122010-08-19 13:35:41 +00002872 struct ixgbe_hw *hw = &adapter->hw;
2873 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002874 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2875 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002876 u32 mrqc = 0, reta = 0;
2877 u32 rxcsum;
2878 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002879 u8 tcs = netdev_get_num_tc(adapter->netdev);
John Fastabend86b4db32011-04-26 07:26:19 +00002880 int maxq = adapter->ring_feature[RING_F_RSS].indices;
2881
2882 if (tcs)
2883 maxq = min(maxq, adapter->num_tx_queues / tcs);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002884
Alexander Duyck05abb122010-08-19 13:35:41 +00002885 /* Fill out hash function seeds */
2886 for (i = 0; i < 10; i++)
2887 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002888
Alexander Duyck05abb122010-08-19 13:35:41 +00002889 /* Fill out redirection table */
2890 for (i = 0, j = 0; i < 128; i++, j++) {
John Fastabend86b4db32011-04-26 07:26:19 +00002891 if (j == maxq)
Alexander Duyck05abb122010-08-19 13:35:41 +00002892 j = 0;
2893 /* reta = 4-byte sliding window of
2894 * 0x00..(indices-1)(indices-1)00..etc. */
2895 reta = (reta << 8) | (j * 0x11);
2896 if ((i & 3) == 3)
2897 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2898 }
2899
2900 /* Disable indicating checksum in descriptor, enables RSS hash */
2901 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2902 rxcsum |= IXGBE_RXCSUM_PCSD;
2903 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2904
John Fastabend8b1c0b22011-05-03 02:26:48 +00002905 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2906 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002907 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002908 } else {
2909 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2910 | IXGBE_FLAG_SRIOV_ENABLED);
2911
2912 switch (mask) {
2913 case (IXGBE_FLAG_RSS_ENABLED):
2914 if (!tcs)
2915 mrqc = IXGBE_MRQC_RSSEN;
2916 else if (tcs <= 4)
2917 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2918 else
2919 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2920 break;
2921 case (IXGBE_FLAG_SRIOV_ENABLED):
2922 mrqc = IXGBE_MRQC_VMDQEN;
2923 break;
2924 default:
2925 break;
2926 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002927 }
2928
Alexander Duyck05abb122010-08-19 13:35:41 +00002929 /* Perform hash on these packet types */
2930 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2931 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2932 | IXGBE_MRQC_RSS_FIELD_IPV6
2933 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2934
2935 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002936}
2937
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002938/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002939 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2940 * @adapter: address of board private structure
2941 * @ring: structure containing ring specific data
2942 **/
2943void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2944 struct ixgbe_ring *ring)
2945{
2946 struct ixgbe_hw *hw = &adapter->hw;
2947 u32 rscctrl;
2948 u8 reg_idx = ring->reg_idx;
2949
2950 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2951 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
2952 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2953}
2954
2955/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002956 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2957 * @adapter: address of board private structure
2958 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002959 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08002960void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002961 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002962{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002963 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002964 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002965 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002966 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002967
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002968 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002969 return;
2970
2971 rx_buf_len = ring->rx_buf_len;
2972 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002973 rscctrl |= IXGBE_RSCCTL_RSCEN;
2974 /*
2975 * we must limit the number of descriptors so that the
2976 * total size of max desc * buf_len is not greater
2977 * than 65535
2978 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002979 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002980#if (MAX_SKB_FRAGS > 16)
2981 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2982#elif (MAX_SKB_FRAGS > 8)
2983 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2984#elif (MAX_SKB_FRAGS > 4)
2985 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2986#else
2987 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2988#endif
2989 } else {
2990 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2991 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2992 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2993 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2994 else
2995 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2996 }
Alexander Duyck73670962010-08-19 13:38:34 +00002997 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002998}
2999
Alexander Duyck9e10e042010-08-19 13:40:06 +00003000/**
3001 * ixgbe_set_uta - Set unicast filter table address
3002 * @adapter: board private structure
3003 *
3004 * The unicast table address is a register array of 32-bit registers.
3005 * The table is meant to be used in a way similar to how the MTA is used
3006 * however due to certain limitations in the hardware it is necessary to
3007 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3008 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3009 **/
3010static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3011{
3012 struct ixgbe_hw *hw = &adapter->hw;
3013 int i;
3014
3015 /* The UTA table only exists on 82599 hardware and newer */
3016 if (hw->mac.type < ixgbe_mac_82599EB)
3017 return;
3018
3019 /* we only need to do this if VMDq is enabled */
3020 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3021 return;
3022
3023 for (i = 0; i < 128; i++)
3024 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3025}
3026
3027#define IXGBE_MAX_RX_DESC_POLL 10
3028static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3029 struct ixgbe_ring *ring)
3030{
3031 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003032 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3033 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003034 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003035
3036 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3037 if (hw->mac.type == ixgbe_mac_82598EB &&
3038 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3039 return;
3040
3041 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003042 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003043 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3044 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3045
3046 if (!wait_loop) {
3047 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3048 "the polling period\n", reg_idx);
3049 }
3050}
3051
Yi Zou2d39d572011-01-06 14:29:56 +00003052void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3053 struct ixgbe_ring *ring)
3054{
3055 struct ixgbe_hw *hw = &adapter->hw;
3056 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3057 u32 rxdctl;
3058 u8 reg_idx = ring->reg_idx;
3059
3060 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3061 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3062
3063 /* write value back with RXDCTL.ENABLE bit cleared */
3064 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3065
3066 if (hw->mac.type == ixgbe_mac_82598EB &&
3067 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3068 return;
3069
3070 /* the hardware may take up to 100us to really disable the rx queue */
3071 do {
3072 udelay(10);
3073 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3074 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3075
3076 if (!wait_loop) {
3077 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3078 "the polling period\n", reg_idx);
3079 }
3080}
3081
Alexander Duyck84418e32010-08-19 13:40:54 +00003082void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3083 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003084{
3085 struct ixgbe_hw *hw = &adapter->hw;
3086 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003087 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003088 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003089
Alexander Duyck9e10e042010-08-19 13:40:06 +00003090 /* disable queue to avoid issues while updating state */
3091 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003092 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003093
Alexander Duyckacd37172010-08-19 13:36:05 +00003094 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3095 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3096 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3097 ring->count * sizeof(union ixgbe_adv_rx_desc));
3098 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3099 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003100 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003101
3102 ixgbe_configure_srrctl(adapter, ring);
3103 ixgbe_configure_rscctl(adapter, ring);
3104
Greg Rosee9f98072011-01-26 01:06:07 +00003105 /* If operating in IOV mode set RLPML for X540 */
3106 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3107 hw->mac.type == ixgbe_mac_X540) {
3108 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3109 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3110 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3111 }
3112
Alexander Duyck9e10e042010-08-19 13:40:06 +00003113 if (hw->mac.type == ixgbe_mac_82598EB) {
3114 /*
3115 * enable cache line friendly hardware writes:
3116 * PTHRESH=32 descriptors (half the internal cache),
3117 * this also removes ugly rx_no_buffer_count increment
3118 * HTHRESH=4 descriptors (to minimize latency on fetch)
3119 * WTHRESH=8 burst writeback up to two cache lines
3120 */
3121 rxdctl &= ~0x3FFFFF;
3122 rxdctl |= 0x080420;
3123 }
3124
3125 /* enable receive descriptor ring */
3126 rxdctl |= IXGBE_RXDCTL_ENABLE;
3127 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3128
3129 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyck7d4987d2011-05-27 05:31:37 +00003130 ixgbe_alloc_rx_buffers(ring, ixgbe_desc_unused(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003131}
3132
Alexander Duyck48654522010-08-19 13:36:27 +00003133static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3134{
3135 struct ixgbe_hw *hw = &adapter->hw;
3136 int p;
3137
3138 /* PSRTYPE must be initialized in non 82598 adapters */
3139 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003140 IXGBE_PSRTYPE_UDPHDR |
3141 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003142 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003143 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003144
3145 if (hw->mac.type == ixgbe_mac_82598EB)
3146 return;
3147
3148 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3149 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3150
3151 for (p = 0; p < adapter->num_rx_pools; p++)
3152 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3153 psrtype);
3154}
3155
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003156static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3157{
3158 struct ixgbe_hw *hw = &adapter->hw;
3159 u32 gcr_ext;
3160 u32 vt_reg_bits;
3161 u32 reg_offset, vf_shift;
3162 u32 vmdctl;
3163
3164 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3165 return;
3166
3167 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3168 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3169 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3170 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3171
3172 vf_shift = adapter->num_vfs % 32;
3173 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3174
3175 /* Enable only the PF's pool for Tx/Rx */
3176 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3177 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3178 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3179 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3180 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3181
3182 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3183 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3184
3185 /*
3186 * Set up VF register offsets for selected VT Mode,
3187 * i.e. 32 or 64 VFs for SR-IOV
3188 */
3189 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3190 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3191 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3192 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3193
3194 /* enable Tx loopback for VF/PF communication */
3195 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003196 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003197 hw->mac.ops.set_mac_anti_spoofing(hw,
3198 (adapter->antispoofing_enabled =
3199 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003200 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003201}
3202
Alexander Duyck477de6e2010-08-19 13:38:11 +00003203static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003204{
Auke Kok9a799d72007-09-15 14:07:45 -07003205 struct ixgbe_hw *hw = &adapter->hw;
3206 struct net_device *netdev = adapter->netdev;
3207 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003208 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003209 struct ixgbe_ring *rx_ring;
3210 int i;
3211 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003212
Auke Kok9a799d72007-09-15 14:07:45 -07003213 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003214 /* On by default */
3215 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3216
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003217 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003218 if (adapter->num_vfs)
3219 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3220
3221 /* Disable packet split due to 82599 erratum #45 */
3222 if (hw->mac.type == ixgbe_mac_82599EB)
3223 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003224
3225 /* Set the RX buffer length according to the mode */
3226 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003227 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003228 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003229 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003230 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003231 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003232 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003233 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3234 }
3235
3236#ifdef IXGBE_FCOE
3237 /* adjust max frame to be able to do baby jumbo for FCoE */
3238 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3239 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3240 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3241
3242#endif /* IXGBE_FCOE */
3243 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3244 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3245 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3246 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3247
3248 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003249 }
3250
Auke Kok9a799d72007-09-15 14:07:45 -07003251 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003252 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3253 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003254 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3255
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003256 /*
3257 * Setup the HW Rx Head and Tail Descriptor Pointers and
3258 * the Base and Length of the Rx Descriptor Ring
3259 */
Auke Kok9a799d72007-09-15 14:07:45 -07003260 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003261 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003262 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003263
Yi Zou6e455b892009-08-06 13:05:44 +00003264 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003265 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003266 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003267 clear_ring_ps_enabled(rx_ring);
3268
3269 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3270 set_ring_rsc_enabled(rx_ring);
3271 else
3272 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003273
Yi Zou63f39bd2009-05-17 12:34:35 +00003274#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003275 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003276 struct ixgbe_ring_feature *f;
3277 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003278 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003279 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003280 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3281 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003282 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003283 } else if (!ring_is_rsc_enabled(rx_ring) &&
3284 !ring_is_ps_enabled(rx_ring)) {
3285 rx_ring->rx_buf_len =
3286 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003287 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003288 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003289#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003290 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003291}
3292
Alexander Duyck73670962010-08-19 13:38:34 +00003293static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3294{
3295 struct ixgbe_hw *hw = &adapter->hw;
3296 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3297
3298 switch (hw->mac.type) {
3299 case ixgbe_mac_82598EB:
3300 /*
3301 * For VMDq support of different descriptor types or
3302 * buffer sizes through the use of multiple SRRCTL
3303 * registers, RDRXCTL.MVMEN must be set to 1
3304 *
3305 * also, the manual doesn't mention it clearly but DCA hints
3306 * will only use queue 0's tags unless this bit is set. Side
3307 * effects of setting this bit are only that SRRCTL must be
3308 * fully programmed [0..15]
3309 */
3310 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3311 break;
3312 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003313 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003314 /* Disable RSC for ACK packets */
3315 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3316 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3317 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3318 /* hardware requires some bits to be set by default */
3319 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3320 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3321 break;
3322 default:
3323 /* We should do nothing since we don't know this hardware */
3324 return;
3325 }
3326
3327 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3328}
3329
Alexander Duyck477de6e2010-08-19 13:38:11 +00003330/**
3331 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3332 * @adapter: board private structure
3333 *
3334 * Configure the Rx unit of the MAC after a reset.
3335 **/
3336static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3337{
3338 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003339 int i;
3340 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003341
3342 /* disable receives while setting up the descriptors */
3343 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3344 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3345
3346 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003347 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003348
Alexander Duyck9e10e042010-08-19 13:40:06 +00003349 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003350 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003351
Alexander Duyck9e10e042010-08-19 13:40:06 +00003352 ixgbe_set_uta(adapter);
3353
Alexander Duyck477de6e2010-08-19 13:38:11 +00003354 /* set_rx_buffer_len must be called before ring initialization */
3355 ixgbe_set_rx_buffer_len(adapter);
3356
3357 /*
3358 * Setup the HW Rx Head and Tail Descriptor Pointers and
3359 * the Base and Length of the Rx Descriptor Ring
3360 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003361 for (i = 0; i < adapter->num_rx_queues; i++)
3362 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003363
Alexander Duyck9e10e042010-08-19 13:40:06 +00003364 /* disable drop enable for 82598 parts */
3365 if (hw->mac.type == ixgbe_mac_82598EB)
3366 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3367
3368 /* enable all receives */
3369 rxctrl |= IXGBE_RXCTRL_RXEN;
3370 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003371}
3372
Auke Kok9a799d72007-09-15 14:07:45 -07003373static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3374{
3375 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003376 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003377 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003378
3379 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003380 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003381 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003382}
3383
3384static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3385{
3386 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003387 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003388 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003389
Auke Kok9a799d72007-09-15 14:07:45 -07003390 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003391 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003392 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003393}
3394
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003395/**
3396 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3397 * @adapter: driver data
3398 */
3399static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3400{
3401 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003402 u32 vlnctrl;
3403
3404 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3405 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3406 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3407}
3408
3409/**
3410 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3411 * @adapter: driver data
3412 */
3413static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3414{
3415 struct ixgbe_hw *hw = &adapter->hw;
3416 u32 vlnctrl;
3417
3418 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3419 vlnctrl |= IXGBE_VLNCTRL_VFE;
3420 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3421 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3422}
3423
3424/**
3425 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3426 * @adapter: driver data
3427 */
3428static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3429{
3430 struct ixgbe_hw *hw = &adapter->hw;
3431 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003432 int i, j;
3433
3434 switch (hw->mac.type) {
3435 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003436 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3437 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003438 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3439 break;
3440 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003441 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003442 for (i = 0; i < adapter->num_rx_queues; i++) {
3443 j = adapter->rx_ring[i]->reg_idx;
3444 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3445 vlnctrl &= ~IXGBE_RXDCTL_VME;
3446 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3447 }
3448 break;
3449 default:
3450 break;
3451 }
3452}
3453
3454/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003455 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003456 * @adapter: driver data
3457 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003458static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003459{
3460 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003461 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003462 int i, j;
3463
3464 switch (hw->mac.type) {
3465 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003466 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3467 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003468 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3469 break;
3470 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003471 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003472 for (i = 0; i < adapter->num_rx_queues; i++) {
3473 j = adapter->rx_ring[i]->reg_idx;
3474 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3475 vlnctrl |= IXGBE_RXDCTL_VME;
3476 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3477 }
3478 break;
3479 default:
3480 break;
3481 }
3482}
3483
Auke Kok9a799d72007-09-15 14:07:45 -07003484static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3485{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003486 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003487
Jesse Grossf62bbb52010-10-20 13:56:10 +00003488 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3489
3490 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3491 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003492}
3493
3494/**
Alexander Duyck28500622010-06-15 09:25:48 +00003495 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3496 * @netdev: network interface device structure
3497 *
3498 * Writes unicast address list to the RAR table.
3499 * Returns: -ENOMEM on failure/insufficient address space
3500 * 0 on no addresses written
3501 * X on writing X addresses to the RAR table
3502 **/
3503static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3504{
3505 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3506 struct ixgbe_hw *hw = &adapter->hw;
3507 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003508 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003509 int count = 0;
3510
3511 /* return ENOMEM indicating insufficient memory for addresses */
3512 if (netdev_uc_count(netdev) > rar_entries)
3513 return -ENOMEM;
3514
3515 if (!netdev_uc_empty(netdev) && rar_entries) {
3516 struct netdev_hw_addr *ha;
3517 /* return error if we do not support writing to RAR table */
3518 if (!hw->mac.ops.set_rar)
3519 return -ENOMEM;
3520
3521 netdev_for_each_uc_addr(ha, netdev) {
3522 if (!rar_entries)
3523 break;
3524 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3525 vfn, IXGBE_RAH_AV);
3526 count++;
3527 }
3528 }
3529 /* write the addresses in reverse order to avoid write combining */
3530 for (; rar_entries > 0 ; rar_entries--)
3531 hw->mac.ops.clear_rar(hw, rar_entries);
3532
3533 return count;
3534}
3535
3536/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003537 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003538 * @netdev: network interface device structure
3539 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003540 * The set_rx_method entry point is called whenever the unicast/multicast
3541 * address list or the network interface flags are updated. This routine is
3542 * responsible for configuring the hardware for proper unicast, multicast and
3543 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003544 **/
Greg Rose7f870472010-01-09 02:25:29 +00003545void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003546{
3547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3548 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003549 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3550 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003551
3552 /* Check for Promiscuous and All Multicast modes */
3553
3554 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3555
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003556 /* set all bits that we expect to always be set */
3557 fctrl |= IXGBE_FCTRL_BAM;
3558 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3559 fctrl |= IXGBE_FCTRL_PMCF;
3560
Alexander Duyck28500622010-06-15 09:25:48 +00003561 /* clear the bits we are changing the status of */
3562 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3563
Auke Kok9a799d72007-09-15 14:07:45 -07003564 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003565 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003566 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003567 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003568 /* don't hardware filter vlans in promisc mode */
3569 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003570 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003571 if (netdev->flags & IFF_ALLMULTI) {
3572 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003573 vmolr |= IXGBE_VMOLR_MPE;
3574 } else {
3575 /*
3576 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003577 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003578 * that we can at least receive multicast traffic
3579 */
3580 hw->mac.ops.update_mc_addr_list(hw, netdev);
3581 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003582 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003583 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003584 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003585 /*
3586 * Write addresses to available RAR registers, if there is not
3587 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003588 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003589 */
3590 count = ixgbe_write_uc_addr_list(netdev);
3591 if (count < 0) {
3592 fctrl |= IXGBE_FCTRL_UPE;
3593 vmolr |= IXGBE_VMOLR_ROPE;
3594 }
3595 }
3596
3597 if (adapter->num_vfs) {
3598 ixgbe_restore_vf_multicasts(adapter);
3599 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3600 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3601 IXGBE_VMOLR_ROPE);
3602 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003603 }
3604
3605 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003606
3607 if (netdev->features & NETIF_F_HW_VLAN_RX)
3608 ixgbe_vlan_strip_enable(adapter);
3609 else
3610 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003611}
3612
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003613static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3614{
3615 int q_idx;
3616 struct ixgbe_q_vector *q_vector;
3617 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3618
3619 /* legacy and MSI only use one vector */
3620 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3621 q_vectors = 1;
3622
3623 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003624 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003625 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003626 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003627 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3628 if (!q_vector->rxr_count || !q_vector->txr_count) {
3629 if (q_vector->txr_count == 1)
3630 napi->poll = &ixgbe_clean_txonly;
3631 else if (q_vector->rxr_count == 1)
3632 napi->poll = &ixgbe_clean_rxonly;
3633 }
3634 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003635
3636 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003637 }
3638}
3639
3640static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3641{
3642 int q_idx;
3643 struct ixgbe_q_vector *q_vector;
3644 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3645
3646 /* legacy and MSI only use one vector */
3647 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3648 q_vectors = 1;
3649
3650 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003651 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003652 napi_disable(&q_vector->napi);
3653 }
3654}
3655
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003656#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003657/*
3658 * ixgbe_configure_dcb - Configure DCB hardware
3659 * @adapter: ixgbe adapter struct
3660 *
3661 * This is called by the driver on open to configure the DCB hardware.
3662 * This is also called by the gennetlink interface when reconfiguring
3663 * the DCB state.
3664 */
3665static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3666{
3667 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003668 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003669
Alexander Duyck67ebd792010-08-19 13:34:04 +00003670 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3671 if (hw->mac.type == ixgbe_mac_82598EB)
3672 netif_set_gso_max_size(adapter->netdev, 65536);
3673 return;
3674 }
3675
3676 if (hw->mac.type == ixgbe_mac_82598EB)
3677 netif_set_gso_max_size(adapter->netdev, 32768);
3678
Alexander Duyck2f90b862008-11-20 20:52:10 -08003679
Alexander Duyck2f90b862008-11-20 20:52:10 -08003680 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003681 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003682
Alexander Duyck2f90b862008-11-20 20:52:10 -08003683 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003684
3685 /* reconfigure the hardware */
John Fastabend6f70f6a2011-04-26 07:26:25 +00003686 if (adapter->dcbx_cap & DCB_CAP_DCBX_VER_CEE) {
John Fastabendc27931d2011-02-23 05:58:25 +00003687#ifdef CONFIG_FCOE
3688 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3689 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3690#endif
3691 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3692 DCB_TX_CONFIG);
3693 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3694 DCB_RX_CONFIG);
3695 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3696 } else {
3697 struct net_device *dev = adapter->netdev;
3698
3699 if (adapter->ixgbe_ieee_ets)
3700 dev->dcbnl_ops->ieee_setets(dev,
3701 adapter->ixgbe_ieee_ets);
3702 if (adapter->ixgbe_ieee_pfc)
3703 dev->dcbnl_ops->ieee_setpfc(dev,
3704 adapter->ixgbe_ieee_pfc);
3705 }
John Fastabend8187cd42011-02-23 05:58:08 +00003706
3707 /* Enable RSS Hash per TC */
3708 if (hw->mac.type != ixgbe_mac_82598EB) {
3709 int i;
3710 u32 reg = 0;
3711
3712 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3713 u8 msb = 0;
3714 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3715
3716 while (cnt >>= 1)
3717 msb++;
3718
3719 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3720 }
3721 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3722 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003723}
3724
3725#endif
John Fastabend80605c652011-05-02 12:34:10 +00003726
3727static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3728{
3729 int hdrm = 0;
3730 int num_tc = netdev_get_num_tc(adapter->netdev);
3731 struct ixgbe_hw *hw = &adapter->hw;
3732
3733 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3734 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3735 hdrm = 64 << adapter->fdir_pballoc;
3736
3737 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3738}
3739
Alexander Duycke4911d52011-05-11 07:18:52 +00003740static void ixgbe_fdir_filter_restore(struct ixgbe_adapter *adapter)
3741{
3742 struct ixgbe_hw *hw = &adapter->hw;
3743 struct hlist_node *node, *node2;
3744 struct ixgbe_fdir_filter *filter;
3745
3746 spin_lock(&adapter->fdir_perfect_lock);
3747
3748 if (!hlist_empty(&adapter->fdir_filter_list))
3749 ixgbe_fdir_set_input_mask_82599(hw, &adapter->fdir_mask);
3750
3751 hlist_for_each_entry_safe(filter, node, node2,
3752 &adapter->fdir_filter_list, fdir_node) {
3753 ixgbe_fdir_write_perfect_filter_82599(hw,
Alexander Duyck1f4d5182011-05-14 01:16:02 +00003754 &filter->filter,
3755 filter->sw_idx,
3756 (filter->action == IXGBE_FDIR_DROP_QUEUE) ?
3757 IXGBE_FDIR_DROP_QUEUE :
3758 adapter->rx_ring[filter->action]->reg_idx);
Alexander Duycke4911d52011-05-11 07:18:52 +00003759 }
3760
3761 spin_unlock(&adapter->fdir_perfect_lock);
3762}
3763
Auke Kok9a799d72007-09-15 14:07:45 -07003764static void ixgbe_configure(struct ixgbe_adapter *adapter)
3765{
3766 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003767 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003768 int i;
3769
John Fastabend80605c652011-05-02 12:34:10 +00003770 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003771#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003772 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003773#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003774
Jesse Grossf62bbb52010-10-20 13:56:10 +00003775 ixgbe_set_rx_mode(netdev);
3776 ixgbe_restore_vlan(adapter);
3777
Yi Zoueacd73f2009-05-13 13:11:06 +00003778#ifdef IXGBE_FCOE
3779 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3780 ixgbe_configure_fcoe(adapter);
3781
3782#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003783 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3784 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003785 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003786 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003787 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
Alexander Duycke4911d52011-05-11 07:18:52 +00003788 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3789 ixgbe_init_fdir_perfect_82599(&adapter->hw,
3790 adapter->fdir_pballoc);
3791 ixgbe_fdir_filter_restore(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003792 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003793 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003794
Auke Kok9a799d72007-09-15 14:07:45 -07003795 ixgbe_configure_tx(adapter);
3796 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003797}
3798
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003799static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3800{
3801 switch (hw->phy.type) {
3802 case ixgbe_phy_sfp_avago:
3803 case ixgbe_phy_sfp_ftl:
3804 case ixgbe_phy_sfp_intel:
3805 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003806 case ixgbe_phy_sfp_passive_tyco:
3807 case ixgbe_phy_sfp_passive_unknown:
3808 case ixgbe_phy_sfp_active_unknown:
3809 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003810 return true;
3811 default:
3812 return false;
3813 }
3814}
3815
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003816/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003817 * ixgbe_sfp_link_config - set up SFP+ link
3818 * @adapter: pointer to private adapter struct
3819 **/
3820static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3821{
Alexander Duyck70864002011-04-27 09:13:56 +00003822 /*
3823 * We are assuming the worst case scenerio here, and that
3824 * is that an SFP was inserted/removed after the reset
3825 * but before SFP detection was enabled. As such the best
3826 * solution is to just start searching as soon as we start
3827 */
3828 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3829 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003830
Alexander Duyck70864002011-04-27 09:13:56 +00003831 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003832}
3833
3834/**
3835 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003836 * @hw: pointer to private hardware struct
3837 *
3838 * Returns 0 on success, negative on failure
3839 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003840static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003841{
3842 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003843 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003844 u32 ret = IXGBE_ERR_LINK_SETUP;
3845
3846 if (hw->mac.ops.check_link)
3847 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3848
3849 if (ret)
3850 goto link_cfg_out;
3851
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003852 autoneg = hw->phy.autoneg_advertised;
3853 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003854 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3855 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003856 if (ret)
3857 goto link_cfg_out;
3858
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003859 if (hw->mac.ops.setup_link)
3860 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003861link_cfg_out:
3862 return ret;
3863}
3864
Alexander Duycka34bcff2010-08-19 13:39:20 +00003865static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003866{
Auke Kok9a799d72007-09-15 14:07:45 -07003867 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003868 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003869
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003870 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003871 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3872 IXGBE_GPIE_OCD;
3873 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003874 /*
3875 * use EIAM to auto-mask when MSI-X interrupt is asserted
3876 * this saves a register write for every interrupt
3877 */
3878 switch (hw->mac.type) {
3879 case ixgbe_mac_82598EB:
3880 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3881 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003882 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003883 case ixgbe_mac_X540:
3884 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003885 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3886 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3887 break;
3888 }
3889 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003890 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3891 * specifically only auto mask tx and rx interrupts */
3892 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003893 }
3894
Alexander Duycka34bcff2010-08-19 13:39:20 +00003895 /* XXX: to interrupt immediately for EICS writes, enable this */
3896 /* gpie |= IXGBE_GPIE_EIMEN; */
3897
3898 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3899 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3900 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003901 }
3902
Alexander Duycka34bcff2010-08-19 13:39:20 +00003903 /* Enable fan failure interrupt */
3904 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003905 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003906
Don Skidmore2698b202011-04-13 07:01:52 +00003907 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003908 gpie |= IXGBE_SDP1_GPIEN;
3909 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003910 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003911
3912 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3913}
3914
3915static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3916{
3917 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003918 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003919 u32 ctrl_ext;
3920
3921 ixgbe_get_hw_control(adapter);
3922 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003923
Auke Kok9a799d72007-09-15 14:07:45 -07003924 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3925 ixgbe_configure_msix(adapter);
3926 else
3927 ixgbe_configure_msi_and_legacy(adapter);
3928
Don Skidmorec6ecf392010-12-03 03:31:51 +00003929 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3930 if (hw->mac.ops.enable_tx_laser &&
3931 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003932 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003933 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003934 hw->mac.ops.enable_tx_laser(hw);
3935
Auke Kok9a799d72007-09-15 14:07:45 -07003936 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003937 ixgbe_napi_enable_all(adapter);
3938
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003939 if (ixgbe_is_sfp(hw)) {
3940 ixgbe_sfp_link_config(adapter);
3941 } else {
3942 err = ixgbe_non_sfp_link_config(hw);
3943 if (err)
3944 e_err(probe, "link_config FAILED %d\n", err);
3945 }
3946
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003947 /* clear any pending interrupts, may auto mask */
3948 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003949 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003950
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003951 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003952 * If this adapter has a fan, check to see if we had a failure
3953 * before we enabled the interrupt.
3954 */
3955 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3956 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3957 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003958 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003959 }
3960
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003961 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003962 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003963
Auke Kok9a799d72007-09-15 14:07:45 -07003964 /* bring the link up in the watchdog, this could race with our first
3965 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003966 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3967 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003968 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003969
3970 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3971 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3972 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3973 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3974
Auke Kok9a799d72007-09-15 14:07:45 -07003975 return 0;
3976}
3977
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003978void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3979{
3980 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003981 /* put off any impending NetWatchDogTimeout */
3982 adapter->netdev->trans_start = jiffies;
3983
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003984 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003985 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003986 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003987 /*
3988 * If SR-IOV enabled then wait a bit before bringing the adapter
3989 * back up to give the VFs time to respond to the reset. The
3990 * two second wait is based upon the watchdog timer cycle in
3991 * the VF driver.
3992 */
3993 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3994 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003995 ixgbe_up(adapter);
3996 clear_bit(__IXGBE_RESETTING, &adapter->state);
3997}
3998
Auke Kok9a799d72007-09-15 14:07:45 -07003999int ixgbe_up(struct ixgbe_adapter *adapter)
4000{
4001 /* hardware has been reset, we need to reload some things */
4002 ixgbe_configure(adapter);
4003
4004 return ixgbe_up_complete(adapter);
4005}
4006
4007void ixgbe_reset(struct ixgbe_adapter *adapter)
4008{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004009 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004010 int err;
4011
Alexander Duyck70864002011-04-27 09:13:56 +00004012 /* lock SFP init bit to prevent race conditions with the watchdog */
4013 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4014 usleep_range(1000, 2000);
4015
4016 /* clear all SFP and link config related flags while holding SFP_INIT */
4017 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4018 IXGBE_FLAG2_SFP_NEEDS_RESET);
4019 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4020
Don Skidmore8ca783a2009-05-26 20:40:47 -07004021 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004022 switch (err) {
4023 case 0:
4024 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004025 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004026 break;
4027 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004028 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004029 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004030 case IXGBE_ERR_EEPROM_VERSION:
4031 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004032 e_dev_warn("This device is a pre-production adapter/LOM. "
4033 "Please be aware there may be issuesassociated with "
4034 "your hardware. If you are experiencing problems "
4035 "please contact your Intel or hardware "
4036 "representative who provided you with this "
4037 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004038 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004039 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004040 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004041 }
Auke Kok9a799d72007-09-15 14:07:45 -07004042
Alexander Duyck70864002011-04-27 09:13:56 +00004043 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4044
Auke Kok9a799d72007-09-15 14:07:45 -07004045 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004046 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4047 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004048}
4049
Auke Kok9a799d72007-09-15 14:07:45 -07004050/**
4051 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004052 * @rx_ring: ring to free buffers from
4053 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004054static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004055{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004056 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004057 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004058 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004059
Alexander Duyck84418e32010-08-19 13:40:54 +00004060 /* ring already cleared, nothing to do */
4061 if (!rx_ring->rx_buffer_info)
4062 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004063
Alexander Duyck84418e32010-08-19 13:40:54 +00004064 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004065 for (i = 0; i < rx_ring->count; i++) {
4066 struct ixgbe_rx_buffer *rx_buffer_info;
4067
4068 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4069 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004070 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004071 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004072 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004073 rx_buffer_info->dma = 0;
4074 }
4075 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004076 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004077 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004078 do {
4079 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004080 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004081 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004082 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004083 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004084 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004085 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004086 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004087 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004088 skb = skb->prev;
4089 dev_kfree_skb(this);
4090 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004091 }
4092 if (!rx_buffer_info->page)
4093 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004094 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004095 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004096 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004097 rx_buffer_info->page_dma = 0;
4098 }
Auke Kok9a799d72007-09-15 14:07:45 -07004099 put_page(rx_buffer_info->page);
4100 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004101 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004102 }
4103
4104 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4105 memset(rx_ring->rx_buffer_info, 0, size);
4106
4107 /* Zero out the descriptor ring */
4108 memset(rx_ring->desc, 0, rx_ring->size);
4109
4110 rx_ring->next_to_clean = 0;
4111 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004112}
4113
4114/**
4115 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004116 * @tx_ring: ring to be cleaned
4117 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004118static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004119{
4120 struct ixgbe_tx_buffer *tx_buffer_info;
4121 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004122 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004123
Alexander Duyck84418e32010-08-19 13:40:54 +00004124 /* ring already cleared, nothing to do */
4125 if (!tx_ring->tx_buffer_info)
4126 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004127
Alexander Duyck84418e32010-08-19 13:40:54 +00004128 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004129 for (i = 0; i < tx_ring->count; i++) {
4130 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004131 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004132 }
4133
4134 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4135 memset(tx_ring->tx_buffer_info, 0, size);
4136
4137 /* Zero out the descriptor ring */
4138 memset(tx_ring->desc, 0, tx_ring->size);
4139
4140 tx_ring->next_to_use = 0;
4141 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004142}
4143
4144/**
Auke Kok9a799d72007-09-15 14:07:45 -07004145 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4146 * @adapter: board private structure
4147 **/
4148static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4149{
4150 int i;
4151
4152 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004153 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004154}
4155
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004156/**
4157 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4158 * @adapter: board private structure
4159 **/
4160static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4161{
4162 int i;
4163
4164 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004165 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004166}
4167
Alexander Duycke4911d52011-05-11 07:18:52 +00004168static void ixgbe_fdir_filter_exit(struct ixgbe_adapter *adapter)
4169{
4170 struct hlist_node *node, *node2;
4171 struct ixgbe_fdir_filter *filter;
4172
4173 spin_lock(&adapter->fdir_perfect_lock);
4174
4175 hlist_for_each_entry_safe(filter, node, node2,
4176 &adapter->fdir_filter_list, fdir_node) {
4177 hlist_del(&filter->fdir_node);
4178 kfree(filter);
4179 }
4180 adapter->fdir_filter_count = 0;
4181
4182 spin_unlock(&adapter->fdir_perfect_lock);
4183}
4184
Auke Kok9a799d72007-09-15 14:07:45 -07004185void ixgbe_down(struct ixgbe_adapter *adapter)
4186{
4187 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004188 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004189 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004190 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004191 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004192
4193 /* signal that we are down to the interrupt handler */
4194 set_bit(__IXGBE_DOWN, &adapter->state);
4195
4196 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004197 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4198 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004199
Yi Zou2d39d572011-01-06 14:29:56 +00004200 /* disable all enabled rx queues */
4201 for (i = 0; i < adapter->num_rx_queues; i++)
4202 /* this call also flushes the previous write */
4203 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4204
Don Skidmore032b4322011-03-18 09:32:53 +00004205 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004206
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004207 netif_tx_stop_all_queues(netdev);
4208
Alexander Duyck70864002011-04-27 09:13:56 +00004209 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004210 netif_carrier_off(netdev);
4211 netif_tx_disable(netdev);
4212
4213 ixgbe_irq_disable(adapter);
4214
4215 ixgbe_napi_disable_all(adapter);
4216
Alexander Duyckd034acf2011-04-27 09:25:34 +00004217 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4218 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004219 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4220
4221 del_timer_sync(&adapter->service_timer);
4222
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004223 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004224 if (adapter->num_vfs) {
4225 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004226 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004227
Auke Kok9a799d72007-09-15 14:07:45 -07004228 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004229 ixgbe_disable_tx_rx(adapter);
4230
4231 /* Mark all the VFs as inactive */
4232 for (i = 0 ; i < adapter->num_vfs; i++)
4233 adapter->vfinfo[i].clear_to_send = 0;
4234 }
4235
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004236 /* Cleanup the affinity_hint CPU mask memory and callback */
4237 for (i = 0; i < num_q_vectors; i++) {
4238 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4239 /* clear the affinity_mask in the IRQ descriptor */
4240 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4241 /* release the CPU mask memory */
4242 free_cpumask_var(q_vector->affinity_mask);
4243 }
4244
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004245 /* disable transmits in the hardware now that interrupts are off */
4246 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004247 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004248 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004249 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004250
4251 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004252 switch (hw->mac.type) {
4253 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004254 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004255 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004256 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4257 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004258 break;
4259 default:
4260 break;
4261 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004262
Paul Larson6f4a0e42008-06-24 17:00:56 -07004263 if (!pci_channel_offline(adapter->pdev))
4264 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004265
4266 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4267 if (hw->mac.ops.disable_tx_laser &&
4268 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004269 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004270 (hw->mac.type == ixgbe_mac_82599EB))))
4271 hw->mac.ops.disable_tx_laser(hw);
4272
Auke Kok9a799d72007-09-15 14:07:45 -07004273 ixgbe_clean_all_tx_rings(adapter);
4274 ixgbe_clean_all_rx_rings(adapter);
4275
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004276#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004277 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004278 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004279#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004280}
4281
Auke Kok9a799d72007-09-15 14:07:45 -07004282/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004283 * ixgbe_poll - NAPI Rx polling callback
4284 * @napi: structure for representing this polling device
4285 * @budget: how many packets driver is allowed to clean
4286 *
4287 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004288 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004289static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004290{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004291 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004292 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004293 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004294 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004295
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004296#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004297 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4298 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004299#endif
4300
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004301 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4302 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004303
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004304 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004305 work_done = budget;
4306
David S. Miller53e52c72008-01-07 21:06:12 -08004307 /* If budget not fully consumed, exit the polling mode */
4308 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004309 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004310 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004311 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004312 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004313 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004314 }
Auke Kok9a799d72007-09-15 14:07:45 -07004315 return work_done;
4316}
4317
4318/**
4319 * ixgbe_tx_timeout - Respond to a Tx Hang
4320 * @netdev: network interface device structure
4321 **/
4322static void ixgbe_tx_timeout(struct net_device *netdev)
4323{
4324 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4325
4326 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004327 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004328}
4329
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004330/**
4331 * ixgbe_set_rss_queues: Allocate queues for RSS
4332 * @adapter: board private structure to initialize
4333 *
4334 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4335 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4336 *
4337 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004338static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4339{
4340 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004341 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004342
4343 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004344 f->mask = 0xF;
4345 adapter->num_rx_queues = f->indices;
4346 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004347 ret = true;
4348 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004349 ret = false;
4350 }
4351
4352 return ret;
4353}
4354
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004355/**
4356 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4357 * @adapter: board private structure to initialize
4358 *
4359 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4360 * to the original CPU that initiated the Tx session. This runs in addition
4361 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4362 * Rx load across CPUs using RSS.
4363 *
4364 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004365static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004366{
4367 bool ret = false;
4368 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4369
4370 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4371 f_fdir->mask = 0;
4372
4373 /* Flow Director must have RSS enabled */
Alexander Duyck03ecf912011-05-20 07:36:17 +00004374 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4375 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004376 adapter->num_tx_queues = f_fdir->indices;
4377 adapter->num_rx_queues = f_fdir->indices;
4378 ret = true;
4379 } else {
4380 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004381 }
4382 return ret;
4383}
4384
Yi Zou0331a832009-05-17 12:33:52 +00004385#ifdef IXGBE_FCOE
4386/**
4387 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4388 * @adapter: board private structure to initialize
4389 *
4390 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4391 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4392 * rx queues out of the max number of rx queues, instead, it is used as the
4393 * index of the first rx queue used by FCoE.
4394 *
4395 **/
4396static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4397{
Yi Zou0331a832009-05-17 12:33:52 +00004398 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4399
John Fastabende5b64632011-03-08 03:44:52 +00004400 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4401 return false;
4402
John Fastabende901acd2011-04-26 07:26:08 +00004403 f->indices = min((int)num_online_cpus(), f->indices);
John Fastabende5b64632011-03-08 03:44:52 +00004404
John Fastabende901acd2011-04-26 07:26:08 +00004405 adapter->num_rx_queues = 1;
4406 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004407
John Fastabende901acd2011-04-26 07:26:08 +00004408 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4409 e_info(probe, "FCoE enabled with RSS\n");
Alexander Duyck03ecf912011-05-20 07:36:17 +00004410 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
John Fastabende901acd2011-04-26 07:26:08 +00004411 ixgbe_set_fdir_queues(adapter);
4412 else
4413 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004414 }
Alexander Duyck03ecf912011-05-20 07:36:17 +00004415
John Fastabende901acd2011-04-26 07:26:08 +00004416 /* adding FCoE rx rings to the end */
4417 f->mask = adapter->num_rx_queues;
4418 adapter->num_rx_queues += f->indices;
4419 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004420
John Fastabende5b64632011-03-08 03:44:52 +00004421 return true;
4422}
4423#endif /* IXGBE_FCOE */
4424
John Fastabende901acd2011-04-26 07:26:08 +00004425/* Artificial max queue cap per traffic class in DCB mode */
4426#define DCB_QUEUE_CAP 8
4427
John Fastabende5b64632011-03-08 03:44:52 +00004428#ifdef CONFIG_IXGBE_DCB
4429static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4430{
John Fastabende901acd2011-04-26 07:26:08 +00004431 int per_tc_q, q, i, offset = 0;
4432 struct net_device *dev = adapter->netdev;
4433 int tcs = netdev_get_num_tc(dev);
John Fastabende5b64632011-03-08 03:44:52 +00004434
John Fastabende901acd2011-04-26 07:26:08 +00004435 if (!tcs)
4436 return false;
John Fastabende5b64632011-03-08 03:44:52 +00004437
John Fastabende901acd2011-04-26 07:26:08 +00004438 /* Map queue offset and counts onto allocated tx queues */
4439 per_tc_q = min(dev->num_tx_queues / tcs, (unsigned int)DCB_QUEUE_CAP);
4440 q = min((int)num_online_cpus(), per_tc_q);
John Fastabend8b1c0b22011-05-03 02:26:48 +00004441
John Fastabend8b1c0b22011-05-03 02:26:48 +00004442 for (i = 0; i < tcs; i++) {
John Fastabende901acd2011-04-26 07:26:08 +00004443 netdev_set_prio_tc_map(dev, i, i);
4444 netdev_set_tc_queue(dev, i, q, offset);
4445 offset += q;
John Fastabende5b64632011-03-08 03:44:52 +00004446 }
4447
John Fastabende901acd2011-04-26 07:26:08 +00004448 adapter->num_tx_queues = q * tcs;
4449 adapter->num_rx_queues = q * tcs;
John Fastabende5b64632011-03-08 03:44:52 +00004450
4451#ifdef IXGBE_FCOE
John Fastabende901acd2011-04-26 07:26:08 +00004452 /* FCoE enabled queues require special configuration indexed
4453 * by feature specific indices and mask. Here we map FCoE
4454 * indices onto the DCB queue pairs allowing FCoE to own
4455 * configuration later.
John Fastabende5b64632011-03-08 03:44:52 +00004456 */
John Fastabende901acd2011-04-26 07:26:08 +00004457 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
4458 int tc;
4459 struct ixgbe_ring_feature *f =
4460 &adapter->ring_feature[RING_F_FCOE];
4461
4462 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4463 f->indices = dev->tc_to_txq[tc].count;
4464 f->mask = dev->tc_to_txq[tc].offset;
4465 }
John Fastabende5b64632011-03-08 03:44:52 +00004466#endif
4467
John Fastabende901acd2011-04-26 07:26:08 +00004468 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004469}
John Fastabende5b64632011-03-08 03:44:52 +00004470#endif
Yi Zou0331a832009-05-17 12:33:52 +00004471
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004472/**
4473 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4474 * @adapter: board private structure to initialize
4475 *
4476 * IOV doesn't actually use anything, so just NAK the
4477 * request for now and let the other queue routines
4478 * figure out what to do.
4479 */
4480static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4481{
4482 return false;
4483}
4484
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004485/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004486 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004487 * @adapter: board private structure to initialize
4488 *
4489 * This is the top level queue allocation routine. The order here is very
4490 * important, starting with the "most" number of features turned on at once,
4491 * and ending with the smallest set of features. This way large combinations
4492 * can be allocated if they're turned on, and smaller combinations are the
4493 * fallthrough conditions.
4494 *
4495 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004496static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004497{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004498 /* Start with base case */
4499 adapter->num_rx_queues = 1;
4500 adapter->num_tx_queues = 1;
4501 adapter->num_rx_pools = adapter->num_rx_queues;
4502 adapter->num_rx_queues_per_pool = 1;
4503
4504 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004505 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004506
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004507#ifdef CONFIG_IXGBE_DCB
4508 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004509 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004510
4511#endif
John Fastabende5b64632011-03-08 03:44:52 +00004512#ifdef IXGBE_FCOE
4513 if (ixgbe_set_fcoe_queues(adapter))
4514 goto done;
4515
4516#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004517 if (ixgbe_set_fdir_queues(adapter))
4518 goto done;
4519
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004520 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004521 goto done;
4522
4523 /* fallback to base case */
4524 adapter->num_rx_queues = 1;
4525 adapter->num_tx_queues = 1;
4526
4527done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004528 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004529 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004530 return netif_set_real_num_rx_queues(adapter->netdev,
4531 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004532}
4533
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004534static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004535 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004536{
4537 int err, vector_threshold;
4538
4539 /* We'll want at least 3 (vector_threshold):
4540 * 1) TxQ[0] Cleanup
4541 * 2) RxQ[0] Cleanup
4542 * 3) Other (Link Status Change, etc.)
4543 * 4) TCP Timer (optional)
4544 */
4545 vector_threshold = MIN_MSIX_COUNT;
4546
4547 /* The more we get, the more we will assign to Tx/Rx Cleanup
4548 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4549 * Right now, we simply care about how many we'll get; we'll
4550 * set them up later while requesting irq's.
4551 */
4552 while (vectors >= vector_threshold) {
4553 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004554 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004555 if (!err) /* Success in acquiring all requested vectors. */
4556 break;
4557 else if (err < 0)
4558 vectors = 0; /* Nasty failure, quit now */
4559 else /* err == number of vectors we should try again with */
4560 vectors = err;
4561 }
4562
4563 if (vectors < vector_threshold) {
4564 /* Can't allocate enough MSI-X interrupts? Oh well.
4565 * This just means we'll go with either a single MSI
4566 * vector or fall back to legacy interrupts.
4567 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004568 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4569 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004570 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4571 kfree(adapter->msix_entries);
4572 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004573 } else {
4574 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004575 /*
4576 * Adjust for only the vectors we'll use, which is minimum
4577 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4578 * vectors we were allocated.
4579 */
4580 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004581 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004582 }
4583}
4584
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004585/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004586 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004587 * @adapter: board private structure to initialize
4588 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004589 * Cache the descriptor ring offsets for RSS to the assigned rings.
4590 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004591 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004592static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004593{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004594 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004595
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004596 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4597 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004598
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004599 for (i = 0; i < adapter->num_rx_queues; i++)
4600 adapter->rx_ring[i]->reg_idx = i;
4601 for (i = 0; i < adapter->num_tx_queues; i++)
4602 adapter->tx_ring[i]->reg_idx = i;
4603
4604 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004605}
4606
4607#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004608
4609/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004610static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4611 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004612{
4613 struct net_device *dev = adapter->netdev;
4614 struct ixgbe_hw *hw = &adapter->hw;
4615 u8 num_tcs = netdev_get_num_tc(dev);
4616
4617 *tx = 0;
4618 *rx = 0;
4619
4620 switch (hw->mac.type) {
4621 case ixgbe_mac_82598EB:
John Fastabendaba70d52011-04-26 07:26:14 +00004622 *tx = tc << 2;
4623 *rx = tc << 3;
John Fastabende5b64632011-03-08 03:44:52 +00004624 break;
4625 case ixgbe_mac_82599EB:
4626 case ixgbe_mac_X540:
4627 if (num_tcs == 8) {
4628 if (tc < 3) {
4629 *tx = tc << 5;
4630 *rx = tc << 4;
4631 } else if (tc < 5) {
4632 *tx = ((tc + 2) << 4);
4633 *rx = tc << 4;
4634 } else if (tc < num_tcs) {
4635 *tx = ((tc + 8) << 3);
4636 *rx = tc << 4;
4637 }
4638 } else if (num_tcs == 4) {
4639 *rx = tc << 5;
4640 switch (tc) {
4641 case 0:
4642 *tx = 0;
4643 break;
4644 case 1:
4645 *tx = 64;
4646 break;
4647 case 2:
4648 *tx = 96;
4649 break;
4650 case 3:
4651 *tx = 112;
4652 break;
4653 default:
4654 break;
4655 }
4656 }
4657 break;
4658 default:
4659 break;
4660 }
4661}
4662
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004663/**
4664 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4665 * @adapter: board private structure to initialize
4666 *
4667 * Cache the descriptor ring offsets for DCB to the assigned rings.
4668 *
4669 **/
4670static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4671{
John Fastabende5b64632011-03-08 03:44:52 +00004672 struct net_device *dev = adapter->netdev;
4673 int i, j, k;
4674 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004675
John Fastabend8b1c0b22011-05-03 02:26:48 +00004676 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004677 return false;
4678
John Fastabende5b64632011-03-08 03:44:52 +00004679 for (i = 0, k = 0; i < num_tcs; i++) {
4680 unsigned int tx_s, rx_s;
4681 u16 count = dev->tc_to_txq[i].count;
4682
4683 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4684 for (j = 0; j < count; j++, k++) {
4685 adapter->tx_ring[k]->reg_idx = tx_s + j;
4686 adapter->rx_ring[k]->reg_idx = rx_s + j;
4687 adapter->tx_ring[k]->dcb_tc = i;
4688 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004689 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004690 }
John Fastabende5b64632011-03-08 03:44:52 +00004691
4692 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004693}
4694#endif
4695
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004696/**
4697 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4698 * @adapter: board private structure to initialize
4699 *
4700 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4701 *
4702 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004703static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004704{
4705 int i;
4706 bool ret = false;
4707
Alexander Duyck03ecf912011-05-20 07:36:17 +00004708 if ((adapter->flags & IXGBE_FLAG_RSS_ENABLED) &&
4709 (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004710 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004711 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004712 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004713 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004714 ret = true;
4715 }
4716
4717 return ret;
4718}
4719
Yi Zou0331a832009-05-17 12:33:52 +00004720#ifdef IXGBE_FCOE
4721/**
4722 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4723 * @adapter: board private structure to initialize
4724 *
4725 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4726 *
4727 */
4728static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4729{
Yi Zou0331a832009-05-17 12:33:52 +00004730 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004731 int i;
4732 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004733
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004734 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4735 return false;
4736
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004737 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Alexander Duyck03ecf912011-05-20 07:36:17 +00004738 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE)
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004739 ixgbe_cache_ring_fdir(adapter);
4740 else
4741 ixgbe_cache_ring_rss(adapter);
4742
4743 fcoe_rx_i = f->mask;
4744 fcoe_tx_i = f->mask;
4745 }
4746 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4747 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4748 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4749 }
4750 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004751}
4752
4753#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004754/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004755 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4756 * @adapter: board private structure to initialize
4757 *
4758 * SR-IOV doesn't use any descriptor rings but changes the default if
4759 * no other mapping is used.
4760 *
4761 */
4762static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4763{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004764 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4765 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004766 if (adapter->num_vfs)
4767 return true;
4768 else
4769 return false;
4770}
4771
4772/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004773 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4774 * @adapter: board private structure to initialize
4775 *
4776 * Once we know the feature-set enabled for the device, we'll cache
4777 * the register offset the descriptor ring is assigned to.
4778 *
4779 * Note, the order the various feature calls is important. It must start with
4780 * the "most" features enabled at the same time, then trickle down to the
4781 * least amount of features turned on at once.
4782 **/
4783static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4784{
4785 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004786 adapter->rx_ring[0]->reg_idx = 0;
4787 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004788
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004789 if (ixgbe_cache_ring_sriov(adapter))
4790 return;
4791
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004792#ifdef CONFIG_IXGBE_DCB
4793 if (ixgbe_cache_ring_dcb(adapter))
4794 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004795#endif
John Fastabende5b64632011-03-08 03:44:52 +00004796
4797#ifdef IXGBE_FCOE
4798 if (ixgbe_cache_ring_fcoe(adapter))
4799 return;
4800#endif /* IXGBE_FCOE */
4801
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004802 if (ixgbe_cache_ring_fdir(adapter))
4803 return;
4804
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004805 if (ixgbe_cache_ring_rss(adapter))
4806 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004807}
4808
Auke Kok9a799d72007-09-15 14:07:45 -07004809/**
4810 * ixgbe_alloc_queues - Allocate memory for all rings
4811 * @adapter: board private structure to initialize
4812 *
4813 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004814 * number of queues at compile-time. The polling_netdev array is
4815 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004816 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004817static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004818{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004819 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004820
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004821 if (nid < 0 || !node_online(nid))
4822 nid = first_online_node;
4823
4824 for (; tx < adapter->num_tx_queues; tx++) {
4825 struct ixgbe_ring *ring;
4826
4827 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004828 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004829 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004830 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004831 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004832 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004833 ring->queue_index = tx;
4834 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004835 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004836 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004837
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004838 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004840
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004841 for (; rx < adapter->num_rx_queues; rx++) {
4842 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004843
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004844 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004845 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004846 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004847 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004848 goto err_allocation;
4849 ring->count = adapter->rx_ring_count;
4850 ring->queue_index = rx;
4851 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004852 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004853 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004854
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004855 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004856 }
4857
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004858 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004859
4860 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004861
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004862err_allocation:
4863 while (tx)
4864 kfree(adapter->tx_ring[--tx]);
4865
4866 while (rx)
4867 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004868 return -ENOMEM;
4869}
4870
4871/**
4872 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4873 * @adapter: board private structure to initialize
4874 *
4875 * Attempt to configure the interrupts using the best available
4876 * capabilities of the hardware and the kernel.
4877 **/
Al Virofeea6a52008-11-27 15:34:07 -08004878static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004879{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004880 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004881 int err = 0;
4882 int vector, v_budget;
4883
4884 /*
4885 * It's easy to be greedy for MSI-X vectors, but it really
4886 * doesn't do us much good if we have a lot more vectors
4887 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004888 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004889 */
4890 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004891 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004892
4893 /*
4894 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004895 * hw.mac->max_msix_vectors vectors. With features
4896 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4897 * descriptor queues supported by our device. Thus, we cap it off in
4898 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004899 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004900 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004901
4902 /* A failure in MSI-X entry allocation isn't fatal, but it does
4903 * mean we disable MSI-X capabilities of the adapter. */
4904 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004905 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004906 if (adapter->msix_entries) {
4907 for (vector = 0; vector < v_budget; vector++)
4908 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004909
Alexander Duyck7a921c92009-05-06 10:43:28 +00004910 ixgbe_acquire_msix_vectors(adapter, v_budget);
4911
4912 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4913 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004914 }
David S. Miller26d27842010-05-03 15:18:22 -07004915
Alexander Duyck7a921c92009-05-06 10:43:28 +00004916 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4917 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck03ecf912011-05-20 07:36:17 +00004918 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
Alexander Duyck45b9f502011-01-06 14:29:59 +00004919 e_err(probe,
Alexander Duyck03ecf912011-05-20 07:36:17 +00004920 "ATR is not supported while multiple "
Alexander Duyck45b9f502011-01-06 14:29:59 +00004921 "queues are disabled. Disabling Flow Director\n");
4922 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004923 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004924 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004925 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4926 ixgbe_disable_sriov(adapter);
4927
Ben Hutchings847f53f2010-09-27 08:28:56 +00004928 err = ixgbe_set_num_queues(adapter);
4929 if (err)
4930 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004931
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004932 err = pci_enable_msi(adapter->pdev);
4933 if (!err) {
4934 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4935 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004936 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4937 "Unable to allocate MSI interrupt, "
4938 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004939 /* reset err */
4940 err = 0;
4941 }
4942
4943out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004944 return err;
4945}
4946
Alexander Duyck7a921c92009-05-06 10:43:28 +00004947/**
4948 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4949 * @adapter: board private structure to initialize
4950 *
4951 * We allocate one q_vector per queue interrupt. If allocation fails we
4952 * return -ENOMEM.
4953 **/
4954static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4955{
4956 int q_idx, num_q_vectors;
4957 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004958 int (*poll)(struct napi_struct *, int);
4959
4960 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4961 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004962 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004963 } else {
4964 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004965 poll = &ixgbe_poll;
4966 }
4967
4968 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004969 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004970 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004971 if (!q_vector)
4972 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004973 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004974 if (!q_vector)
4975 goto err_out;
4976 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004977 if (q_vector->txr_count && !q_vector->rxr_count)
4978 q_vector->eitr = adapter->tx_eitr_param;
4979 else
4980 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00004981 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004982 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004983 adapter->q_vector[q_idx] = q_vector;
4984 }
4985
4986 return 0;
4987
4988err_out:
4989 while (q_idx) {
4990 q_idx--;
4991 q_vector = adapter->q_vector[q_idx];
4992 netif_napi_del(&q_vector->napi);
4993 kfree(q_vector);
4994 adapter->q_vector[q_idx] = NULL;
4995 }
4996 return -ENOMEM;
4997}
4998
4999/**
5000 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5001 * @adapter: board private structure to initialize
5002 *
5003 * This function frees the memory allocated to the q_vectors. In addition if
5004 * NAPI is enabled it will delete any references to the NAPI struct prior
5005 * to freeing the q_vector.
5006 **/
5007static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5008{
5009 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005010
Alexander Duyck91281fd2009-06-04 16:00:27 +00005011 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005012 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005013 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005014 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005015
5016 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5017 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005018 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005019 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005020 kfree(q_vector);
5021 }
5022}
5023
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005024static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005025{
5026 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5027 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5028 pci_disable_msix(adapter->pdev);
5029 kfree(adapter->msix_entries);
5030 adapter->msix_entries = NULL;
5031 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5032 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5033 pci_disable_msi(adapter->pdev);
5034 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005035}
5036
5037/**
5038 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5039 * @adapter: board private structure to initialize
5040 *
5041 * We determine which interrupt scheme to use based on...
5042 * - Kernel support (MSI, MSI-X)
5043 * - which can be user-defined (via MODULE_PARAM)
5044 * - Hardware queue count (num_*_queues)
5045 * - defined by miscellaneous hardware support/features (RSS, etc.)
5046 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005047int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005048{
5049 int err;
5050
5051 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005052 err = ixgbe_set_num_queues(adapter);
5053 if (err)
5054 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005055
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005056 err = ixgbe_set_interrupt_capability(adapter);
5057 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005058 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005059 goto err_set_interrupt;
5060 }
5061
Alexander Duyck7a921c92009-05-06 10:43:28 +00005062 err = ixgbe_alloc_q_vectors(adapter);
5063 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005064 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005065 goto err_alloc_q_vectors;
5066 }
5067
5068 err = ixgbe_alloc_queues(adapter);
5069 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005070 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005071 goto err_alloc_queues;
5072 }
5073
Emil Tantilov849c4542010-06-03 16:53:41 +00005074 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005075 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5076 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005077
5078 set_bit(__IXGBE_DOWN, &adapter->state);
5079
5080 return 0;
5081
Alexander Duyck7a921c92009-05-06 10:43:28 +00005082err_alloc_queues:
5083 ixgbe_free_q_vectors(adapter);
5084err_alloc_q_vectors:
5085 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005086err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005087 return err;
5088}
5089
5090/**
5091 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5092 * @adapter: board private structure to clear interrupt scheme on
5093 *
5094 * We go through and clear interrupt specific resources and reset the structure
5095 * to pre-load conditions
5096 **/
5097void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5098{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005099 int i;
5100
5101 for (i = 0; i < adapter->num_tx_queues; i++) {
5102 kfree(adapter->tx_ring[i]);
5103 adapter->tx_ring[i] = NULL;
5104 }
5105 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005106 struct ixgbe_ring *ring = adapter->rx_ring[i];
5107
5108 /* ixgbe_get_stats64() might access this ring, we must wait
5109 * a grace period before freeing it.
5110 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005111 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005112 adapter->rx_ring[i] = NULL;
5113 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005114
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005115 adapter->num_tx_queues = 0;
5116 adapter->num_rx_queues = 0;
5117
Alexander Duyck7a921c92009-05-06 10:43:28 +00005118 ixgbe_free_q_vectors(adapter);
5119 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005120}
5121
5122/**
5123 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5124 * @adapter: board private structure to initialize
5125 *
5126 * ixgbe_sw_init initializes the Adapter private data structure.
5127 * Fields are initialized based on PCI device information and
5128 * OS network device settings (MTU size).
5129 **/
5130static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5131{
5132 struct ixgbe_hw *hw = &adapter->hw;
5133 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005134 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005135 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005136#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005137 int j;
5138 struct tc_configuration *tc;
5139#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005140 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005141
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005142 /* PCI config space info */
5143
5144 hw->vendor_id = pdev->vendor;
5145 hw->device_id = pdev->device;
5146 hw->revision_id = pdev->revision;
5147 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5148 hw->subsystem_device_id = pdev->subsystem_device;
5149
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005150 /* Set capability flags */
5151 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5152 adapter->ring_feature[RING_F_RSS].indices = rss;
5153 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyckbd508172010-11-16 19:27:03 -08005154 switch (hw->mac.type) {
5155 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005156 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5157 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005158 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005159 break;
5160 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005161 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005162 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005163 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5164 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005165 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5166 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005167 /* n-tuple support exists, always init our spinlock */
5168 spin_lock_init(&adapter->fdir_perfect_lock);
5169 /* Flow Director hash filters enabled */
5170 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5171 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005172 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005173 IXGBE_MAX_FDIR_INDICES;
Alexander Duyckc04f6ca2011-05-11 07:18:36 +00005174 adapter->fdir_pballoc = IXGBE_FDIR_PBALLOC_64K;
Yi Zoueacd73f2009-05-13 13:11:06 +00005175#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005176 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5177 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5178 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005179#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005180 /* Default traffic class to use for FCoE */
5181 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005182 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005183#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005184#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005185 break;
5186 default:
5187 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005188 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005189
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005190#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005191 /* Configure DCB traffic classes */
5192 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5193 tc = &adapter->dcb_cfg.tc_config[j];
5194 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5195 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5196 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5197 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5198 tc->dcb_pfc = pfc_disabled;
5199 }
5200 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5201 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005202 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005203 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005204 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005205 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005206 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005207
5208#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005209
5210 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005211 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005212 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005213#ifdef CONFIG_DCB
5214 adapter->last_lfc_mode = hw->fc.current_mode;
5215#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005216 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5217 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005218 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5219 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005220 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005221
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005222 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005223 adapter->rx_itr_setting = 1;
5224 adapter->rx_eitr_param = 20000;
5225 adapter->tx_itr_setting = 1;
5226 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005227
5228 /* set defaults for eitr in MegaBytes */
5229 adapter->eitr_low = 10;
5230 adapter->eitr_high = 20;
5231
5232 /* set default ring sizes */
5233 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5234 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5235
Auke Kok9a799d72007-09-15 14:07:45 -07005236 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005237 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005238 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005239 return -EIO;
5240 }
5241
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005242 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005243 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5244
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005245 /* get assigned NUMA node */
5246 adapter->node = dev_to_node(&pdev->dev);
5247
Auke Kok9a799d72007-09-15 14:07:45 -07005248 set_bit(__IXGBE_DOWN, &adapter->state);
5249
5250 return 0;
5251}
5252
5253/**
5254 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005255 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005256 *
5257 * Return 0 on success, negative on failure
5258 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005259int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005260{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005261 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005262 int size;
5263
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005264 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005265 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005266 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005267 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005268 if (!tx_ring->tx_buffer_info)
5269 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005270
5271 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005272 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005273 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005274
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005275 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005276 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005277 if (!tx_ring->desc)
5278 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005279
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005280 tx_ring->next_to_use = 0;
5281 tx_ring->next_to_clean = 0;
5282 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005283 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005284
5285err:
5286 vfree(tx_ring->tx_buffer_info);
5287 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005288 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005289 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005290}
5291
5292/**
Alexander Duyck69888672008-09-11 20:05:39 -07005293 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5294 * @adapter: board private structure
5295 *
5296 * If this function returns with an error, then it's possible one or
5297 * more of the rings is populated (while the rest are not). It is the
5298 * callers duty to clean those orphaned rings.
5299 *
5300 * Return 0 on success, negative on failure
5301 **/
5302static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5303{
5304 int i, err = 0;
5305
5306 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005307 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005308 if (!err)
5309 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005310 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005311 break;
5312 }
5313
5314 return err;
5315}
5316
5317/**
Auke Kok9a799d72007-09-15 14:07:45 -07005318 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005319 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005320 *
5321 * Returns 0 on success, negative on failure
5322 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005323int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005324{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005325 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005326 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005327
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005328 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005329 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005330 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005331 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005332 if (!rx_ring->rx_buffer_info)
5333 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005334
Auke Kok9a799d72007-09-15 14:07:45 -07005335 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005336 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5337 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005338
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005339 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005340 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005341
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005342 if (!rx_ring->desc)
5343 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005344
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005345 rx_ring->next_to_clean = 0;
5346 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005347
5348 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005349err:
5350 vfree(rx_ring->rx_buffer_info);
5351 rx_ring->rx_buffer_info = NULL;
5352 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005353 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005354}
5355
5356/**
Alexander Duyck69888672008-09-11 20:05:39 -07005357 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5358 * @adapter: board private structure
5359 *
5360 * If this function returns with an error, then it's possible one or
5361 * more of the rings is populated (while the rest are not). It is the
5362 * callers duty to clean those orphaned rings.
5363 *
5364 * Return 0 on success, negative on failure
5365 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005366static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5367{
5368 int i, err = 0;
5369
5370 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005371 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005372 if (!err)
5373 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005374 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005375 break;
5376 }
5377
5378 return err;
5379}
5380
5381/**
Auke Kok9a799d72007-09-15 14:07:45 -07005382 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005383 * @tx_ring: Tx descriptor ring for a specific queue
5384 *
5385 * Free all transmit software resources
5386 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005387void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005388{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005389 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005390
5391 vfree(tx_ring->tx_buffer_info);
5392 tx_ring->tx_buffer_info = NULL;
5393
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005394 /* if not set, then don't free */
5395 if (!tx_ring->desc)
5396 return;
5397
5398 dma_free_coherent(tx_ring->dev, tx_ring->size,
5399 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005400
5401 tx_ring->desc = NULL;
5402}
5403
5404/**
5405 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5406 * @adapter: board private structure
5407 *
5408 * Free all transmit software resources
5409 **/
5410static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5411{
5412 int i;
5413
5414 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005415 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005416 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005417}
5418
5419/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005420 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005421 * @rx_ring: ring to clean the resources from
5422 *
5423 * Free all receive software resources
5424 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005425void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005426{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005427 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005428
5429 vfree(rx_ring->rx_buffer_info);
5430 rx_ring->rx_buffer_info = NULL;
5431
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005432 /* if not set, then don't free */
5433 if (!rx_ring->desc)
5434 return;
5435
5436 dma_free_coherent(rx_ring->dev, rx_ring->size,
5437 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005438
5439 rx_ring->desc = NULL;
5440}
5441
5442/**
5443 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5444 * @adapter: board private structure
5445 *
5446 * Free all receive software resources
5447 **/
5448static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5449{
5450 int i;
5451
5452 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005453 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005454 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005455}
5456
5457/**
Auke Kok9a799d72007-09-15 14:07:45 -07005458 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5459 * @netdev: network interface device structure
5460 * @new_mtu: new value for maximum frame size
5461 *
5462 * Returns 0 on success, negative on failure
5463 **/
5464static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5465{
5466 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005467 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005468 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5469
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005470 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005471 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5472 hw->mac.type != ixgbe_mac_X540) {
5473 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5474 return -EINVAL;
5475 } else {
5476 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5477 return -EINVAL;
5478 }
Auke Kok9a799d72007-09-15 14:07:45 -07005479
Emil Tantilov396e7992010-07-01 20:05:12 +00005480 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005481 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005482 netdev->mtu = new_mtu;
5483
John Fastabend16b61be2010-11-16 19:26:44 -08005484 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5485 hw->fc.low_water = FC_LOW_WATER(max_frame);
5486
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005487 if (netif_running(netdev))
5488 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005489
5490 return 0;
5491}
5492
5493/**
5494 * ixgbe_open - Called when a network interface is made active
5495 * @netdev: network interface device structure
5496 *
5497 * Returns 0 on success, negative value on failure
5498 *
5499 * The open entry point is called when a network interface is made
5500 * active by the system (IFF_UP). At this point all resources needed
5501 * for transmit and receive operations are allocated, the interrupt
5502 * handler is registered with the OS, the watchdog timer is started,
5503 * and the stack is notified that the interface is ready.
5504 **/
5505static int ixgbe_open(struct net_device *netdev)
5506{
5507 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5508 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005509
Auke Kok4bebfaa2008-02-11 09:26:01 -08005510 /* disallow open during test */
5511 if (test_bit(__IXGBE_TESTING, &adapter->state))
5512 return -EBUSY;
5513
Jesse Brandeburg54386462009-04-17 20:44:27 +00005514 netif_carrier_off(netdev);
5515
Auke Kok9a799d72007-09-15 14:07:45 -07005516 /* allocate transmit descriptors */
5517 err = ixgbe_setup_all_tx_resources(adapter);
5518 if (err)
5519 goto err_setup_tx;
5520
Auke Kok9a799d72007-09-15 14:07:45 -07005521 /* allocate receive descriptors */
5522 err = ixgbe_setup_all_rx_resources(adapter);
5523 if (err)
5524 goto err_setup_rx;
5525
5526 ixgbe_configure(adapter);
5527
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005528 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005529 if (err)
5530 goto err_req_irq;
5531
Auke Kok9a799d72007-09-15 14:07:45 -07005532 err = ixgbe_up_complete(adapter);
5533 if (err)
5534 goto err_up;
5535
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005536 netif_tx_start_all_queues(netdev);
5537
Auke Kok9a799d72007-09-15 14:07:45 -07005538 return 0;
5539
5540err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005541 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005542 ixgbe_free_irq(adapter);
5543err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005544err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005545 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005546err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005547 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005548 ixgbe_reset(adapter);
5549
5550 return err;
5551}
5552
5553/**
5554 * ixgbe_close - Disables a network interface
5555 * @netdev: network interface device structure
5556 *
5557 * Returns 0, this is not allowed to fail
5558 *
5559 * The close entry point is called when an interface is de-activated
5560 * by the OS. The hardware is still under the drivers control, but
5561 * needs to be disabled. A global MAC reset is issued to stop the
5562 * hardware, and all transmit and receive resources are freed.
5563 **/
5564static int ixgbe_close(struct net_device *netdev)
5565{
5566 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005567
5568 ixgbe_down(adapter);
5569 ixgbe_free_irq(adapter);
5570
Alexander Duycke4911d52011-05-11 07:18:52 +00005571 ixgbe_fdir_filter_exit(adapter);
5572
Auke Kok9a799d72007-09-15 14:07:45 -07005573 ixgbe_free_all_tx_resources(adapter);
5574 ixgbe_free_all_rx_resources(adapter);
5575
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005576 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005577
5578 return 0;
5579}
5580
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005581#ifdef CONFIG_PM
5582static int ixgbe_resume(struct pci_dev *pdev)
5583{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005584 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5585 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005586 u32 err;
5587
5588 pci_set_power_state(pdev, PCI_D0);
5589 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005590 /*
5591 * pci_restore_state clears dev->state_saved so call
5592 * pci_save_state to restore it.
5593 */
5594 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005595
5596 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005597 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005598 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005599 return err;
5600 }
5601 pci_set_master(pdev);
5602
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005603 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005604
5605 err = ixgbe_init_interrupt_scheme(adapter);
5606 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005607 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005608 return err;
5609 }
5610
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005611 ixgbe_reset(adapter);
5612
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005613 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5614
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005615 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005616 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005617 if (err)
5618 return err;
5619 }
5620
5621 netif_device_attach(netdev);
5622
5623 return 0;
5624}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005625#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005626
5627static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005629 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5630 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005631 struct ixgbe_hw *hw = &adapter->hw;
5632 u32 ctrl, fctrl;
5633 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005634#ifdef CONFIG_PM
5635 int retval = 0;
5636#endif
5637
5638 netif_device_detach(netdev);
5639
5640 if (netif_running(netdev)) {
5641 ixgbe_down(adapter);
5642 ixgbe_free_irq(adapter);
5643 ixgbe_free_all_tx_resources(adapter);
5644 ixgbe_free_all_rx_resources(adapter);
5645 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005646
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005647 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005648#ifdef CONFIG_DCB
5649 kfree(adapter->ixgbe_ieee_pfc);
5650 kfree(adapter->ixgbe_ieee_ets);
5651#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005652
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005653#ifdef CONFIG_PM
5654 retval = pci_save_state(pdev);
5655 if (retval)
5656 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005657
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005658#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005659 if (wufc) {
5660 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005661
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005662 /* turn on all-multi mode if wake on multicast is enabled */
5663 if (wufc & IXGBE_WUFC_MC) {
5664 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5665 fctrl |= IXGBE_FCTRL_MPE;
5666 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5667 }
5668
5669 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5670 ctrl |= IXGBE_CTRL_GIO_DIS;
5671 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5672
5673 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5674 } else {
5675 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5676 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5677 }
5678
Alexander Duyckbd508172010-11-16 19:27:03 -08005679 switch (hw->mac.type) {
5680 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005681 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005682 break;
5683 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005684 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005685 pci_wake_from_d3(pdev, !!wufc);
5686 break;
5687 default:
5688 break;
5689 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005690
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005691 *enable_wake = !!wufc;
5692
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005693 ixgbe_release_hw_control(adapter);
5694
5695 pci_disable_device(pdev);
5696
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005697 return 0;
5698}
5699
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005700#ifdef CONFIG_PM
5701static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5702{
5703 int retval;
5704 bool wake;
5705
5706 retval = __ixgbe_shutdown(pdev, &wake);
5707 if (retval)
5708 return retval;
5709
5710 if (wake) {
5711 pci_prepare_to_sleep(pdev);
5712 } else {
5713 pci_wake_from_d3(pdev, false);
5714 pci_set_power_state(pdev, PCI_D3hot);
5715 }
5716
5717 return 0;
5718}
5719#endif /* CONFIG_PM */
5720
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005721static void ixgbe_shutdown(struct pci_dev *pdev)
5722{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005723 bool wake;
5724
5725 __ixgbe_shutdown(pdev, &wake);
5726
5727 if (system_state == SYSTEM_POWER_OFF) {
5728 pci_wake_from_d3(pdev, wake);
5729 pci_set_power_state(pdev, PCI_D3hot);
5730 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005731}
5732
5733/**
Auke Kok9a799d72007-09-15 14:07:45 -07005734 * ixgbe_update_stats - Update the board statistics counters.
5735 * @adapter: board private structure
5736 **/
5737void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5738{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005739 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005740 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005741 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005742 u64 total_mpc = 0;
5743 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005744 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5745 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5746 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005747
Don Skidmored08935c2010-06-11 13:20:29 +00005748 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5749 test_bit(__IXGBE_RESETTING, &adapter->state))
5750 return;
5751
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005752 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005753 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005754 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005755 for (i = 0; i < 16; i++)
5756 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005757 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005758 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005759 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5760 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005761 }
5762 adapter->rsc_total_count = rsc_count;
5763 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005764 }
5765
Alexander Duyck5b7da512010-11-16 19:26:50 -08005766 for (i = 0; i < adapter->num_rx_queues; i++) {
5767 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5768 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5769 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5770 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5771 bytes += rx_ring->stats.bytes;
5772 packets += rx_ring->stats.packets;
5773 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005774 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005775 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5776 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5777 netdev->stats.rx_bytes = bytes;
5778 netdev->stats.rx_packets = packets;
5779
5780 bytes = 0;
5781 packets = 0;
5782 /* gather some stats to the adapter struct that are per queue */
5783 for (i = 0; i < adapter->num_tx_queues; i++) {
5784 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5785 restart_queue += tx_ring->tx_stats.restart_queue;
5786 tx_busy += tx_ring->tx_stats.tx_busy;
5787 bytes += tx_ring->stats.bytes;
5788 packets += tx_ring->stats.packets;
5789 }
5790 adapter->restart_queue = restart_queue;
5791 adapter->tx_busy = tx_busy;
5792 netdev->stats.tx_bytes = bytes;
5793 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005794
Joe Perches7ca647b2010-09-07 21:35:40 +00005795 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005796 for (i = 0; i < 8; i++) {
5797 /* for packet buffers not used, the register should read 0 */
5798 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5799 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005800 hwstats->mpc[i] += mpc;
5801 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005802 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005803 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5804 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5805 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5806 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5807 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005808 switch (hw->mac.type) {
5809 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005810 hwstats->pxonrxc[i] +=
5811 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005812 break;
5813 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005814 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005815 hwstats->pxonrxc[i] +=
5816 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005817 break;
5818 default:
5819 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005820 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005821 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5822 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005823 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005824 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005825 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005826 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005827
John Fastabendc84d3242010-11-16 19:27:12 -08005828 ixgbe_update_xoff_received(adapter);
5829
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005830 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005831 switch (hw->mac.type) {
5832 case ixgbe_mac_82598EB:
5833 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005834 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5835 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5836 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5837 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005838 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005839 /* OS2BMC stats are X540 only*/
5840 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5841 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5842 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5843 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5844 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005845 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005846 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005848 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005849 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005850 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005851 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005852 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5853 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005854#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005855 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5856 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5857 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5858 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5859 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5860 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005861#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005862 break;
5863 default:
5864 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005865 }
Auke Kok9a799d72007-09-15 14:07:45 -07005866 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005867 hwstats->bprc += bprc;
5868 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005869 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005870 hwstats->mprc -= bprc;
5871 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5872 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5873 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5874 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5875 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5876 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5877 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5878 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005879 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005880 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005881 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005882 hwstats->lxofftxc += lxoff;
5883 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5884 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5885 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005886 /*
5887 * 82598 errata - tx of flow control packets is included in tx counters
5888 */
5889 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005890 hwstats->gptc -= xon_off_tot;
5891 hwstats->mptc -= xon_off_tot;
5892 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5893 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5894 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5895 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5896 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5897 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5898 hwstats->ptc64 -= xon_off_tot;
5899 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5900 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5901 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5902 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5903 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5904 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005905
5906 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005907 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005908
5909 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005910 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005911 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005912 netdev->stats.rx_length_errors = hwstats->rlec;
5913 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005914 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005915}
5916
5917/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005918 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5919 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005920 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005921static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005922{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005923 struct ixgbe_hw *hw = &adapter->hw;
5924 int i;
5925
Alexander Duyckd034acf2011-04-27 09:25:34 +00005926 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5927 return;
5928
5929 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5930
5931 /* if interface is down do nothing */
5932 if (test_bit(__IXGBE_DOWN, &adapter->state))
5933 return;
5934
5935 /* do nothing if we are not using signature filters */
5936 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5937 return;
5938
5939 adapter->fdir_overflow++;
5940
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005941 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5942 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005943 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005944 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005945 /* re-enable flow director interrupts */
5946 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005947 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005948 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005949 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005950 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005951}
5952
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005953/**
5954 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5955 * @adapter - pointer to the device adapter structure
5956 *
5957 * This function serves two purposes. First it strobes the interrupt lines
5958 * in order to make certain interrupts are occuring. Secondly it sets the
5959 * bits needed to check for TX hangs. As a result we should immediately
5960 * determine if a hang has occured.
5961 */
5962static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5963{
Auke Kok9a799d72007-09-15 14:07:45 -07005964 struct ixgbe_hw *hw = &adapter->hw;
5965 u64 eics = 0;
5966 int i;
5967
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005968 /* If we're down or resetting, just bail */
5969 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5970 test_bit(__IXGBE_RESETTING, &adapter->state))
5971 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005972
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005973 /* Force detection of hung controller */
5974 if (netif_carrier_ok(adapter->netdev)) {
5975 for (i = 0; i < adapter->num_tx_queues; i++)
5976 set_check_for_tx_hang(adapter->tx_ring[i]);
5977 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005978
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005979 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00005980 /*
5981 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005982 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00005983 * would set *both* EIMS and EICS for any bit in EIAM
5984 */
5985 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5986 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005987 } else {
5988 /* get one bit for every active tx/rx interrupt vector */
5989 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5990 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5991 if (qv->rxr_count || qv->txr_count)
5992 eics |= ((u64)1 << i);
5993 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005994 }
5995
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005996 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00005997 ixgbe_irq_rearm_queues(adapter, eics);
5998
Alexander Duyckfe49f042009-06-04 16:00:09 +00005999}
6000
6001/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006002 * ixgbe_watchdog_update_link - update the link status
6003 * @adapter - pointer to the device adapter structure
6004 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006005 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006006static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006007{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006008 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006009 u32 link_speed = adapter->link_speed;
6010 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006011 int i;
6012
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006013 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6014 return;
6015
6016 if (hw->mac.ops.check_link) {
6017 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006018 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006019 /* always assume link is up, if no check link function */
6020 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6021 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006022 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006023 if (link_up) {
6024 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6025 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6026 hw->mac.ops.fc_enable(hw, i);
6027 } else {
6028 hw->mac.ops.fc_enable(hw, 0);
6029 }
6030 }
6031
6032 if (link_up ||
6033 time_after(jiffies, (adapter->link_check_timeout +
6034 IXGBE_TRY_LINK_TIMEOUT))) {
6035 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6036 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6037 IXGBE_WRITE_FLUSH(hw);
6038 }
6039
6040 adapter->link_up = link_up;
6041 adapter->link_speed = link_speed;
6042}
6043
6044/**
6045 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6046 * print link up message
6047 * @adapter - pointer to the device adapter structure
6048 **/
6049static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6050{
6051 struct net_device *netdev = adapter->netdev;
6052 struct ixgbe_hw *hw = &adapter->hw;
6053 u32 link_speed = adapter->link_speed;
6054 bool flow_rx, flow_tx;
6055
6056 /* only continue if link was previously down */
6057 if (netif_carrier_ok(netdev))
6058 return;
6059
6060 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6061
6062 switch (hw->mac.type) {
6063 case ixgbe_mac_82598EB: {
6064 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6065 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6066 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6067 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6068 }
6069 break;
6070 case ixgbe_mac_X540:
6071 case ixgbe_mac_82599EB: {
6072 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6073 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6074 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6075 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6076 }
6077 break;
6078 default:
6079 flow_tx = false;
6080 flow_rx = false;
6081 break;
6082 }
6083 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6084 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6085 "10 Gbps" :
6086 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6087 "1 Gbps" :
6088 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6089 "100 Mbps" :
6090 "unknown speed"))),
6091 ((flow_rx && flow_tx) ? "RX/TX" :
6092 (flow_rx ? "RX" :
6093 (flow_tx ? "TX" : "None"))));
6094
6095 netif_carrier_on(netdev);
6096#ifdef HAVE_IPLINK_VF_CONFIG
6097 ixgbe_check_vf_rate_limit(adapter);
6098#endif /* HAVE_IPLINK_VF_CONFIG */
6099}
6100
6101/**
6102 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6103 * print link down message
6104 * @adapter - pointer to the adapter structure
6105 **/
6106static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6107{
6108 struct net_device *netdev = adapter->netdev;
6109 struct ixgbe_hw *hw = &adapter->hw;
6110
6111 adapter->link_up = false;
6112 adapter->link_speed = 0;
6113
6114 /* only continue if link was up previously */
6115 if (!netif_carrier_ok(netdev))
6116 return;
6117
6118 /* poll for SFP+ cable when link is down */
6119 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6120 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6121
6122 e_info(drv, "NIC Link is Down\n");
6123 netif_carrier_off(netdev);
6124}
6125
6126/**
6127 * ixgbe_watchdog_flush_tx - flush queues on link down
6128 * @adapter - pointer to the device adapter structure
6129 **/
6130static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6131{
6132 int i;
6133 int some_tx_pending = 0;
6134
6135 if (!netif_carrier_ok(adapter->netdev)) {
6136 for (i = 0; i < adapter->num_tx_queues; i++) {
6137 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6138 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6139 some_tx_pending = 1;
6140 break;
6141 }
6142 }
6143
6144 if (some_tx_pending) {
6145 /* We've lost link, so the controller stops DMA,
6146 * but we've got queued Tx work that's never going
6147 * to get done, so reset controller to flush Tx.
6148 * (Do the reset outside of interrupt context).
6149 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006150 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006151 }
6152 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006153}
6154
Greg Rosea985b6c32010-11-18 03:02:52 +00006155static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6156{
6157 u32 ssvpc;
6158
6159 /* Do not perform spoof check for 82598 */
6160 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6161 return;
6162
6163 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6164
6165 /*
6166 * ssvpc register is cleared on read, if zero then no
6167 * spoofed packets in the last interval.
6168 */
6169 if (!ssvpc)
6170 return;
6171
6172 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6173}
6174
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006175/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006176 * ixgbe_watchdog_subtask - check and bring link up
6177 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006178 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006179static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006180{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006181 /* if interface is down do nothing */
6182 if (test_bit(__IXGBE_DOWN, &adapter->state))
6183 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006184
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006185 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006186
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006187 if (adapter->link_up)
6188 ixgbe_watchdog_link_is_up(adapter);
6189 else
6190 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006191
Greg Rosea985b6c32010-11-18 03:02:52 +00006192 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006193 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006194
6195 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006196}
6197
Alexander Duyck70864002011-04-27 09:13:56 +00006198/**
6199 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6200 * @adapter - the ixgbe adapter structure
6201 **/
6202static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6203{
6204 struct ixgbe_hw *hw = &adapter->hw;
6205 s32 err;
6206
6207 /* not searching for SFP so there is nothing to do here */
6208 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6209 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6210 return;
6211
6212 /* someone else is in init, wait until next service event */
6213 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6214 return;
6215
6216 err = hw->phy.ops.identify_sfp(hw);
6217 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6218 goto sfp_out;
6219
6220 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6221 /* If no cable is present, then we need to reset
6222 * the next time we find a good cable. */
6223 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6224 }
6225
6226 /* exit on error */
6227 if (err)
6228 goto sfp_out;
6229
6230 /* exit if reset not needed */
6231 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6232 goto sfp_out;
6233
6234 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6235
6236 /*
6237 * A module may be identified correctly, but the EEPROM may not have
6238 * support for that module. setup_sfp() will fail in that case, so
6239 * we should not allow that module to load.
6240 */
6241 if (hw->mac.type == ixgbe_mac_82598EB)
6242 err = hw->phy.ops.reset(hw);
6243 else
6244 err = hw->mac.ops.setup_sfp(hw);
6245
6246 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6247 goto sfp_out;
6248
6249 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6250 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6251
6252sfp_out:
6253 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6254
6255 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6256 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6257 e_dev_err("failed to initialize because an unsupported "
6258 "SFP+ module type was detected.\n");
6259 e_dev_err("Reload the driver after installing a "
6260 "supported module.\n");
6261 unregister_netdev(adapter->netdev);
6262 }
6263}
6264
6265/**
6266 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6267 * @adapter - the ixgbe adapter structure
6268 **/
6269static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6270{
6271 struct ixgbe_hw *hw = &adapter->hw;
6272 u32 autoneg;
6273 bool negotiation;
6274
6275 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6276 return;
6277
6278 /* someone else is in init, wait until next service event */
6279 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6280 return;
6281
6282 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6283
6284 autoneg = hw->phy.autoneg_advertised;
6285 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6286 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6287 hw->mac.autotry_restart = false;
6288 if (hw->mac.ops.setup_link)
6289 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6290
6291 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6292 adapter->link_check_timeout = jiffies;
6293 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6294}
6295
6296/**
6297 * ixgbe_service_timer - Timer Call-back
6298 * @data: pointer to adapter cast into an unsigned long
6299 **/
6300static void ixgbe_service_timer(unsigned long data)
6301{
6302 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6303 unsigned long next_event_offset;
6304
6305 /* poll faster when waiting for link */
6306 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6307 next_event_offset = HZ / 10;
6308 else
6309 next_event_offset = HZ * 2;
6310
6311 /* Reset the timer */
6312 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6313
6314 ixgbe_service_event_schedule(adapter);
6315}
6316
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006317static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6318{
6319 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6320 return;
6321
6322 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6323
6324 /* If we're already down or resetting, just bail */
6325 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6326 test_bit(__IXGBE_RESETTING, &adapter->state))
6327 return;
6328
6329 ixgbe_dump(adapter);
6330 netdev_err(adapter->netdev, "Reset adapter\n");
6331 adapter->tx_timeout_count++;
6332
6333 ixgbe_reinit_locked(adapter);
6334}
6335
Alexander Duyck70864002011-04-27 09:13:56 +00006336/**
6337 * ixgbe_service_task - manages and runs subtasks
6338 * @work: pointer to work_struct containing our data
6339 **/
6340static void ixgbe_service_task(struct work_struct *work)
6341{
6342 struct ixgbe_adapter *adapter = container_of(work,
6343 struct ixgbe_adapter,
6344 service_task);
6345
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006346 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006347 ixgbe_sfp_detection_subtask(adapter);
6348 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006349 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006350 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006351 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006352 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006353
6354 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006355}
6356
Alexander Duyck897ab152011-05-27 05:31:47 +00006357void ixgbe_tx_ctxtdesc(struct ixgbe_ring *tx_ring, u32 vlan_macip_lens,
6358 u32 fcoe_sof_eof, u32 type_tucmd, u32 mss_l4len_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07006359{
6360 struct ixgbe_adv_tx_context_desc *context_desc;
Alexander Duyck897ab152011-05-27 05:31:47 +00006361 u16 i = tx_ring->next_to_use;
6362
6363 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
6364
6365 i++;
6366 tx_ring->next_to_use = (i < tx_ring->count) ? i : 0;
6367
6368 /* set bits to identify this as an advanced context descriptor */
6369 type_tucmd |= IXGBE_TXD_CMD_DEXT | IXGBE_ADVTXD_DTYP_CTXT;
6370
6371 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6372 context_desc->seqnum_seed = cpu_to_le32(fcoe_sof_eof);
6373 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd);
6374 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6375}
6376
6377static int ixgbe_tso(struct ixgbe_ring *tx_ring, struct sk_buff *skb,
6378 u32 tx_flags, __be16 protocol, u8 *hdr_len)
6379{
Auke Kok9a799d72007-09-15 14:07:45 -07006380 int err;
Alexander Duyck897ab152011-05-27 05:31:47 +00006381 u32 vlan_macip_lens, type_tucmd;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006382 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006383
Alexander Duyck897ab152011-05-27 05:31:47 +00006384 if (!skb_is_gso(skb))
6385 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006386
Alexander Duyck897ab152011-05-27 05:31:47 +00006387 if (skb_header_cloned(skb)) {
6388 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6389 if (err)
6390 return err;
Joe Perches7ca647b2010-09-07 21:35:40 +00006391 }
6392
Alexander Duyck897ab152011-05-27 05:31:47 +00006393 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
6394 type_tucmd = IXGBE_ADVTXD_TUCMD_L4T_TCP;
6395
6396 if (protocol == __constant_htons(ETH_P_IP)) {
6397 struct iphdr *iph = ip_hdr(skb);
6398 iph->tot_len = 0;
6399 iph->check = 0;
6400 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
6401 iph->daddr, 0,
6402 IPPROTO_TCP,
6403 0);
6404 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6405 } else if (skb_is_gso_v6(skb)) {
6406 ipv6_hdr(skb)->payload_len = 0;
6407 tcp_hdr(skb)->check =
6408 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
6409 &ipv6_hdr(skb)->daddr,
6410 0, IPPROTO_TCP, 0);
6411 }
6412
6413 l4len = tcp_hdrlen(skb);
6414 *hdr_len = skb_transport_offset(skb) + l4len;
6415
6416 /* mss_l4len_id: use 1 as index for TSO */
6417 mss_l4len_idx = l4len << IXGBE_ADVTXD_L4LEN_SHIFT;
6418 mss_l4len_idx |= skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT;
6419 mss_l4len_idx |= 1 << IXGBE_ADVTXD_IDX_SHIFT;
6420
6421 /* vlan_macip_lens: HEADLEN, MACLEN, VLAN tag */
6422 vlan_macip_lens = skb_network_header_len(skb);
6423 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6424 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6425
6426 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0, type_tucmd,
6427 mss_l4len_idx);
6428
6429 return 1;
Joe Perches7ca647b2010-09-07 21:35:40 +00006430}
6431
Alexander Duyck897ab152011-05-27 05:31:47 +00006432static bool ixgbe_tx_csum(struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006433 struct sk_buff *skb, u32 tx_flags,
6434 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006435{
Alexander Duyck897ab152011-05-27 05:31:47 +00006436 u32 vlan_macip_lens = 0;
6437 u32 mss_l4len_idx = 0;
6438 u32 type_tucmd = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006439
Alexander Duyck897ab152011-05-27 05:31:47 +00006440 if (skb->ip_summed != CHECKSUM_PARTIAL) {
6441 if (!(tx_flags & IXGBE_TX_FLAGS_VLAN))
6442 return false;
6443 } else {
6444 u8 l4_hdr = 0;
6445 switch (protocol) {
6446 case __constant_htons(ETH_P_IP):
6447 vlan_macip_lens |= skb_network_header_len(skb);
6448 type_tucmd |= IXGBE_ADVTXD_TUCMD_IPV4;
6449 l4_hdr = ip_hdr(skb)->protocol;
6450 break;
6451 case __constant_htons(ETH_P_IPV6):
6452 vlan_macip_lens |= skb_network_header_len(skb);
6453 l4_hdr = ipv6_hdr(skb)->nexthdr;
6454 break;
6455 default:
6456 if (unlikely(net_ratelimit())) {
6457 dev_warn(tx_ring->dev,
6458 "partial checksum but proto=%x!\n",
6459 skb->protocol);
6460 }
6461 break;
6462 }
Auke Kok9a799d72007-09-15 14:07:45 -07006463
Alexander Duyck897ab152011-05-27 05:31:47 +00006464 switch (l4_hdr) {
6465 case IPPROTO_TCP:
6466 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6467 mss_l4len_idx = tcp_hdrlen(skb) <<
6468 IXGBE_ADVTXD_L4LEN_SHIFT;
6469 break;
6470 case IPPROTO_SCTP:
6471 type_tucmd |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6472 mss_l4len_idx = sizeof(struct sctphdr) <<
6473 IXGBE_ADVTXD_L4LEN_SHIFT;
6474 break;
6475 case IPPROTO_UDP:
6476 mss_l4len_idx = sizeof(struct udphdr) <<
6477 IXGBE_ADVTXD_L4LEN_SHIFT;
6478 break;
6479 default:
6480 if (unlikely(net_ratelimit())) {
6481 dev_warn(tx_ring->dev,
6482 "partial checksum but l4 proto=%x!\n",
6483 skb->protocol);
6484 }
6485 break;
6486 }
Auke Kok9a799d72007-09-15 14:07:45 -07006487 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006488
Alexander Duyck897ab152011-05-27 05:31:47 +00006489 vlan_macip_lens |= skb_network_offset(skb) << IXGBE_ADVTXD_MACLEN_SHIFT;
6490 vlan_macip_lens |= tx_flags & IXGBE_TX_FLAGS_VLAN_MASK;
6491
6492 ixgbe_tx_ctxtdesc(tx_ring, vlan_macip_lens, 0,
6493 type_tucmd, mss_l4len_idx);
6494
6495 return (skb->ip_summed == CHECKSUM_PARTIAL);
Auke Kok9a799d72007-09-15 14:07:45 -07006496}
6497
6498static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006499 struct ixgbe_ring *tx_ring,
6500 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006501 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006502{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006503 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006504 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006505 unsigned int len;
6506 unsigned int total = skb->len;
Alexander Duyck63544e92011-05-27 05:31:42 +00006507 unsigned int offset = 0, size, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006508 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6509 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006510 unsigned int bytecount = skb->len;
6511 u16 gso_segs = 1;
Alexander Duyck63544e92011-05-27 05:31:42 +00006512 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07006513
6514 i = tx_ring->next_to_use;
6515
Yi Zoueacd73f2009-05-13 13:11:06 +00006516 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6517 /* excluding fcoe_crc_eof for FCoE */
6518 total -= sizeof(struct fcoe_crc_eof);
6519
6520 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006521 while (len) {
6522 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6523 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6524
6525 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006526 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006527 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006528 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006529 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006530 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006531 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006532 tx_buffer_info->time_stamp = jiffies;
6533 tx_buffer_info->next_to_watch = i;
6534
6535 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006536 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006537 offset += size;
6538 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006539
6540 if (len) {
6541 i++;
6542 if (i == tx_ring->count)
6543 i = 0;
6544 }
Auke Kok9a799d72007-09-15 14:07:45 -07006545 }
6546
6547 for (f = 0; f < nr_frags; f++) {
6548 struct skb_frag_struct *frag;
6549
6550 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006551 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006552 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006553
6554 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006555 i++;
6556 if (i == tx_ring->count)
6557 i = 0;
6558
Auke Kok9a799d72007-09-15 14:07:45 -07006559 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6560 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6561
6562 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006563 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006564 frag->page,
6565 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006566 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006567 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006568 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006569 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006570 tx_buffer_info->time_stamp = jiffies;
6571 tx_buffer_info->next_to_watch = i;
6572
6573 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006574 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006575 offset += size;
6576 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006577 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006578 if (total == 0)
6579 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006580 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006581
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006582 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6583 gso_segs = skb_shinfo(skb)->gso_segs;
6584#ifdef IXGBE_FCOE
6585 /* adjust for FCoE Sequence Offload */
6586 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6587 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6588 skb_shinfo(skb)->gso_size);
6589#endif /* IXGBE_FCOE */
6590 bytecount += (gso_segs - 1) * hdr_len;
6591
6592 /* multiply data chunks by size of headers */
6593 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6594 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006595 tx_ring->tx_buffer_info[i].skb = skb;
6596 tx_ring->tx_buffer_info[first].next_to_watch = i;
6597
6598 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006599
6600dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006601 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006602
6603 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6604 tx_buffer_info->dma = 0;
6605 tx_buffer_info->time_stamp = 0;
6606 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006607 if (count)
6608 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006609
6610 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006611 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006612 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006613 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006614 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006615 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006616 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006617 }
6618
Anton Blancharde44d38e2010-02-03 13:12:51 +00006619 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006620}
6621
Alexander Duyck84ea2592010-11-16 19:26:49 -08006622static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006623 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006624{
6625 union ixgbe_adv_tx_desc *tx_desc = NULL;
6626 struct ixgbe_tx_buffer *tx_buffer_info;
6627 u32 olinfo_status = 0, cmd_type_len = 0;
6628 unsigned int i;
6629 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6630
6631 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6632
6633 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6634
6635 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6636 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6637
6638 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6639 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6640
6641 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006642 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006643
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006644 /* use index 1 context for tso */
6645 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006646 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6647 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006648 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006649
6650 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6651 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006652 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006653
Yi Zoueacd73f2009-05-13 13:11:06 +00006654 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6655 olinfo_status |= IXGBE_ADVTXD_CC;
6656 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6657 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6658 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6659 }
6660
Auke Kok9a799d72007-09-15 14:07:45 -07006661 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6662
6663 i = tx_ring->next_to_use;
6664 while (count--) {
6665 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006666 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006667 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6668 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006669 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006670 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006671 i++;
6672 if (i == tx_ring->count)
6673 i = 0;
6674 }
6675
6676 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6677
6678 /*
6679 * Force memory writes to complete before letting h/w
6680 * know there are new descriptors to fetch. (Only
6681 * applicable for weak-ordered memory model archs,
6682 * such as IA-64).
6683 */
6684 wmb();
6685
6686 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006687 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006688}
6689
Alexander Duyck69830522011-01-06 14:29:58 +00006690static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6691 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006692{
Alexander Duyck69830522011-01-06 14:29:58 +00006693 struct ixgbe_q_vector *q_vector = ring->q_vector;
6694 union ixgbe_atr_hash_dword input = { .dword = 0 };
6695 union ixgbe_atr_hash_dword common = { .dword = 0 };
6696 union {
6697 unsigned char *network;
6698 struct iphdr *ipv4;
6699 struct ipv6hdr *ipv6;
6700 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006701 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006702 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006703
Alexander Duyck69830522011-01-06 14:29:58 +00006704 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6705 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006706 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006707
Alexander Duyck69830522011-01-06 14:29:58 +00006708 /* do nothing if sampling is disabled */
6709 if (!ring->atr_sample_rate)
6710 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006711
Alexander Duyck69830522011-01-06 14:29:58 +00006712 ring->atr_count++;
6713
6714 /* snag network header to get L4 type and address */
6715 hdr.network = skb_network_header(skb);
6716
6717 /* Currently only IPv4/IPv6 with TCP is supported */
6718 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6719 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6720 (protocol != __constant_htons(ETH_P_IP) ||
6721 hdr.ipv4->protocol != IPPROTO_TCP))
6722 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006723
6724 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006725
Alexander Duyck69830522011-01-06 14:29:58 +00006726 /* skip this packet since the socket is closing */
6727 if (th->fin)
6728 return;
6729
6730 /* sample on all syn packets or once every atr sample count */
6731 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6732 return;
6733
6734 /* reset sample count */
6735 ring->atr_count = 0;
6736
6737 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6738
6739 /*
6740 * src and dst are inverted, think how the receiver sees them
6741 *
6742 * The input is broken into two sections, a non-compressed section
6743 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6744 * is XORed together and stored in the compressed dword.
6745 */
6746 input.formatted.vlan_id = vlan_id;
6747
6748 /*
6749 * since src port and flex bytes occupy the same word XOR them together
6750 * and write the value to source port portion of compressed dword
6751 */
6752 if (vlan_id)
6753 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6754 else
6755 common.port.src ^= th->dest ^ protocol;
6756 common.port.dst ^= th->source;
6757
6758 if (protocol == __constant_htons(ETH_P_IP)) {
6759 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6760 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6761 } else {
6762 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6763 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6764 hdr.ipv6->saddr.s6_addr32[1] ^
6765 hdr.ipv6->saddr.s6_addr32[2] ^
6766 hdr.ipv6->saddr.s6_addr32[3] ^
6767 hdr.ipv6->daddr.s6_addr32[0] ^
6768 hdr.ipv6->daddr.s6_addr32[1] ^
6769 hdr.ipv6->daddr.s6_addr32[2] ^
6770 hdr.ipv6->daddr.s6_addr32[3];
6771 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006772
6773 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006774 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6775 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006776}
6777
Alexander Duyck63544e92011-05-27 05:31:42 +00006778static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006779{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006780 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006781 /* Herbert's original patch had:
6782 * smp_mb__after_netif_stop_queue();
6783 * but since that doesn't exist yet, just open code it. */
6784 smp_mb();
6785
6786 /* We need to check again in a case another CPU has just
6787 * made room available. */
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006788 if (likely(ixgbe_desc_unused(tx_ring) < size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006789 return -EBUSY;
6790
6791 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006792 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006793 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006794 return 0;
6795}
6796
Alexander Duyck63544e92011-05-27 05:31:42 +00006797static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, u16 size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006798{
Alexander Duyck7d4987d2011-05-27 05:31:37 +00006799 if (likely(ixgbe_desc_unused(tx_ring) >= size))
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006800 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006801 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006802}
6803
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006804static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6805{
6806 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006807 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006808#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006809 __be16 protocol;
6810
6811 protocol = vlan_get_protocol(skb);
6812
John Fastabende5b64632011-03-08 03:44:52 +00006813 if (((protocol == htons(ETH_P_FCOE)) ||
6814 (protocol == htons(ETH_P_FIP))) &&
6815 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6816 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6817 txq += adapter->ring_feature[RING_F_FCOE].mask;
6818 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006819 }
6820#endif
6821
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006822 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6823 while (unlikely(txq >= dev->real_num_tx_queues))
6824 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006825 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006826 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006827
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006828 return skb_tx_hash(dev, skb);
6829}
6830
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006831netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006832 struct ixgbe_adapter *adapter,
6833 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006834{
Auke Kok9a799d72007-09-15 14:07:45 -07006835 unsigned int tx_flags = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006836 int tso;
Alexander Duyck63544e92011-05-27 05:31:42 +00006837 u16 count = 0;
6838 u16 first;
Auke Kok9a799d72007-09-15 14:07:45 -07006839 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006840 __be16 protocol;
Alexander Duyck63544e92011-05-27 05:31:42 +00006841 u8 hdr_len = 0;
Hao Zheng5e09a102010-11-11 13:47:59 +00006842
6843 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006844
Jesse Grosseab6d182010-10-20 13:56:03 +00006845 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006846 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006847 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6848 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006849 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006850 }
6851 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6852 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006853 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6854 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006855 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006856 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6857 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006858 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006859
Yi Zou09ad1cc2009-09-03 14:56:10 +00006860#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006861 /* for FCoE with DCB, we force the priority to what
6862 * was specified by the switch */
6863 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006864 (protocol == htons(ETH_P_FCOE)))
6865 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006866#endif
6867
Yi Zoueacd73f2009-05-13 13:11:06 +00006868 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006869 if (skb_is_gso(skb) ||
6870 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006871 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6872 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006873 count++;
6874
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006875 count += TXD_USE_COUNT(skb_headlen(skb));
6876 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006877 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6878
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006879 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006880 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006881 return NETDEV_TX_BUSY;
6882 }
Auke Kok9a799d72007-09-15 14:07:45 -07006883
Auke Kok9a799d72007-09-15 14:07:45 -07006884 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006885 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6886#ifdef IXGBE_FCOE
6887 /* setup tx offload for FCoE */
Alexander Duyck897ab152011-05-27 05:31:47 +00006888 tso = ixgbe_fso(tx_ring, skb, tx_flags, &hdr_len);
6889 if (tso < 0)
6890 goto out_drop;
6891 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006892 tx_flags |= IXGBE_TX_FLAGS_FSO;
6893#endif /* IXGBE_FCOE */
6894 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006895 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006896 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Alexander Duyck897ab152011-05-27 05:31:47 +00006897 tso = ixgbe_tso(tx_ring, skb, tx_flags, protocol, &hdr_len);
6898 if (tso < 0)
6899 goto out_drop;
6900 else if (tso)
Yi Zoueacd73f2009-05-13 13:11:06 +00006901 tx_flags |= IXGBE_TX_FLAGS_TSO;
Alexander Duyck897ab152011-05-27 05:31:47 +00006902 else if (ixgbe_tx_csum(tx_ring, skb, tx_flags, protocol))
Yi Zoueacd73f2009-05-13 13:11:06 +00006903 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006904 }
6905
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006906 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006907 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006908 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006909 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6910 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006911 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006912 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006913
Alexander Duyck44df32c2009-03-31 21:34:23 +00006914 } else {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006915 tx_ring->tx_buffer_info[first].time_stamp = 0;
6916 tx_ring->next_to_use = first;
Alexander Duyck897ab152011-05-27 05:31:47 +00006917 goto out_drop;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006918 }
Auke Kok9a799d72007-09-15 14:07:45 -07006919
6920 return NETDEV_TX_OK;
Alexander Duyck897ab152011-05-27 05:31:47 +00006921
6922out_drop:
6923 dev_kfree_skb_any(skb);
6924 return NETDEV_TX_OK;
Auke Kok9a799d72007-09-15 14:07:45 -07006925}
6926
Alexander Duyck84418e32010-08-19 13:40:54 +00006927static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6928{
6929 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6930 struct ixgbe_ring *tx_ring;
6931
6932 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006933 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006934}
6935
Auke Kok9a799d72007-09-15 14:07:45 -07006936/**
Auke Kok9a799d72007-09-15 14:07:45 -07006937 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6938 * @netdev: network interface device structure
6939 * @p: pointer to an address structure
6940 *
6941 * Returns 0 on success, negative on failure
6942 **/
6943static int ixgbe_set_mac(struct net_device *netdev, void *p)
6944{
6945 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006946 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006947 struct sockaddr *addr = p;
6948
6949 if (!is_valid_ether_addr(addr->sa_data))
6950 return -EADDRNOTAVAIL;
6951
6952 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006953 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006954
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006955 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6956 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006957
6958 return 0;
6959}
6960
Ben Hutchings6b73e102009-04-29 08:08:58 +00006961static int
6962ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6963{
6964 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6965 struct ixgbe_hw *hw = &adapter->hw;
6966 u16 value;
6967 int rc;
6968
6969 if (prtad != hw->phy.mdio.prtad)
6970 return -EINVAL;
6971 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6972 if (!rc)
6973 rc = value;
6974 return rc;
6975}
6976
6977static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6978 u16 addr, u16 value)
6979{
6980 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6981 struct ixgbe_hw *hw = &adapter->hw;
6982
6983 if (prtad != hw->phy.mdio.prtad)
6984 return -EINVAL;
6985 return hw->phy.ops.write_reg(hw, addr, devad, value);
6986}
6987
6988static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6989{
6990 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6991
6992 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6993}
6994
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006995/**
6996 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006997 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006998 * @netdev: network interface device structure
6999 *
7000 * Returns non-zero on failure
7001 **/
7002static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7003{
7004 int err = 0;
7005 struct ixgbe_adapter *adapter = netdev_priv(dev);
7006 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7007
7008 if (is_valid_ether_addr(mac->san_addr)) {
7009 rtnl_lock();
7010 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7011 rtnl_unlock();
7012 }
7013 return err;
7014}
7015
7016/**
7017 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007018 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007019 * @netdev: network interface device structure
7020 *
7021 * Returns non-zero on failure
7022 **/
7023static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7024{
7025 int err = 0;
7026 struct ixgbe_adapter *adapter = netdev_priv(dev);
7027 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7028
7029 if (is_valid_ether_addr(mac->san_addr)) {
7030 rtnl_lock();
7031 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7032 rtnl_unlock();
7033 }
7034 return err;
7035}
7036
Auke Kok9a799d72007-09-15 14:07:45 -07007037#ifdef CONFIG_NET_POLL_CONTROLLER
7038/*
7039 * Polling 'interrupt' - used by things like netconsole to send skbs
7040 * without having to re-enable interrupts. It's not called while
7041 * the interrupt routine is executing.
7042 */
7043static void ixgbe_netpoll(struct net_device *netdev)
7044{
7045 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007046 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007047
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007048 /* if interface is down do nothing */
7049 if (test_bit(__IXGBE_DOWN, &adapter->state))
7050 return;
7051
Auke Kok9a799d72007-09-15 14:07:45 -07007052 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007053 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7054 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7055 for (i = 0; i < num_q_vectors; i++) {
7056 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7057 ixgbe_msix_clean_many(0, q_vector);
7058 }
7059 } else {
7060 ixgbe_intr(adapter->pdev->irq, netdev);
7061 }
Auke Kok9a799d72007-09-15 14:07:45 -07007062 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007063}
7064#endif
7065
Eric Dumazetde1036b2010-10-20 23:00:04 +00007066static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7067 struct rtnl_link_stats64 *stats)
7068{
7069 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7070 int i;
7071
Eric Dumazet1a515022010-11-16 19:26:42 -08007072 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007073 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007074 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007075 u64 bytes, packets;
7076 unsigned int start;
7077
Eric Dumazet1a515022010-11-16 19:26:42 -08007078 if (ring) {
7079 do {
7080 start = u64_stats_fetch_begin_bh(&ring->syncp);
7081 packets = ring->stats.packets;
7082 bytes = ring->stats.bytes;
7083 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7084 stats->rx_packets += packets;
7085 stats->rx_bytes += bytes;
7086 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007087 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007088
7089 for (i = 0; i < adapter->num_tx_queues; i++) {
7090 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7091 u64 bytes, packets;
7092 unsigned int start;
7093
7094 if (ring) {
7095 do {
7096 start = u64_stats_fetch_begin_bh(&ring->syncp);
7097 packets = ring->stats.packets;
7098 bytes = ring->stats.bytes;
7099 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7100 stats->tx_packets += packets;
7101 stats->tx_bytes += bytes;
7102 }
7103 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007104 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007105 /* following stats updated by ixgbe_watchdog_task() */
7106 stats->multicast = netdev->stats.multicast;
7107 stats->rx_errors = netdev->stats.rx_errors;
7108 stats->rx_length_errors = netdev->stats.rx_length_errors;
7109 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7110 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7111 return stats;
7112}
7113
John Fastabend8b1c0b22011-05-03 02:26:48 +00007114/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7115 * #adapter: pointer to ixgbe_adapter
7116 * @tc: number of traffic classes currently enabled
7117 *
7118 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7119 * 802.1Q priority maps to a packet buffer that exists.
7120 */
7121static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7122{
7123 struct ixgbe_hw *hw = &adapter->hw;
7124 u32 reg, rsave;
7125 int i;
7126
7127 /* 82598 have a static priority to TC mapping that can not
7128 * be changed so no validation is needed.
7129 */
7130 if (hw->mac.type == ixgbe_mac_82598EB)
7131 return;
7132
7133 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7134 rsave = reg;
7135
7136 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7137 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7138
7139 /* If up2tc is out of bounds default to zero */
7140 if (up2tc > tc)
7141 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7142 }
7143
7144 if (reg != rsave)
7145 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7146
7147 return;
7148}
7149
7150
7151/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7152 * classes.
7153 *
7154 * @netdev: net device to configure
7155 * @tc: number of traffic classes to enable
7156 */
7157int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7158{
John Fastabend8b1c0b22011-05-03 02:26:48 +00007159 struct ixgbe_adapter *adapter = netdev_priv(dev);
7160 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend8b1c0b22011-05-03 02:26:48 +00007161
7162 /* If DCB is anabled do not remove traffic classes, multiple
7163 * traffic classes are required to implement DCB
7164 */
7165 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7166 return 0;
7167
7168 /* Hardware supports up to 8 traffic classes */
7169 if (tc > MAX_TRAFFIC_CLASS ||
7170 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7171 return -EINVAL;
7172
7173 /* Hardware has to reinitialize queues and interrupts to
7174 * match packet buffer alignment. Unfortunantly, the
7175 * hardware is not flexible enough to do this dynamically.
7176 */
7177 if (netif_running(dev))
7178 ixgbe_close(dev);
7179 ixgbe_clear_interrupt_scheme(adapter);
7180
7181 if (tc)
7182 netdev_set_num_tc(dev, tc);
7183 else
7184 netdev_reset_tc(dev);
7185
John Fastabend8b1c0b22011-05-03 02:26:48 +00007186 ixgbe_init_interrupt_scheme(adapter);
7187 ixgbe_validate_rtr(adapter, tc);
7188 if (netif_running(dev))
7189 ixgbe_open(dev);
7190
7191 return 0;
7192}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007193
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007194static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007195 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007196 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007197 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007198 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007199 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007200 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7201 .ndo_validate_addr = eth_validate_addr,
7202 .ndo_set_mac_address = ixgbe_set_mac,
7203 .ndo_change_mtu = ixgbe_change_mtu,
7204 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007205 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7206 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007207 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007208 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7209 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7210 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7211 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007212 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007213 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007214#ifdef CONFIG_NET_POLL_CONTROLLER
7215 .ndo_poll_controller = ixgbe_netpoll,
7216#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007217#ifdef IXGBE_FCOE
7218 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007219 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007220 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007221 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7222 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007223 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007224#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007225};
7226
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007227static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7228 const struct ixgbe_info *ii)
7229{
7230#ifdef CONFIG_PCI_IOV
7231 struct ixgbe_hw *hw = &adapter->hw;
7232 int err;
Greg Rosea1cbb152011-05-13 01:33:48 +00007233 int num_vf_macvlans, i;
7234 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007235
Greg Rose3377eba792010-12-07 08:16:45 +00007236 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007237 return;
7238
7239 /* The 82599 supports up to 64 VFs per physical function
7240 * but this implementation limits allocation to 63 so that
7241 * basic networking resources are still available to the
7242 * physical function
7243 */
7244 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7245 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7246 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7247 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007248 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007249 goto err_novfs;
7250 }
Greg Rosea1cbb152011-05-13 01:33:48 +00007251
7252 num_vf_macvlans = hw->mac.num_rar_entries -
7253 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7254
7255 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7256 sizeof(struct vf_macvlans),
7257 GFP_KERNEL);
7258 if (mv_list) {
7259 /* Initialize list of VF macvlans */
7260 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7261 for (i = 0; i < num_vf_macvlans; i++) {
7262 mv_list->vf = -1;
7263 mv_list->free = true;
7264 mv_list->rar_entry = hw->mac.num_rar_entries -
7265 (i + adapter->num_vfs + 1);
7266 list_add(&mv_list->l, &adapter->vf_mvs.l);
7267 mv_list++;
7268 }
7269 }
7270
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007271 /* If call to enable VFs succeeded then allocate memory
7272 * for per VF control structures.
7273 */
7274 adapter->vfinfo =
7275 kcalloc(adapter->num_vfs,
7276 sizeof(struct vf_data_storage), GFP_KERNEL);
7277 if (adapter->vfinfo) {
7278 /* Now that we're sure SR-IOV is enabled
7279 * and memory allocated set up the mailbox parameters
7280 */
7281 ixgbe_init_mbx_params_pf(hw);
7282 memcpy(&hw->mbx.ops, ii->mbx_ops,
7283 sizeof(hw->mbx.ops));
7284
7285 /* Disable RSC when in SR-IOV mode */
7286 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7287 IXGBE_FLAG2_RSC_ENABLED);
7288 return;
7289 }
7290
7291 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007292 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7293 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007294 pci_disable_sriov(adapter->pdev);
7295
7296err_novfs:
7297 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7298 adapter->num_vfs = 0;
7299#endif /* CONFIG_PCI_IOV */
7300}
7301
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007302/**
Auke Kok9a799d72007-09-15 14:07:45 -07007303 * ixgbe_probe - Device Initialization Routine
7304 * @pdev: PCI device information struct
7305 * @ent: entry in ixgbe_pci_tbl
7306 *
7307 * Returns 0 on success, negative on failure
7308 *
7309 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7310 * The OS initialization, configuring of the adapter private structure,
7311 * and a hardware reset occur.
7312 **/
7313static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007314 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007315{
7316 struct net_device *netdev;
7317 struct ixgbe_adapter *adapter = NULL;
7318 struct ixgbe_hw *hw;
7319 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007320 static int cards_found;
7321 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007322 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007323 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007324#ifdef IXGBE_FCOE
7325 u16 device_caps;
7326#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007327 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007328
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007329 /* Catch broken hardware that put the wrong VF device ID in
7330 * the PCIe SR-IOV capability.
7331 */
7332 if (pdev->is_virtfn) {
7333 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7334 pci_name(pdev), pdev->vendor, pdev->device);
7335 return -EINVAL;
7336 }
7337
gouji-new9ce77662009-05-06 10:44:45 +00007338 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007339 if (err)
7340 return err;
7341
Nick Nunley1b507732010-04-27 13:10:27 +00007342 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7343 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007344 pci_using_dac = 1;
7345 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007346 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007347 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007348 err = dma_set_coherent_mask(&pdev->dev,
7349 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007350 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007351 dev_err(&pdev->dev,
7352 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007353 goto err_dma;
7354 }
7355 }
7356 pci_using_dac = 0;
7357 }
7358
gouji-new9ce77662009-05-06 10:44:45 +00007359 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007360 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007361 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007362 dev_err(&pdev->dev,
7363 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007364 goto err_pci_reg;
7365 }
7366
Frans Pop19d5afd2009-10-02 10:04:12 -07007367 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007368
Auke Kok9a799d72007-09-15 14:07:45 -07007369 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007370 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007371
John Fastabende901acd2011-04-26 07:26:08 +00007372#ifdef CONFIG_IXGBE_DCB
7373 indices *= MAX_TRAFFIC_CLASS;
7374#endif
7375
John Fastabendc85a2612010-02-25 23:15:21 +00007376 if (ii->mac == ixgbe_mac_82598EB)
7377 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7378 else
7379 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7380
John Fastabende901acd2011-04-26 07:26:08 +00007381#ifdef IXGBE_FCOE
John Fastabendc85a2612010-02-25 23:15:21 +00007382 indices += min_t(unsigned int, num_possible_cpus(),
7383 IXGBE_MAX_FCOE_INDICES);
7384#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007385 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007386 if (!netdev) {
7387 err = -ENOMEM;
7388 goto err_alloc_etherdev;
7389 }
7390
Auke Kok9a799d72007-09-15 14:07:45 -07007391 SET_NETDEV_DEV(netdev, &pdev->dev);
7392
Auke Kok9a799d72007-09-15 14:07:45 -07007393 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007394 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007395
7396 adapter->netdev = netdev;
7397 adapter->pdev = pdev;
7398 hw = &adapter->hw;
7399 hw->back = adapter;
7400 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7401
Jeff Kirsher05857982008-09-11 19:57:00 -07007402 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007403 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007404 if (!hw->hw_addr) {
7405 err = -EIO;
7406 goto err_ioremap;
7407 }
7408
7409 for (i = 1; i <= 5; i++) {
7410 if (pci_resource_len(pdev, i) == 0)
7411 continue;
7412 }
7413
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007414 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007415 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007416 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007417 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007418
Auke Kok9a799d72007-09-15 14:07:45 -07007419 adapter->bd_number = cards_found;
7420
Auke Kok9a799d72007-09-15 14:07:45 -07007421 /* Setup hw api */
7422 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007423 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007424
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007425 /* EEPROM */
7426 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7427 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7428 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7429 if (!(eec & (1 << 8)))
7430 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7431
7432 /* PHY */
7433 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007434 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007435 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7436 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7437 hw->phy.mdio.mmds = 0;
7438 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7439 hw->phy.mdio.dev = netdev;
7440 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7441 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007442
Don Skidmore8ca783a2009-05-26 20:40:47 -07007443 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007444
7445 /* setup the private structure */
7446 err = ixgbe_sw_init(adapter);
7447 if (err)
7448 goto err_sw_init;
7449
Don Skidmoree86bff02010-02-11 04:14:08 +00007450 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007451 switch (adapter->hw.mac.type) {
7452 case ixgbe_mac_82599EB:
7453 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007454 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007455 break;
7456 default:
7457 break;
7458 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007459
Don Skidmorebf069c92009-05-07 10:39:54 +00007460 /*
7461 * If there is a fan on this device and it has failed log the
7462 * failure.
7463 */
7464 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7465 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7466 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007467 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007468 }
7469
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007470 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007471 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007472 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007473 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007474 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7475 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007476 err = 0;
7477 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007478 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007479 "module type was detected.\n");
7480 e_dev_err("Reload the driver after installing a supported "
7481 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007482 goto err_sw_init;
7483 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007484 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007485 goto err_sw_init;
7486 }
7487
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007488 ixgbe_probe_vf(adapter, ii);
7489
Emil Tantilov396e7992010-07-01 20:05:12 +00007490 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007491 NETIF_F_IP_CSUM |
7492 NETIF_F_HW_VLAN_TX |
7493 NETIF_F_HW_VLAN_RX |
7494 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007495
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007496 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007497 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007498 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007499 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007500 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007501
Don Skidmore58be7662011-04-12 09:42:11 +00007502 switch (adapter->hw.mac.type) {
7503 case ixgbe_mac_82599EB:
7504 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007505 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007506 break;
7507 default:
7508 break;
7509 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007510
Jeff Kirsherad31c402008-06-05 04:05:30 -07007511 netdev->vlan_features |= NETIF_F_TSO;
7512 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007513 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007514 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007515 netdev->vlan_features |= NETIF_F_SG;
7516
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007517 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7518 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7519 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007520
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007521#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007522 netdev->dcbnl_ops = &dcbnl_ops;
7523#endif
7524
Yi Zoueacd73f2009-05-13 13:11:06 +00007525#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007526 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007527 if (hw->mac.ops.get_device_caps) {
7528 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007529 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7530 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007531 }
7532 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007533 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7534 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7535 netdev->vlan_features |= NETIF_F_FSO;
7536 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7537 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007538#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007539 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007540 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007541 netdev->vlan_features |= NETIF_F_HIGHDMA;
7542 }
Auke Kok9a799d72007-09-15 14:07:45 -07007543
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007544 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007545 netdev->features |= NETIF_F_LRO;
7546
Auke Kok9a799d72007-09-15 14:07:45 -07007547 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007548 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007549 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007550 err = -EIO;
7551 goto err_eeprom;
7552 }
7553
7554 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7555 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7556
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007557 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007558 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007559 err = -EIO;
7560 goto err_eeprom;
7561 }
7562
Don Skidmorec6ecf392010-12-03 03:31:51 +00007563 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7564 if (hw->mac.ops.disable_tx_laser &&
7565 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007566 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007567 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007568 hw->mac.ops.disable_tx_laser(hw);
7569
Alexander Duyck70864002011-04-27 09:13:56 +00007570 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7571 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007572
Alexander Duyck70864002011-04-27 09:13:56 +00007573 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7574 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007575
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007576 err = ixgbe_init_interrupt_scheme(adapter);
7577 if (err)
7578 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007579
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007580 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7581 netdev->features &= ~NETIF_F_RXHASH;
7582
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007583 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007584 case IXGBE_DEV_ID_82599_SFP:
7585 /* Only this subdevice supports WOL */
7586 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7587 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7588 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7589 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007590 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7591 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007592 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7593 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7594 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7595 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007596 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007597 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007598 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007599 break;
7600 default:
7601 adapter->wol = 0;
7602 break;
7603 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007604 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7605
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007606 /* pick up the PCI bus settings for reporting later */
7607 hw->mac.ops.get_bus_info(hw);
7608
Auke Kok9a799d72007-09-15 14:07:45 -07007609 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007610 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007611 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7612 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007613 "Unknown"),
7614 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7615 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7616 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7617 "Unknown"),
7618 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007619
7620 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7621 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007622 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007623 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007624 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007625 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007626 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007627 else
Don Skidmore289700db2010-12-03 03:32:58 +00007628 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7629 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007630
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007631 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007632 e_dev_warn("PCI-Express bandwidth available for this card is "
7633 "not sufficient for optimal performance.\n");
7634 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7635 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007636 }
7637
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007638 /* save off EEPROM version number */
7639 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7640
Auke Kok9a799d72007-09-15 14:07:45 -07007641 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007642 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007643
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007644 if (err == IXGBE_ERR_EEPROM_VERSION) {
7645 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007646 e_dev_warn("This device is a pre-production adapter/LOM. "
7647 "Please be aware there may be issues associated "
7648 "with your hardware. If you are experiencing "
7649 "problems please contact your Intel or hardware "
7650 "representative who provided you with this "
7651 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007652 }
Auke Kok9a799d72007-09-15 14:07:45 -07007653 strcpy(netdev->name, "eth%d");
7654 err = register_netdev(netdev);
7655 if (err)
7656 goto err_register;
7657
Jesse Brandeburg54386462009-04-17 20:44:27 +00007658 /* carrier off reporting is important to ethtool even BEFORE open */
7659 netif_carrier_off(netdev);
7660
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007661#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007662 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007663 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007664 ixgbe_setup_dca(adapter);
7665 }
7666#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007667 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007668 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007669 for (i = 0; i < adapter->num_vfs; i++)
7670 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7671 }
7672
Emil Tantilov9612de92011-05-07 07:40:20 +00007673 /* Inform firmware of driver version */
7674 if (hw->mac.ops.set_fw_drv_ver)
Don Skidmorea38a1042011-05-20 03:05:14 +00007675 hw->mac.ops.set_fw_drv_ver(hw, MAJ, MIN, BUILD,
7676 FW_CEM_UNUSED_VER);
Emil Tantilov9612de92011-05-07 07:40:20 +00007677
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007678 /* add san mac addr to netdev */
7679 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007680
Emil Tantilov849c4542010-06-03 16:53:41 +00007681 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007682 cards_found++;
7683 return 0;
7684
7685err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007686 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007687 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007688err_sw_init:
7689err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007690 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7691 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007692 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007693 iounmap(hw->hw_addr);
7694err_ioremap:
7695 free_netdev(netdev);
7696err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007697 pci_release_selected_regions(pdev,
7698 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007699err_pci_reg:
7700err_dma:
7701 pci_disable_device(pdev);
7702 return err;
7703}
7704
7705/**
7706 * ixgbe_remove - Device Removal Routine
7707 * @pdev: PCI device information struct
7708 *
7709 * ixgbe_remove is called by the PCI subsystem to alert the driver
7710 * that it should release a PCI device. The could be caused by a
7711 * Hot-Plug event, or because the driver is going to be removed from
7712 * memory.
7713 **/
7714static void __devexit ixgbe_remove(struct pci_dev *pdev)
7715{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007716 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7717 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007718
7719 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007720 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007721
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007722#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007723 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7724 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7725 dca_remove_requester(&pdev->dev);
7726 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7727 }
7728
7729#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007730#ifdef IXGBE_FCOE
7731 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7732 ixgbe_cleanup_fcoe(adapter);
7733
7734#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007735
7736 /* remove the added san mac */
7737 ixgbe_del_sanmac_netdev(netdev);
7738
Donald Skidmorec4900be2008-11-20 21:11:42 -08007739 if (netdev->reg_state == NETREG_REGISTERED)
7740 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007741
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007742 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7743 ixgbe_disable_sriov(adapter);
7744
Alexander Duyck7a921c92009-05-06 10:43:28 +00007745 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007746
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007747 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007748
7749 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007750 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007751 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007752
Emil Tantilov849c4542010-06-03 16:53:41 +00007753 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007754
Auke Kok9a799d72007-09-15 14:07:45 -07007755 free_netdev(netdev);
7756
Frans Pop19d5afd2009-10-02 10:04:12 -07007757 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007758
Auke Kok9a799d72007-09-15 14:07:45 -07007759 pci_disable_device(pdev);
7760}
7761
7762/**
7763 * ixgbe_io_error_detected - called when PCI error is detected
7764 * @pdev: Pointer to PCI device
7765 * @state: The current pci connection state
7766 *
7767 * This function is called after a PCI bus error affecting
7768 * this device has been detected.
7769 */
7770static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007771 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007772{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007773 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7774 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007775
7776 netif_device_detach(netdev);
7777
Breno Leitao3044b8d2009-05-06 10:44:26 +00007778 if (state == pci_channel_io_perm_failure)
7779 return PCI_ERS_RESULT_DISCONNECT;
7780
Auke Kok9a799d72007-09-15 14:07:45 -07007781 if (netif_running(netdev))
7782 ixgbe_down(adapter);
7783 pci_disable_device(pdev);
7784
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007785 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007786 return PCI_ERS_RESULT_NEED_RESET;
7787}
7788
7789/**
7790 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7791 * @pdev: Pointer to PCI device
7792 *
7793 * Restart the card from scratch, as if from a cold-boot.
7794 */
7795static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7796{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007797 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007798 pci_ers_result_t result;
7799 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007800
gouji-new9ce77662009-05-06 10:44:45 +00007801 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007802 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007803 result = PCI_ERS_RESULT_DISCONNECT;
7804 } else {
7805 pci_set_master(pdev);
7806 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007807 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007808
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007809 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007810
7811 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007812 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007813 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007814 }
Auke Kok9a799d72007-09-15 14:07:45 -07007815
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007816 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7817 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007818 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7819 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007820 /* non-fatal, continue */
7821 }
Auke Kok9a799d72007-09-15 14:07:45 -07007822
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007823 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007824}
7825
7826/**
7827 * ixgbe_io_resume - called when traffic can start flowing again.
7828 * @pdev: Pointer to PCI device
7829 *
7830 * This callback is called when the error recovery driver tells us that
7831 * its OK to resume normal operation.
7832 */
7833static void ixgbe_io_resume(struct pci_dev *pdev)
7834{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007835 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7836 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007837
7838 if (netif_running(netdev)) {
7839 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007840 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007841 return;
7842 }
7843 }
7844
7845 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007846}
7847
7848static struct pci_error_handlers ixgbe_err_handler = {
7849 .error_detected = ixgbe_io_error_detected,
7850 .slot_reset = ixgbe_io_slot_reset,
7851 .resume = ixgbe_io_resume,
7852};
7853
7854static struct pci_driver ixgbe_driver = {
7855 .name = ixgbe_driver_name,
7856 .id_table = ixgbe_pci_tbl,
7857 .probe = ixgbe_probe,
7858 .remove = __devexit_p(ixgbe_remove),
7859#ifdef CONFIG_PM
7860 .suspend = ixgbe_suspend,
7861 .resume = ixgbe_resume,
7862#endif
7863 .shutdown = ixgbe_shutdown,
7864 .err_handler = &ixgbe_err_handler
7865};
7866
7867/**
7868 * ixgbe_init_module - Driver Registration Routine
7869 *
7870 * ixgbe_init_module is the first routine called when the driver is
7871 * loaded. All it does is register with the PCI subsystem.
7872 **/
7873static int __init ixgbe_init_module(void)
7874{
7875 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007876 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007877 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007878
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007879#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007880 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007881#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007882
Auke Kok9a799d72007-09-15 14:07:45 -07007883 ret = pci_register_driver(&ixgbe_driver);
7884 return ret;
7885}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007886
Auke Kok9a799d72007-09-15 14:07:45 -07007887module_init(ixgbe_init_module);
7888
7889/**
7890 * ixgbe_exit_module - Driver Exit Cleanup Routine
7891 *
7892 * ixgbe_exit_module is called just before the driver is removed
7893 * from memory.
7894 **/
7895static void __exit ixgbe_exit_module(void)
7896{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007897#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007898 dca_unregister_notify(&dca_notifier);
7899#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007900 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007901 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007902}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007903
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007904#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007905static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007906 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007907{
7908 int ret_val;
7909
7910 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007911 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007912
7913 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7914}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007915
Alexander Duyckb4533682009-03-31 21:32:42 +00007916#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007917
Auke Kok9a799d72007-09-15 14:07:45 -07007918module_exit(ixgbe_exit_module);
7919
7920/* ixgbe_main.c */