blob: 7e3850ab4223c55a43c41c4bde941651d620dc44 [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>
Lucy Liu60127862009-07-22 14:07:33 +000038#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070039#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090040#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070041#include <net/checksum.h>
42#include <net/ip6_checksum.h>
43#include <linux/ethtool.h>
44#include <linux/if_vlan.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040045#include <linux/prefetch.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000046#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070047
48#include "ixgbe.h"
49#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000050#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000051#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070052
53char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070054static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000055 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000056#define MAJ 3
Don Skidmorec89c7112011-04-14 07:40:11 +000057#define MIN 3
58#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000059#define KFIX 2
60#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
61 __stringify(BUILD) "-k" __stringify(KFIX)
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070062const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000063static const char ixgbe_copyright[] =
64 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070065
66static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070067 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000068 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080069 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070070};
71
72/* ixgbe_pci_tbl - PCI Device ID Table
73 *
74 * Wildcard entries (PCI_ANY_ID) should come last
75 * Last entry must be all 0s
76 *
77 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
78 * Class, Class Mask, private data (not used) }
79 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000080static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
82 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070086 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
88 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
90 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070092 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
94 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080095 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
96 board_82598 },
97 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
98 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
100 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
102 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
104 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
106 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
108 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
110 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
112 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
114 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
116 board_82599 },
Peter P Waskiewicz 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
Yi Zou26f23d82009-11-06 12:56:00 +0000668/**
John Fastabendc84d3242010-11-16 19:27:12 -0800669 * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class
670 * @adapter: driver private struct
671 * @index: reg idx of queue to query (0-127)
Yi Zou26f23d82009-11-06 12:56:00 +0000672 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300673 * Helper function to determine the traffic index for a particular
John Fastabendc84d3242010-11-16 19:27:12 -0800674 * register index.
Yi Zou26f23d82009-11-06 12:56:00 +0000675 *
John Fastabendc84d3242010-11-16 19:27:12 -0800676 * Returns : a tc index for use in range 0-7, or 0-3
Yi Zou26f23d82009-11-06 12:56:00 +0000677 */
Don Skidmore3b2ee942011-01-28 02:28:26 +0000678static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx)
Yi Zou26f23d82009-11-06 12:56:00 +0000679{
John Fastabendc84d3242010-11-16 19:27:12 -0800680 int tc = -1;
John Fastabende5b64632011-03-08 03:44:52 +0000681 int dcb_i = netdev_get_num_tc(adapter->netdev);
Yi Zou26f23d82009-11-06 12:56:00 +0000682
John Fastabendc84d3242010-11-16 19:27:12 -0800683 /* if DCB is not enabled the queues have no TC */
684 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
685 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000686
John Fastabendc84d3242010-11-16 19:27:12 -0800687 /* check valid range */
688 if (reg_idx >= adapter->hw.mac.max_tx_queues)
689 return tc;
690
691 switch (adapter->hw.mac.type) {
692 case ixgbe_mac_82598EB:
693 tc = reg_idx >> 2;
694 break;
695 default:
696 if (dcb_i != 4 && dcb_i != 8)
PJ Waskiewicz6837e892010-01-06 17:50:29 +0000697 break;
John Fastabendc84d3242010-11-16 19:27:12 -0800698
699 /* if VMDq is enabled the lowest order bits determine TC */
700 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
701 IXGBE_FLAG_VMDQ_ENABLED)) {
702 tc = reg_idx & (dcb_i - 1);
Alexander Duyckbd508172010-11-16 19:27:03 -0800703 break;
Yi Zou26f23d82009-11-06 12:56:00 +0000704 }
John Fastabendc84d3242010-11-16 19:27:12 -0800705
706 /*
707 * Convert the reg_idx into the correct TC. This bitmask
708 * targets the last full 32 ring traffic class and assigns
709 * it a value of 1. From there the rest of the rings are
710 * based on shifting the mask further up to include the
711 * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i
712 * will only ever be 8 or 4 and that reg_idx will never
713 * be greater then 128. The code without the power of 2
714 * optimizations would be:
715 * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32)
716 */
717 tc = ((reg_idx & 0X1F) + 0x20) * dcb_i;
718 tc >>= 9 - (reg_idx >> 5);
Yi Zou26f23d82009-11-06 12:56:00 +0000719 }
John Fastabendc84d3242010-11-16 19:27:12 -0800720
721 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000722}
723
John Fastabendc84d3242010-11-16 19:27:12 -0800724static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700725{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700726 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800727 struct ixgbe_hw_stats *hwstats = &adapter->stats;
728 u32 data = 0;
729 u32 xoff[8] = {0};
730 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700731
John Fastabendc84d3242010-11-16 19:27:12 -0800732 if ((hw->fc.current_mode == ixgbe_fc_full) ||
733 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
734 switch (hw->mac.type) {
735 case ixgbe_mac_82598EB:
736 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
737 break;
738 default:
739 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
740 }
741 hwstats->lxoffrxc += data;
742
743 /* refill credits (no tx hang) if we received xoff */
744 if (!data)
745 return;
746
747 for (i = 0; i < adapter->num_tx_queues; i++)
748 clear_bit(__IXGBE_HANG_CHECK_ARMED,
749 &adapter->tx_ring[i]->state);
750 return;
751 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
752 return;
753
754 /* update stats for each tc, only valid with PFC enabled */
755 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
756 switch (hw->mac.type) {
757 case ixgbe_mac_82598EB:
758 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
759 break;
760 default:
761 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
762 }
763 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700764 }
765
John Fastabendc84d3242010-11-16 19:27:12 -0800766 /* disarm tx queues that have received xoff frames */
767 for (i = 0; i < adapter->num_tx_queues; i++) {
768 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
769 u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx);
770
771 if (xoff[tc])
772 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
773 }
774}
775
776static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
777{
778 return ring->tx_stats.completed;
779}
780
781static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
782{
783 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
784 struct ixgbe_hw *hw = &adapter->hw;
785
786 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
787 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
788
789 if (head != tail)
790 return (head < tail) ?
791 tail - head : (tail + ring->count - head);
792
793 return 0;
794}
795
796static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
797{
798 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
799 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
800 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
801 bool ret = false;
802
803 clear_check_for_tx_hang(tx_ring);
804
805 /*
806 * Check for a hung queue, but be thorough. This verifies
807 * that a transmit has been completed since the previous
808 * check AND there is at least one packet pending. The
809 * ARMED bit is set to indicate a potential hang. The
810 * bit is cleared if a pause frame is received to remove
811 * false hang detection due to PFC or 802.3x frames. By
812 * requiring this to fail twice we avoid races with
813 * pfc clearing the ARMED bit and conditions where we
814 * run the check_tx_hang logic with a transmit completion
815 * pending but without time to complete it yet.
816 */
817 if ((tx_done_old == tx_done) && tx_pending) {
818 /* make sure it is true for two checks in a row */
819 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
820 &tx_ring->state);
821 } else {
822 /* update completed stats and continue */
823 tx_ring->tx_stats.tx_done_old = tx_done;
824 /* reset the countdown */
825 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
826 }
827
828 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700829}
830
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700831#define IXGBE_MAX_TXD_PWR 14
832#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800833
834/* Tx Descriptors needed, worst case */
835#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
836 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
837#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700838 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800839
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000840/**
841 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
842 * @adapter: driver private struct
843 **/
844static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
845{
846
847 /* Do the reset outside of interrupt context */
848 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
849 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
850 ixgbe_service_event_schedule(adapter);
851 }
852}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700853
Auke Kok9a799d72007-09-15 14:07:45 -0700854/**
855 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000856 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700857 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700858 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000859static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000860 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700861{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000862 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800863 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
864 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700865 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800866 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700867
868 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800869 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000870 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800871
872 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000873 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800874 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000875 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800876 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000877 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700878 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700879
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800880 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800881 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800882
Auke Kok9a799d72007-09-15 14:07:45 -0700883 i++;
884 if (i == tx_ring->count)
885 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800886
887 if (cleaned && tx_buffer_info->skb) {
888 total_bytes += tx_buffer_info->bytecount;
889 total_packets += tx_buffer_info->gso_segs;
890 }
891
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800892 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800893 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700894 }
895
John Fastabendc84d3242010-11-16 19:27:12 -0800896 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800897 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000898 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800899 }
900
Auke Kok9a799d72007-09-15 14:07:45 -0700901 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800902 tx_ring->total_bytes += total_bytes;
903 tx_ring->total_packets += total_packets;
904 u64_stats_update_begin(&tx_ring->syncp);
905 tx_ring->stats.packets += total_packets;
906 tx_ring->stats.bytes += total_bytes;
907 u64_stats_update_end(&tx_ring->syncp);
908
John Fastabendc84d3242010-11-16 19:27:12 -0800909 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800910 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800911 struct ixgbe_hw *hw = &adapter->hw;
912 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
913 e_err(drv, "Detected Tx Unit Hang\n"
914 " Tx Queue <%d>\n"
915 " TDH, TDT <%x>, <%x>\n"
916 " next_to_use <%x>\n"
917 " next_to_clean <%x>\n"
918 "tx_buffer_info[next_to_clean]\n"
919 " time_stamp <%lx>\n"
920 " jiffies <%lx>\n",
921 tx_ring->queue_index,
922 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
923 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
924 tx_ring->next_to_use, eop,
925 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
926
927 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
928
929 e_info(probe,
930 "tx hang %d detected on queue %d, resetting adapter\n",
931 adapter->tx_timeout_count + 1, tx_ring->queue_index);
932
933 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000934 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800935
936 /* the adapter is about to reset, no point in enabling stuff */
937 return true;
938 }
Auke Kok9a799d72007-09-15 14:07:45 -0700939
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800940#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800941 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Joe Perchese8e9f692010-09-07 21:34:53 +0000942 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800943 /* Make sure that anybody stopping the queue after this
944 * sees the new next_to_clean.
945 */
946 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800947 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800948 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800949 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800950 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800951 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800952 }
Auke Kok9a799d72007-09-15 14:07:45 -0700953
Eric Dumazet807540b2010-09-23 05:40:09 +0000954 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700955}
956
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400957#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800958static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800959 struct ixgbe_ring *rx_ring,
960 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800961{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800963 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800964 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800965
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800966 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
967 switch (hw->mac.type) {
968 case ixgbe_mac_82598EB:
969 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
970 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
971 break;
972 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800973 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800974 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
975 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
976 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
977 break;
978 default:
979 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800980 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800981 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
982 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
983 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800984 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800985}
986
987static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800988 struct ixgbe_ring *tx_ring,
989 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800990{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000991 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800992 u32 txctrl;
993 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800994
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800995 switch (hw->mac.type) {
996 case ixgbe_mac_82598EB:
997 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
998 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
999 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
1000 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001001 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
1002 break;
1003 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001004 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001005 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
1006 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
1007 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
1008 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
1009 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001010 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
1011 break;
1012 default:
1013 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001014 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001015}
1016
1017static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1018{
1019 struct ixgbe_adapter *adapter = q_vector->adapter;
1020 int cpu = get_cpu();
1021 long r_idx;
1022 int i;
1023
1024 if (q_vector->cpu == cpu)
1025 goto out_no_update;
1026
1027 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1028 for (i = 0; i < q_vector->txr_count; i++) {
1029 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
1030 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1031 r_idx + 1);
1032 }
1033
1034 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1035 for (i = 0; i < q_vector->rxr_count; i++) {
1036 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1037 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1038 r_idx + 1);
1039 }
1040
1041 q_vector->cpu = cpu;
1042out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001043 put_cpu();
1044}
1045
1046static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1047{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001048 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001049 int i;
1050
1051 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1052 return;
1053
Alexander Duycke35ec122009-05-21 13:07:12 +00001054 /* always use CB2 mode, difference is masked in the CB driver */
1055 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1056
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001057 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1058 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1059 else
1060 num_q_vectors = 1;
1061
1062 for (i = 0; i < num_q_vectors; i++) {
1063 adapter->q_vector[i]->cpu = -1;
1064 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001065 }
1066}
1067
1068static int __ixgbe_notify_dca(struct device *dev, void *data)
1069{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001070 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001071 unsigned long event = *(unsigned long *)data;
1072
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001073 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1074 return 0;
1075
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001076 switch (event) {
1077 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001078 /* if we're already enabled, don't do it again */
1079 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1080 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001081 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001082 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001083 ixgbe_setup_dca(adapter);
1084 break;
1085 }
1086 /* Fall Through since DCA is disabled. */
1087 case DCA_PROVIDER_REMOVE:
1088 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1089 dca_remove_requester(dev);
1090 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1091 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1092 }
1093 break;
1094 }
1095
Denis V. Lunev652f0932008-03-27 14:39:17 +03001096 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001097}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001098#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001099
1100static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1101 struct sk_buff *skb)
1102{
1103 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1104}
1105
Auke Kok9a799d72007-09-15 14:07:45 -07001106/**
1107 * ixgbe_receive_skb - Send a completed packet up the stack
1108 * @adapter: board private structure
1109 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001110 * @status: hardware indication of status of receive
1111 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1112 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001113 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001114static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001115 struct sk_buff *skb, u8 status,
1116 struct ixgbe_ring *ring,
1117 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001118{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001119 struct ixgbe_adapter *adapter = q_vector->adapter;
1120 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001121 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1122 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001123
Jesse Grossf62bbb52010-10-20 13:56:10 +00001124 if (is_vlan && (tag & VLAN_VID_MASK))
1125 __vlan_hwaccel_put_tag(skb, tag);
1126
1127 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1128 napi_gro_receive(napi, skb);
1129 else
1130 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001131}
1132
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001133/**
1134 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1135 * @adapter: address of board private structure
1136 * @status_err: hardware indication of status of receive
1137 * @skb: skb currently being received and modified
1138 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001139static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001140 union ixgbe_adv_rx_desc *rx_desc,
1141 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001142{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001143 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1144
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001145 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001146
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001147 /* Rx csum disabled */
1148 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001149 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001150
1151 /* if IP and error */
1152 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1153 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001154 adapter->hw_csum_rx_error++;
1155 return;
1156 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001157
1158 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1159 return;
1160
1161 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001162 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1163
1164 /*
1165 * 82599 errata, UDP frames with a 0 checksum can be marked as
1166 * checksum errors.
1167 */
1168 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1169 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1170 return;
1171
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001172 adapter->hw_csum_rx_error++;
1173 return;
1174 }
1175
Auke Kok9a799d72007-09-15 14:07:45 -07001176 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001177 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001178}
1179
Alexander Duyck84ea2592010-11-16 19:26:49 -08001180static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001181{
1182 /*
1183 * Force memory writes to complete before letting h/w
1184 * know there are new descriptors to fetch. (Only
1185 * applicable for weak-ordered memory model archs,
1186 * such as IA-64).
1187 */
1188 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001189 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001190}
1191
Auke Kok9a799d72007-09-15 14:07:45 -07001192/**
1193 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001194 * @rx_ring: ring to place buffers on
1195 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001196 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001197void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001198{
Auke Kok9a799d72007-09-15 14:07:45 -07001199 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001200 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001201 struct sk_buff *skb;
1202 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001203
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001204 /* do nothing if no valid netdev defined */
1205 if (!rx_ring->netdev)
1206 return;
1207
Auke Kok9a799d72007-09-15 14:07:45 -07001208 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001209 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001210 bi = &rx_ring->rx_buffer_info[i];
1211 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001212
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001213 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001214 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001215 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001216 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001217 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001218 goto no_buffers;
1219 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001220 /* initialize queue mapping */
1221 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001222 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001223 }
Auke Kok9a799d72007-09-15 14:07:45 -07001224
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001225 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001226 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001227 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001228 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001229 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001230 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001231 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001232 bi->dma = 0;
1233 goto no_buffers;
1234 }
Auke Kok9a799d72007-09-15 14:07:45 -07001235 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001236
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001237 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001238 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001239 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001240 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001241 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001242 goto no_buffers;
1243 }
1244 }
1245
1246 if (!bi->page_dma) {
1247 /* use a half page if we're re-using */
1248 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001249 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001250 bi->page,
1251 bi->page_offset,
1252 PAGE_SIZE / 2,
1253 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001254 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001255 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001256 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001257 bi->page_dma = 0;
1258 goto no_buffers;
1259 }
1260 }
1261
1262 /* Refresh the desc even if buffer_addrs didn't change
1263 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001264 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1265 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001266 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001267 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001268 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001269 }
1270
1271 i++;
1272 if (i == rx_ring->count)
1273 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001274 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001275
Auke Kok9a799d72007-09-15 14:07:45 -07001276no_buffers:
1277 if (rx_ring->next_to_use != i) {
1278 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001279 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001280 }
1281}
1282
Alexander Duyckc267fc12010-11-16 19:27:00 -08001283static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001284{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001285 /* HW will not DMA in data larger than the given buffer, even if it
1286 * parses the (NFS, of course) header to be larger. In that case, it
1287 * fills the header buffer and spills the rest into the page.
1288 */
1289 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1290 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1291 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1292 if (hlen > IXGBE_RX_HDR_SIZE)
1293 hlen = IXGBE_RX_HDR_SIZE;
1294 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001295}
1296
Alexander Duyckf8212f92009-04-27 22:42:37 +00001297/**
1298 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1299 * @skb: pointer to the last skb in the rsc queue
1300 *
1301 * This function changes a queue full of hw rsc buffers into a completed
1302 * packet. It uses the ->prev pointers to find the first packet and then
1303 * turns it into the frag list owner.
1304 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001305static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001306{
1307 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001308 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001309
1310 while (skb->prev) {
1311 struct sk_buff *prev = skb->prev;
1312 frag_list_size += skb->len;
1313 skb->prev = NULL;
1314 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001315 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001316 }
1317
1318 skb_shinfo(skb)->frag_list = skb->next;
1319 skb->next = NULL;
1320 skb->len += frag_list_size;
1321 skb->data_len += frag_list_size;
1322 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001323 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1324
Alexander Duyckf8212f92009-04-27 22:42:37 +00001325 return skb;
1326}
1327
Alexander Duyckaa801752010-11-16 19:27:02 -08001328static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1329{
1330 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1331 IXGBE_RXDADV_RSCCNT_MASK);
1332}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001333
Alexander Duyckc267fc12010-11-16 19:27:00 -08001334static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001335 struct ixgbe_ring *rx_ring,
1336 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001337{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001338 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001339 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1340 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1341 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001342 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001343 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001344#ifdef IXGBE_FCOE
1345 int ddp_bytes = 0;
1346#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001347 u32 staterr;
1348 u16 i;
1349 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001350 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001351
1352 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001353 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001354 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001355
1356 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001357 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001358
Milton Miller3c945e52010-02-19 17:44:42 +00001359 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001360
Alexander Duyckc267fc12010-11-16 19:27:00 -08001361 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1362
Auke Kok9a799d72007-09-15 14:07:45 -07001363 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001364 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001365 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001366
Alexander Duyckc267fc12010-11-16 19:27:00 -08001367 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001368 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001369
1370 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001371 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001372 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001373 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001374 !(staterr & IXGBE_RXD_STAT_EOP) &&
1375 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001376 /*
1377 * When HWRSC is enabled, delay unmapping
1378 * of the first packet. It carries the
1379 * header information, HW may still
1380 * access the header after the writeback.
1381 * Only unmap it when EOP is reached
1382 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001383 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001384 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001385 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001386 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001387 rx_buffer_info->dma,
1388 rx_ring->rx_buf_len,
1389 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001390 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001391 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001392
1393 if (ring_is_ps_enabled(rx_ring)) {
1394 hlen = ixgbe_get_hlen(rx_desc);
1395 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1396 } else {
1397 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1398 }
1399
1400 skb_put(skb, hlen);
1401 } else {
1402 /* assume packet split since header is unmapped */
1403 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001404 }
1405
1406 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001407 dma_unmap_page(rx_ring->dev,
1408 rx_buffer_info->page_dma,
1409 PAGE_SIZE / 2,
1410 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001411 rx_buffer_info->page_dma = 0;
1412 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001413 rx_buffer_info->page,
1414 rx_buffer_info->page_offset,
1415 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001416
Alexander Duyckc267fc12010-11-16 19:27:00 -08001417 if ((page_count(rx_buffer_info->page) == 1) &&
1418 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001419 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001420 else
1421 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001422
1423 skb->len += upper_len;
1424 skb->data_len += upper_len;
1425 skb->truesize += upper_len;
1426 }
1427
1428 i++;
1429 if (i == rx_ring->count)
1430 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001431
Alexander Duyck31f05a22010-08-19 13:40:31 +00001432 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001433 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001434 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001435
Alexander Duyckaa801752010-11-16 19:27:02 -08001436 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001437 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1438 IXGBE_RXDADV_NEXTP_SHIFT;
1439 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001440 } else {
1441 next_buffer = &rx_ring->rx_buffer_info[i];
1442 }
1443
Alexander Duyckc267fc12010-11-16 19:27:00 -08001444 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001445 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001446 rx_buffer_info->skb = next_buffer->skb;
1447 rx_buffer_info->dma = next_buffer->dma;
1448 next_buffer->skb = skb;
1449 next_buffer->dma = 0;
1450 } else {
1451 skb->next = next_buffer->skb;
1452 skb->next->prev = skb;
1453 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001454 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001455 goto next_desc;
1456 }
1457
Alexander Duyckaa801752010-11-16 19:27:02 -08001458 if (skb->prev) {
1459 skb = ixgbe_transform_rsc_queue(skb);
1460 /* if we got here without RSC the packet is invalid */
1461 if (!pkt_is_rsc) {
1462 __pskb_trim(skb, 0);
1463 rx_buffer_info->skb = skb;
1464 goto next_desc;
1465 }
1466 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001467
1468 if (ring_is_rsc_enabled(rx_ring)) {
1469 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1470 dma_unmap_single(rx_ring->dev,
1471 IXGBE_RSC_CB(skb)->dma,
1472 rx_ring->rx_buf_len,
1473 DMA_FROM_DEVICE);
1474 IXGBE_RSC_CB(skb)->dma = 0;
1475 IXGBE_RSC_CB(skb)->delay_unmap = false;
1476 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001477 }
1478 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001479 if (ring_is_ps_enabled(rx_ring))
1480 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001481 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001482 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001483 rx_ring->rx_stats.rsc_count +=
1484 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001485 rx_ring->rx_stats.rsc_flush++;
1486 }
1487
1488 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001489 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001490 /* trim packet back to size 0 and recycle it */
1491 __pskb_trim(skb, 0);
1492 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001493 goto next_desc;
1494 }
1495
Don Skidmore8bae1b22009-07-23 18:00:39 +00001496 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001497 if (adapter->netdev->features & NETIF_F_RXHASH)
1498 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001499
1500 /* probably a little skewed due to removing CRC */
1501 total_rx_bytes += skb->len;
1502 total_rx_packets++;
1503
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001504 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001505#ifdef IXGBE_FCOE
1506 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001507 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1508 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1509 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001510 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001511 }
Yi Zou332d4a72009-05-13 13:11:53 +00001512#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001513 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001514
1515next_desc:
1516 rx_desc->wb.upper.status_error = 0;
1517
Alexander Duyckc267fc12010-11-16 19:27:00 -08001518 (*work_done)++;
1519 if (*work_done >= work_to_do)
1520 break;
1521
Auke Kok9a799d72007-09-15 14:07:45 -07001522 /* return some buffers to hardware, one at a time is too slow */
1523 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001524 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001525 cleaned_count = 0;
1526 }
1527
1528 /* use prefetched values */
1529 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001530 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001531 }
1532
Auke Kok9a799d72007-09-15 14:07:45 -07001533 rx_ring->next_to_clean = i;
1534 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1535
1536 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001537 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001538
Yi Zou3d8fd382009-06-08 14:38:44 +00001539#ifdef IXGBE_FCOE
1540 /* include DDPed FCoE data */
1541 if (ddp_bytes > 0) {
1542 unsigned int mss;
1543
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001544 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001545 sizeof(struct fc_frame_header) -
1546 sizeof(struct fcoe_crc_eof);
1547 if (mss > 512)
1548 mss &= ~511;
1549 total_rx_bytes += ddp_bytes;
1550 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1551 }
1552#endif /* IXGBE_FCOE */
1553
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001554 rx_ring->total_packets += total_rx_packets;
1555 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001556 u64_stats_update_begin(&rx_ring->syncp);
1557 rx_ring->stats.packets += total_rx_packets;
1558 rx_ring->stats.bytes += total_rx_bytes;
1559 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001560}
1561
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001562static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001563/**
1564 * ixgbe_configure_msix - Configure MSI-X hardware
1565 * @adapter: board private structure
1566 *
1567 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1568 * interrupts.
1569 **/
1570static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1571{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001572 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001573 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001574 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001575
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001576 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1577
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001578 /*
1579 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001580 * corresponding register.
1581 */
1582 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001583 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001584 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001585 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001586 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587
1588 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001589 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1590 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001591 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001592 adapter->num_rx_queues,
1593 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001594 }
1595 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001596 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001597
1598 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001599 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1600 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001601 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001602 adapter->num_tx_queues,
1603 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001604 }
1605
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001606 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001607 /* tx only */
1608 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001609 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001610 /* rx or mixed */
1611 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001612
Alexander Duyckfe49f042009-06-04 16:00:09 +00001613 ixgbe_write_eitr(q_vector);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001614 /* If Flow Director is enabled, set interrupt affinity */
1615 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1616 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1617 /*
1618 * Allocate the affinity_hint cpumask, assign the mask
1619 * for this vector, and set our affinity_hint for
1620 * this irq.
1621 */
1622 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1623 GFP_KERNEL))
1624 return;
1625 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1626 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1627 q_vector->affinity_mask);
1628 }
Auke Kok9a799d72007-09-15 14:07:45 -07001629 }
1630
Alexander Duyckbd508172010-11-16 19:27:03 -08001631 switch (adapter->hw.mac.type) {
1632 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001633 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001634 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001635 break;
1636 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001637 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001638 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001639 break;
1640
1641 default:
1642 break;
1643 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001644 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001645
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001646 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001647 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001648 if (adapter->num_vfs)
1649 mask &= ~(IXGBE_EIMS_OTHER |
1650 IXGBE_EIMS_MAILBOX |
1651 IXGBE_EIMS_LSC);
1652 else
1653 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001654 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001655}
1656
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001657enum latency_range {
1658 lowest_latency = 0,
1659 low_latency = 1,
1660 bulk_latency = 2,
1661 latency_invalid = 255
1662};
1663
1664/**
1665 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1666 * @adapter: pointer to adapter
1667 * @eitr: eitr setting (ints per sec) to give last timeslice
1668 * @itr_setting: current throttle rate in ints/second
1669 * @packets: the number of packets during this measurement interval
1670 * @bytes: the number of bytes during this measurement interval
1671 *
1672 * Stores a new ITR value based on packets and byte
1673 * counts during the last interrupt. The advantage of per interrupt
1674 * computation is faster updates and more accurate ITR for the current
1675 * traffic pattern. Constants in this function were computed
1676 * based on theoretical maximum wire speed and thresholds were set based
1677 * on testing data as well as attempting to minimize response time
1678 * while increasing bulk throughput.
1679 * this functionality is controlled by the InterruptThrottleRate module
1680 * parameter (see ixgbe_param.c)
1681 **/
1682static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001683 u32 eitr, u8 itr_setting,
1684 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001685{
1686 unsigned int retval = itr_setting;
1687 u32 timepassed_us;
1688 u64 bytes_perint;
1689
1690 if (packets == 0)
1691 goto update_itr_done;
1692
1693
1694 /* simple throttlerate management
1695 * 0-20MB/s lowest (100000 ints/s)
1696 * 20-100MB/s low (20000 ints/s)
1697 * 100-1249MB/s bulk (8000 ints/s)
1698 */
1699 /* what was last interrupt timeslice? */
1700 timepassed_us = 1000000/eitr;
1701 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1702
1703 switch (itr_setting) {
1704 case lowest_latency:
1705 if (bytes_perint > adapter->eitr_low)
1706 retval = low_latency;
1707 break;
1708 case low_latency:
1709 if (bytes_perint > adapter->eitr_high)
1710 retval = bulk_latency;
1711 else if (bytes_perint <= adapter->eitr_low)
1712 retval = lowest_latency;
1713 break;
1714 case bulk_latency:
1715 if (bytes_perint <= adapter->eitr_high)
1716 retval = low_latency;
1717 break;
1718 }
1719
1720update_itr_done:
1721 return retval;
1722}
1723
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001724/**
1725 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001726 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001727 *
1728 * This function is made to be called by ethtool and by the driver
1729 * when it needs to update EITR registers at runtime. Hardware
1730 * specific quirks/differences are taken care of here.
1731 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001732void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001733{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001734 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001735 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001736 int v_idx = q_vector->v_idx;
1737 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1738
Alexander Duyckbd508172010-11-16 19:27:03 -08001739 switch (adapter->hw.mac.type) {
1740 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001741 /* must write high and low 16 bits to reset counter */
1742 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001743 break;
1744 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001745 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001746 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001747 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001748 * max interrupt rate, but there is an errata where it can
1749 * not be zero with RSC
1750 */
1751 if (itr_reg == 8 &&
1752 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1753 itr_reg = 0;
1754
1755 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001756 * set the WDIS bit to not clear the timer bits and cause an
1757 * immediate assertion of the interrupt
1758 */
1759 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001760 break;
1761 default:
1762 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001763 }
1764 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1765}
1766
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001767static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1768{
1769 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001770 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771 u32 new_itr;
1772 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001773
1774 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1775 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001776 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001777 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001778 q_vector->tx_itr,
1779 tx_ring->total_packets,
1780 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001781 /* if the result for this queue would decrease interrupt
1782 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001783 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001784 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001785 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001786 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001787 }
1788
1789 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1790 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001791 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001792 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001793 q_vector->rx_itr,
1794 rx_ring->total_packets,
1795 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001796 /* if the result for this queue would decrease interrupt
1797 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001798 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001799 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001800 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001801 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001802 }
1803
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001804 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001805
1806 switch (current_itr) {
1807 /* counts and packets in update_itr are dependent on these numbers */
1808 case lowest_latency:
1809 new_itr = 100000;
1810 break;
1811 case low_latency:
1812 new_itr = 20000; /* aka hwitr = ~200 */
1813 break;
1814 case bulk_latency:
1815 default:
1816 new_itr = 8000;
1817 break;
1818 }
1819
1820 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001821 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001822 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001823
1824 /* save the algorithm value here, not the smoothed one */
1825 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001826
1827 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001828 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001829}
1830
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001831/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001832 * ixgbe_check_overtemp_subtask - check for over tempurature
1833 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001834 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001835static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001836{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001837 struct ixgbe_hw *hw = &adapter->hw;
1838 u32 eicr = adapter->interrupt_event;
1839
Alexander Duyckf0f97782011-04-22 04:08:09 +00001840 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001841 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001842
Alexander Duyckf0f97782011-04-22 04:08:09 +00001843 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1844 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1845 return;
1846
1847 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1848
Joe Perches7ca647b2010-09-07 21:35:40 +00001849 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001850 case IXGBE_DEV_ID_82599_T3_LOM:
1851 /*
1852 * Since the warning interrupt is for both ports
1853 * we don't have to check if:
1854 * - This interrupt wasn't for our port.
1855 * - We may have missed the interrupt so always have to
1856 * check if we got a LSC
1857 */
1858 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1859 !(eicr & IXGBE_EICR_LSC))
1860 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001861
Alexander Duyckf0f97782011-04-22 04:08:09 +00001862 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1863 u32 autoneg;
1864 bool link_up = false;
1865
Joe Perches7ca647b2010-09-07 21:35:40 +00001866 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1867
Alexander Duyckf0f97782011-04-22 04:08:09 +00001868 if (link_up)
1869 return;
1870 }
1871
1872 /* Check if this is not due to overtemp */
1873 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1874 return;
1875
1876 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001877 default:
1878 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1879 return;
1880 break;
1881 }
1882 e_crit(drv,
1883 "Network adapter has been stopped because it has over heated. "
1884 "Restart the computer. If the problem persists, "
1885 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001886
1887 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001888}
1889
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001890static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1891{
1892 struct ixgbe_hw *hw = &adapter->hw;
1893
1894 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1895 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001896 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001897 /* write to clear the interrupt */
1898 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1899 }
1900}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001901
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001902static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1903{
1904 struct ixgbe_hw *hw = &adapter->hw;
1905
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001906 if (eicr & IXGBE_EICR_GPI_SDP2) {
1907 /* Clear the interrupt */
1908 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001909 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1910 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1911 ixgbe_service_event_schedule(adapter);
1912 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001913 }
1914
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001915 if (eicr & IXGBE_EICR_GPI_SDP1) {
1916 /* Clear the interrupt */
1917 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001918 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1919 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1920 ixgbe_service_event_schedule(adapter);
1921 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001922 }
1923}
1924
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001925static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1926{
1927 struct ixgbe_hw *hw = &adapter->hw;
1928
1929 adapter->lsc_int++;
1930 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1931 adapter->link_check_timeout = jiffies;
1932 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1933 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001934 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001935 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001936 }
1937}
1938
Auke Kok9a799d72007-09-15 14:07:45 -07001939static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1940{
1941 struct net_device *netdev = data;
1942 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1943 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001944 u32 eicr;
1945
1946 /*
1947 * Workaround for Silicon errata. Use clear-by-write instead
1948 * of clear-by-read. Reading with EICS will return the
1949 * interrupt causes without clearing, which later be done
1950 * with the write to EICR.
1951 */
1952 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1953 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001954
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001955 if (eicr & IXGBE_EICR_LSC)
1956 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001957
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001958 if (eicr & IXGBE_EICR_MAILBOX)
1959 ixgbe_msg_task(adapter);
1960
Alexander Duyckbd508172010-11-16 19:27:03 -08001961 switch (hw->mac.type) {
1962 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001963 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001964 /* Handle Flow Director Full threshold interrupt */
1965 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001966 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001967 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001968 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001969 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001970 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001971 &ring->state))
1972 reinit_count++;
1973 }
1974 if (reinit_count) {
1975 /* no more flow director interrupts until after init */
1976 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1977 eicr &= ~IXGBE_EICR_FLOW_DIR;
1978 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1979 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001980 }
1981 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001982 ixgbe_check_sfp_event(adapter, eicr);
1983 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1984 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1985 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1986 adapter->interrupt_event = eicr;
1987 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1988 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001989 }
1990 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001991 break;
1992 default:
1993 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001994 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001995
1996 ixgbe_check_fan_failure(adapter, eicr);
1997
Alexander Duyck70864002011-04-27 09:13:56 +00001998 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001999 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00002000 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
2001 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07002002
2003 return IRQ_HANDLED;
2004}
2005
Alexander Duyckfe49f042009-06-04 16:00:09 +00002006static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2007 u64 qmask)
2008{
2009 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002010 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002011
Alexander Duyckbd508172010-11-16 19:27:03 -08002012 switch (hw->mac.type) {
2013 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002014 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002015 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2016 break;
2017 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002018 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002019 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002020 if (mask)
2021 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002022 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002023 if (mask)
2024 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2025 break;
2026 default:
2027 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002028 }
2029 /* skip the flush */
2030}
2031
2032static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002033 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002034{
2035 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002036 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002037
Alexander Duyckbd508172010-11-16 19:27:03 -08002038 switch (hw->mac.type) {
2039 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002040 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002041 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2042 break;
2043 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002044 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002045 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002046 if (mask)
2047 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002048 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002049 if (mask)
2050 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2051 break;
2052 default:
2053 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002054 }
2055 /* skip the flush */
2056}
2057
Auke Kok9a799d72007-09-15 14:07:45 -07002058static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2059{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002060 struct ixgbe_q_vector *q_vector = data;
2061 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002062 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002064
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002065 if (!q_vector->txr_count)
2066 return IRQ_HANDLED;
2067
2068 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2069 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002070 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002071 tx_ring->total_bytes = 0;
2072 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002073 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002074 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002075 }
2076
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002077 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002078 napi_schedule(&q_vector->napi);
2079
Auke Kok9a799d72007-09-15 14:07:45 -07002080 return IRQ_HANDLED;
2081}
2082
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002083/**
2084 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2085 * @irq: unused
2086 * @data: pointer to our q_vector struct for this interrupt vector
2087 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002088static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2089{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002090 struct ixgbe_q_vector *q_vector = data;
2091 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002092 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002093 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002094 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002095
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002096#ifdef CONFIG_IXGBE_DCA
2097 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2098 ixgbe_update_dca(q_vector);
2099#endif
2100
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002101 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002102 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002103 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002104 rx_ring->total_bytes = 0;
2105 rx_ring->total_packets = 0;
2106 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002107 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002108 }
2109
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002110 if (!q_vector->rxr_count)
2111 return IRQ_HANDLED;
2112
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002113 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002114 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002115
Auke Kok9a799d72007-09-15 14:07:45 -07002116 return IRQ_HANDLED;
2117}
2118
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002119static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2120{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002121 struct ixgbe_q_vector *q_vector = data;
2122 struct ixgbe_adapter *adapter = q_vector->adapter;
2123 struct ixgbe_ring *ring;
2124 int r_idx;
2125 int i;
2126
2127 if (!q_vector->txr_count && !q_vector->rxr_count)
2128 return IRQ_HANDLED;
2129
2130 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2131 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002132 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002133 ring->total_bytes = 0;
2134 ring->total_packets = 0;
2135 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002136 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002137 }
2138
2139 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2140 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002141 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002142 ring->total_bytes = 0;
2143 ring->total_packets = 0;
2144 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002145 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002146 }
2147
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002148 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002149 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002150
2151 return IRQ_HANDLED;
2152}
2153
2154/**
2155 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2156 * @napi: napi struct with our devices info in it
2157 * @budget: amount of work driver is allowed to do this pass, in packets
2158 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002159 * This function is optimized for cleaning one queue only on a single
2160 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002161 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002162static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2163{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002164 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002165 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002166 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002167 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002168 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002169 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002170
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002171#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002172 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002173 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002174#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002175
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002176 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2177 rx_ring = adapter->rx_ring[r_idx];
2178
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002179 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002180
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002181 /* If all Rx work done, exit the polling mode */
2182 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)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002185 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002186 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));
Auke Kok9a799d72007-09-15 14:07:45 -07002189 }
2190
2191 return work_done;
2192}
2193
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002194/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002195 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002196 * @napi: napi struct with our devices info in it
2197 * @budget: amount of work driver is allowed to do this pass, in packets
2198 *
2199 * This function will clean more than one rx queue associated with a
2200 * q_vector.
2201 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002202static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002203{
2204 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002205 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002206 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002207 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002208 int work_done = 0, i;
2209 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002210 bool tx_clean_complete = true;
2211
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002212#ifdef CONFIG_IXGBE_DCA
2213 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2214 ixgbe_update_dca(q_vector);
2215#endif
2216
Alexander Duyck91281fd2009-06-04 16:00:27 +00002217 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2218 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002219 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002220 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2221 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002222 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002223 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002224
2225 /* attempt to distribute budget to each queue fairly, but don't allow
2226 * the budget to go below 1 because we'll exit polling */
2227 budget /= (q_vector->rxr_count ?: 1);
2228 budget = max(budget, 1);
2229 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2230 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002231 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002232 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002233 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002234 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002235 }
2236
2237 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002238 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002239 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002240 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002241 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002242 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002243 ixgbe_set_itr_msix(q_vector);
2244 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002245 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002246 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002247 return 0;
2248 }
2249
2250 return work_done;
2251}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002252
2253/**
2254 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2255 * @napi: napi struct with our devices info in it
2256 * @budget: amount of work driver is allowed to do this pass, in packets
2257 *
2258 * This function is optimized for cleaning one queue only on a single
2259 * q_vector!!!
2260 **/
2261static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2262{
2263 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002264 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002265 struct ixgbe_adapter *adapter = q_vector->adapter;
2266 struct ixgbe_ring *tx_ring = NULL;
2267 int work_done = 0;
2268 long r_idx;
2269
Alexander Duyck91281fd2009-06-04 16:00:27 +00002270#ifdef CONFIG_IXGBE_DCA
2271 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002272 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002273#endif
2274
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002275 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2276 tx_ring = adapter->tx_ring[r_idx];
2277
Alexander Duyck91281fd2009-06-04 16:00:27 +00002278 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2279 work_done = budget;
2280
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002281 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002282 if (work_done < budget) {
2283 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002284 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002285 ixgbe_set_itr_msix(q_vector);
2286 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002287 ixgbe_irq_enable_queues(adapter,
2288 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002289 }
2290
2291 return work_done;
2292}
2293
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002294static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002295 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002296{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002297 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002298 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002299
2300 set_bit(r_idx, q_vector->rxr_idx);
2301 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002302 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002303}
Auke Kok9a799d72007-09-15 14:07:45 -07002304
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002306 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002307{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002308 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002309 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002310
2311 set_bit(t_idx, q_vector->txr_idx);
2312 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002313 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002314}
Auke Kok9a799d72007-09-15 14:07:45 -07002315
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002316/**
2317 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2318 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002319 *
2320 * This function maps descriptor rings to the queue-specific vectors
2321 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2322 * one vector per ring/queue, but on a constrained vector budget, we
2323 * group the rings as "efficiently" as possible. You would add new
2324 * mapping configurations in here.
2325 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002326static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002328 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002329 int v_start = 0;
2330 int rxr_idx = 0, txr_idx = 0;
2331 int rxr_remaining = adapter->num_rx_queues;
2332 int txr_remaining = adapter->num_tx_queues;
2333 int i, j;
2334 int rqpv, tqpv;
2335 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002336
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002337 /* No mapping required if MSI-X is disabled. */
2338 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002339 goto out;
2340
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002341 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2342
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002343 /*
2344 * The ideal configuration...
2345 * We have enough vectors to map one per queue.
2346 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002347 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002348 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2349 map_vector_to_rxq(adapter, v_start, rxr_idx);
2350
2351 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2352 map_vector_to_txq(adapter, v_start, txr_idx);
2353
2354 goto out;
2355 }
2356
2357 /*
2358 * If we don't have enough vectors for a 1-to-1
2359 * mapping, we'll have to group them so there are
2360 * multiple queues per vector.
2361 */
2362 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002363 for (i = v_start; i < q_vectors; i++) {
2364 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002365 for (j = 0; j < rqpv; j++) {
2366 map_vector_to_rxq(adapter, i, rxr_idx);
2367 rxr_idx++;
2368 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002369 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002370 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002371 for (j = 0; j < tqpv; j++) {
2372 map_vector_to_txq(adapter, i, txr_idx);
2373 txr_idx++;
2374 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002375 }
Auke Kok9a799d72007-09-15 14:07:45 -07002376 }
Auke Kok9a799d72007-09-15 14:07:45 -07002377out:
Auke Kok9a799d72007-09-15 14:07:45 -07002378 return err;
2379}
2380
2381/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002382 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2383 * @adapter: board private structure
2384 *
2385 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2386 * interrupts from the kernel.
2387 **/
2388static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2389{
2390 struct net_device *netdev = adapter->netdev;
2391 irqreturn_t (*handler)(int, void *);
2392 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002393 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002394
2395 /* Decrement for Other and TCP Timer vectors */
2396 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2397
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002398 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002399 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002400 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002401
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002402#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2403 ? &ixgbe_msix_clean_many : \
2404 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2405 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2406 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002407 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002408 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2409 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002410
Joe Perchese8e9f692010-09-07 21:34:53 +00002411 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002412 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2413 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002414 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002415 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2416 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002417 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002418 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2419 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002420 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002421 } else {
2422 /* skip this unused q_vector */
2423 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002424 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002425 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002426 handler, 0, q_vector->name,
2427 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002428 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002429 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002430 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002431 goto free_queue_irqs;
2432 }
2433 }
2434
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002435 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002436 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002437 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002438 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002439 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002440 goto free_queue_irqs;
2441 }
2442
2443 return 0;
2444
2445free_queue_irqs:
2446 for (i = vector - 1; i >= 0; i--)
2447 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002448 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002449 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2450 pci_disable_msix(adapter->pdev);
2451 kfree(adapter->msix_entries);
2452 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002453 return err;
2454}
2455
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002456static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2457{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002458 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002459 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2460 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002461 u32 new_itr = q_vector->eitr;
2462 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002463
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002464 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002465 q_vector->tx_itr,
2466 tx_ring->total_packets,
2467 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002468 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002469 q_vector->rx_itr,
2470 rx_ring->total_packets,
2471 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002472
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002473 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002474
2475 switch (current_itr) {
2476 /* counts and packets in update_itr are dependent on these numbers */
2477 case lowest_latency:
2478 new_itr = 100000;
2479 break;
2480 case low_latency:
2481 new_itr = 20000; /* aka hwitr = ~200 */
2482 break;
2483 case bulk_latency:
2484 new_itr = 8000;
2485 break;
2486 default:
2487 break;
2488 }
2489
2490 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002491 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002492 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002493
Alexander Duyck125601b2010-11-16 19:27:08 -08002494 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002495 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002496
2497 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002498 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002499}
2500
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002501/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002502 * ixgbe_irq_enable - Enable default interrupt generation settings
2503 * @adapter: board private structure
2504 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002505static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2506 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002507{
2508 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002509
2510 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002511 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2512 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002513 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2514 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002515 switch (adapter->hw.mac.type) {
2516 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002517 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002518 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002519 mask |= IXGBE_EIMS_GPI_SDP1;
2520 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002521 if (adapter->num_vfs)
2522 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002523 break;
2524 default:
2525 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002526 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002527 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2528 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2529 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002530
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002531 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002532 if (queues)
2533 ixgbe_irq_enable_queues(adapter, ~0);
2534 if (flush)
2535 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002536
2537 if (adapter->num_vfs > 32) {
2538 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2539 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2540 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002541}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002542
2543/**
2544 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002545 * @irq: interrupt number
2546 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002547 **/
2548static irqreturn_t ixgbe_intr(int irq, void *data)
2549{
2550 struct net_device *netdev = data;
2551 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2552 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002553 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002554 u32 eicr;
2555
Don Skidmore54037502009-02-21 15:42:56 -08002556 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002557 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002558 * before the read of EICR.
2559 */
2560 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2561
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002562 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2563 * therefore no explict interrupt disable is necessary */
2564 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002565 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002566 /*
2567 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002568 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002569 * have disabled interrupts due to EIAM
2570 * finish the workaround of silicon errata on 82598. Unmask
2571 * the interrupt that we masked before the EICR read.
2572 */
2573 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2574 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002575 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002576 }
Auke Kok9a799d72007-09-15 14:07:45 -07002577
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002578 if (eicr & IXGBE_EICR_LSC)
2579 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002580
Alexander Duyckbd508172010-11-16 19:27:03 -08002581 switch (hw->mac.type) {
2582 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002583 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002584 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2585 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002586 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2587 adapter->interrupt_event = eicr;
2588 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2589 ixgbe_service_event_schedule(adapter);
2590 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002591 }
2592 break;
2593 default:
2594 break;
2595 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002596
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002597 ixgbe_check_fan_failure(adapter, eicr);
2598
Alexander Duyck7a921c92009-05-06 10:43:28 +00002599 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002600 adapter->tx_ring[0]->total_packets = 0;
2601 adapter->tx_ring[0]->total_bytes = 0;
2602 adapter->rx_ring[0]->total_packets = 0;
2603 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002604 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002605 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002606 }
2607
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002608 /*
2609 * re-enable link(maybe) and non-queue interrupts, no flush.
2610 * ixgbe_poll will re-enable the queue interrupts
2611 */
2612
2613 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2614 ixgbe_irq_enable(adapter, false, false);
2615
Auke Kok9a799d72007-09-15 14:07:45 -07002616 return IRQ_HANDLED;
2617}
2618
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002619static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2620{
2621 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2622
2623 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002624 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002625 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2626 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2627 q_vector->rxr_count = 0;
2628 q_vector->txr_count = 0;
2629 }
2630}
2631
Auke Kok9a799d72007-09-15 14:07:45 -07002632/**
2633 * ixgbe_request_irq - initialize interrupts
2634 * @adapter: board private structure
2635 *
2636 * Attempts to configure interrupts using the best available
2637 * capabilities of the hardware and kernel.
2638 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002639static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002640{
2641 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002642 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002643
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002644 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2645 err = ixgbe_request_msix_irqs(adapter);
2646 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002647 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Joe Perchese8e9f692010-09-07 21:34:53 +00002648 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002649 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002650 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Joe Perchese8e9f692010-09-07 21:34:53 +00002651 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002652 }
2653
Auke Kok9a799d72007-09-15 14:07:45 -07002654 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002655 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002656
Auke Kok9a799d72007-09-15 14:07:45 -07002657 return err;
2658}
2659
2660static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2661{
2662 struct net_device *netdev = adapter->netdev;
2663
2664 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002666
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002667 q_vectors = adapter->num_msix_vectors;
2668
2669 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002670 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002671
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002672 i--;
2673 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002674 /* free only the irqs that were actually requested */
2675 if (!adapter->q_vector[i]->rxr_count &&
2676 !adapter->q_vector[i]->txr_count)
2677 continue;
2678
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002679 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002680 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002681 }
2682
2683 ixgbe_reset_q_vectors(adapter);
2684 } else {
2685 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002686 }
2687}
2688
2689/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002690 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2691 * @adapter: board private structure
2692 **/
2693static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2694{
Alexander Duyckbd508172010-11-16 19:27:03 -08002695 switch (adapter->hw.mac.type) {
2696 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002697 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002698 break;
2699 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002700 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002701 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2702 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002703 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002704 if (adapter->num_vfs > 32)
2705 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002706 break;
2707 default:
2708 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002709 }
2710 IXGBE_WRITE_FLUSH(&adapter->hw);
2711 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2712 int i;
2713 for (i = 0; i < adapter->num_msix_vectors; i++)
2714 synchronize_irq(adapter->msix_entries[i].vector);
2715 } else {
2716 synchronize_irq(adapter->pdev->irq);
2717 }
2718}
2719
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002720/**
Auke Kok9a799d72007-09-15 14:07:45 -07002721 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2722 *
2723 **/
2724static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2725{
Auke Kok9a799d72007-09-15 14:07:45 -07002726 struct ixgbe_hw *hw = &adapter->hw;
2727
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002728 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002729 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002730
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002731 ixgbe_set_ivar(adapter, 0, 0, 0);
2732 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002733
2734 map_vector_to_rxq(adapter, 0, 0);
2735 map_vector_to_txq(adapter, 0, 0);
2736
Emil Tantilov396e7992010-07-01 20:05:12 +00002737 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002738}
2739
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002740/**
2741 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2742 * @adapter: board private structure
2743 * @ring: structure containing ring specific data
2744 *
2745 * Configure the Tx descriptor ring after a reset.
2746 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002747void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2748 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002749{
2750 struct ixgbe_hw *hw = &adapter->hw;
2751 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002752 int wait_loop = 10;
2753 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002754 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002755
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002756 /* disable queue to avoid issues while updating state */
2757 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2758 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2759 txdctl & ~IXGBE_TXDCTL_ENABLE);
2760 IXGBE_WRITE_FLUSH(hw);
2761
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002762 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002763 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002764 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2765 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2766 ring->count * sizeof(union ixgbe_adv_tx_desc));
2767 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2768 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002769 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002770
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002771 /* configure fetching thresholds */
2772 if (adapter->rx_itr_setting == 0) {
2773 /* cannot set wthresh when itr==0 */
2774 txdctl &= ~0x007F0000;
2775 } else {
2776 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2777 txdctl |= (8 << 16);
2778 }
2779 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2780 /* PThresh workaround for Tx hang with DFP enabled. */
2781 txdctl |= 32;
2782 }
2783
2784 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002785 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2786 adapter->atr_sample_rate) {
2787 ring->atr_sample_rate = adapter->atr_sample_rate;
2788 ring->atr_count = 0;
2789 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2790 } else {
2791 ring->atr_sample_rate = 0;
2792 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002793
John Fastabendc84d3242010-11-16 19:27:12 -08002794 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2795
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002796 /* enable queue */
2797 txdctl |= IXGBE_TXDCTL_ENABLE;
2798 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2799
2800 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2801 if (hw->mac.type == ixgbe_mac_82598EB &&
2802 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2803 return;
2804
2805 /* poll to verify queue is enabled */
2806 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002807 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002808 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2809 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2810 if (!wait_loop)
2811 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002812}
2813
Alexander Duyck120ff942010-08-19 13:34:50 +00002814static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2815{
2816 struct ixgbe_hw *hw = &adapter->hw;
2817 u32 rttdcs;
John Fastabend72a32f12011-04-26 07:25:58 +00002818 u32 reg;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002819 u8 tcs = netdev_get_num_tc(adapter->netdev);
Alexander Duyck120ff942010-08-19 13:34:50 +00002820
2821 if (hw->mac.type == ixgbe_mac_82598EB)
2822 return;
2823
2824 /* disable the arbiter while setting MTQC */
2825 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2826 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2827 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2828
2829 /* set transmit pool layout */
John Fastabend8b1c0b22011-05-03 02:26:48 +00002830 switch (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Alexander Duyck120ff942010-08-19 13:34:50 +00002831 case (IXGBE_FLAG_SRIOV_ENABLED):
2832 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2833 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2834 break;
Alexander Duyck120ff942010-08-19 13:34:50 +00002835 default:
John Fastabend8b1c0b22011-05-03 02:26:48 +00002836 if (!tcs)
2837 reg = IXGBE_MTQC_64Q_1PB;
2838 else if (tcs <= 4)
2839 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_4TC_4TQ;
2840 else
2841 reg = IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ;
2842
2843 IXGBE_WRITE_REG(hw, IXGBE_MTQC, reg);
2844
2845 /* Enable Security TX Buffer IFG for multiple pb */
2846 if (tcs) {
2847 reg = IXGBE_READ_REG(hw, IXGBE_SECTXMINIFG);
2848 reg |= IXGBE_SECTX_DCB;
2849 IXGBE_WRITE_REG(hw, IXGBE_SECTXMINIFG, reg);
2850 }
Alexander Duyck120ff942010-08-19 13:34:50 +00002851 break;
2852 }
2853
2854 /* re-enable the arbiter */
2855 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2856 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2857}
2858
Auke Kok9a799d72007-09-15 14:07:45 -07002859/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002860 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002861 * @adapter: board private structure
2862 *
2863 * Configure the Tx unit of the MAC after a reset.
2864 **/
2865static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2866{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002867 struct ixgbe_hw *hw = &adapter->hw;
2868 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002869 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002870
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002871 ixgbe_setup_mtqc(adapter);
2872
2873 if (hw->mac.type != ixgbe_mac_82598EB) {
2874 /* DMATXCTL.EN must be before Tx queues are enabled */
2875 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2876 dmatxctl |= IXGBE_DMATXCTL_TE;
2877 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2878 }
2879
Auke Kok9a799d72007-09-15 14:07:45 -07002880 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002881 for (i = 0; i < adapter->num_tx_queues; i++)
2882 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002883}
2884
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002885#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002886
Yi Zoua6616b42009-08-06 13:05:23 +00002887static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002888 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002889{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002890 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002891 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002892
Alexander Duyckbd508172010-11-16 19:27:03 -08002893 switch (adapter->hw.mac.type) {
2894 case ixgbe_mac_82598EB: {
2895 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2896 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002897 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002898 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002899 break;
2900 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002901 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002902 default:
2903 break;
2904 }
2905
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002906 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002907
2908 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2909 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002910 if (adapter->num_vfs)
2911 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002912
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002913 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2914 IXGBE_SRRCTL_BSIZEHDR_MASK;
2915
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002916 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002917#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2918 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2919#else
2920 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2921#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002922 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002923 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002924 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2925 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002926 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002927 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002928
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002929 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002930}
2931
Alexander Duyck05abb122010-08-19 13:35:41 +00002932static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002933{
Alexander Duyck05abb122010-08-19 13:35:41 +00002934 struct ixgbe_hw *hw = &adapter->hw;
2935 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002936 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2937 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002938 u32 mrqc = 0, reta = 0;
2939 u32 rxcsum;
2940 int i, j;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002941 u8 tcs = netdev_get_num_tc(adapter->netdev);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002942
Alexander Duyck05abb122010-08-19 13:35:41 +00002943 /* Fill out hash function seeds */
2944 for (i = 0; i < 10; i++)
2945 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002946
Alexander Duyck05abb122010-08-19 13:35:41 +00002947 /* Fill out redirection table */
2948 for (i = 0, j = 0; i < 128; i++, j++) {
2949 if (j == adapter->ring_feature[RING_F_RSS].indices)
2950 j = 0;
2951 /* reta = 4-byte sliding window of
2952 * 0x00..(indices-1)(indices-1)00..etc. */
2953 reta = (reta << 8) | (j * 0x11);
2954 if ((i & 3) == 3)
2955 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2956 }
2957
2958 /* Disable indicating checksum in descriptor, enables RSS hash */
2959 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2960 rxcsum |= IXGBE_RXCSUM_PCSD;
2961 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2962
John Fastabend8b1c0b22011-05-03 02:26:48 +00002963 if (adapter->hw.mac.type == ixgbe_mac_82598EB &&
2964 (adapter->flags & IXGBE_FLAG_RSS_ENABLED)) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002965 mrqc = IXGBE_MRQC_RSSEN;
John Fastabend8b1c0b22011-05-03 02:26:48 +00002966 } else {
2967 int mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
2968 | IXGBE_FLAG_SRIOV_ENABLED);
2969
2970 switch (mask) {
2971 case (IXGBE_FLAG_RSS_ENABLED):
2972 if (!tcs)
2973 mrqc = IXGBE_MRQC_RSSEN;
2974 else if (tcs <= 4)
2975 mrqc = IXGBE_MRQC_RTRSS4TCEN;
2976 else
2977 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2978 break;
2979 case (IXGBE_FLAG_SRIOV_ENABLED):
2980 mrqc = IXGBE_MRQC_VMDQEN;
2981 break;
2982 default:
2983 break;
2984 }
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002985 }
2986
Alexander Duyck05abb122010-08-19 13:35:41 +00002987 /* Perform hash on these packet types */
2988 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2989 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2990 | IXGBE_MRQC_RSS_FIELD_IPV6
2991 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2992
2993 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002994}
2995
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002996/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002997 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2998 * @adapter: address of board private structure
2999 * @ring: structure containing ring specific data
3000 **/
3001void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
3002 struct ixgbe_ring *ring)
3003{
3004 struct ixgbe_hw *hw = &adapter->hw;
3005 u32 rscctrl;
3006 u8 reg_idx = ring->reg_idx;
3007
3008 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3009 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
3010 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3011}
3012
3013/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003014 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3015 * @adapter: address of board private structure
3016 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003017 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08003018void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003019 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003020{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003021 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003022 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08003023 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003024 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003025
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003026 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003027 return;
3028
3029 rx_buf_len = ring->rx_buf_len;
3030 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003031 rscctrl |= IXGBE_RSCCTL_RSCEN;
3032 /*
3033 * we must limit the number of descriptors so that the
3034 * total size of max desc * buf_len is not greater
3035 * than 65535
3036 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003037 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003038#if (MAX_SKB_FRAGS > 16)
3039 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3040#elif (MAX_SKB_FRAGS > 8)
3041 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3042#elif (MAX_SKB_FRAGS > 4)
3043 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3044#else
3045 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3046#endif
3047 } else {
3048 if (rx_buf_len < IXGBE_RXBUFFER_4096)
3049 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3050 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
3051 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3052 else
3053 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3054 }
Alexander Duyck73670962010-08-19 13:38:34 +00003055 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003056}
3057
Alexander Duyck9e10e042010-08-19 13:40:06 +00003058/**
3059 * ixgbe_set_uta - Set unicast filter table address
3060 * @adapter: board private structure
3061 *
3062 * The unicast table address is a register array of 32-bit registers.
3063 * The table is meant to be used in a way similar to how the MTA is used
3064 * however due to certain limitations in the hardware it is necessary to
3065 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3066 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3067 **/
3068static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3069{
3070 struct ixgbe_hw *hw = &adapter->hw;
3071 int i;
3072
3073 /* The UTA table only exists on 82599 hardware and newer */
3074 if (hw->mac.type < ixgbe_mac_82599EB)
3075 return;
3076
3077 /* we only need to do this if VMDq is enabled */
3078 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3079 return;
3080
3081 for (i = 0; i < 128; i++)
3082 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3083}
3084
3085#define IXGBE_MAX_RX_DESC_POLL 10
3086static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3087 struct ixgbe_ring *ring)
3088{
3089 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003090 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3091 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003092 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003093
3094 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3095 if (hw->mac.type == ixgbe_mac_82598EB &&
3096 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3097 return;
3098
3099 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003100 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003101 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3102 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3103
3104 if (!wait_loop) {
3105 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3106 "the polling period\n", reg_idx);
3107 }
3108}
3109
Yi Zou2d39d572011-01-06 14:29:56 +00003110void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3111 struct ixgbe_ring *ring)
3112{
3113 struct ixgbe_hw *hw = &adapter->hw;
3114 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3115 u32 rxdctl;
3116 u8 reg_idx = ring->reg_idx;
3117
3118 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3119 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3120
3121 /* write value back with RXDCTL.ENABLE bit cleared */
3122 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3123
3124 if (hw->mac.type == ixgbe_mac_82598EB &&
3125 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3126 return;
3127
3128 /* the hardware may take up to 100us to really disable the rx queue */
3129 do {
3130 udelay(10);
3131 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3132 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3133
3134 if (!wait_loop) {
3135 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3136 "the polling period\n", reg_idx);
3137 }
3138}
3139
Alexander Duyck84418e32010-08-19 13:40:54 +00003140void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3141 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003142{
3143 struct ixgbe_hw *hw = &adapter->hw;
3144 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003145 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003146 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003147
Alexander Duyck9e10e042010-08-19 13:40:06 +00003148 /* disable queue to avoid issues while updating state */
3149 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003150 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003151
Alexander Duyckacd37172010-08-19 13:36:05 +00003152 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3153 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3154 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3155 ring->count * sizeof(union ixgbe_adv_rx_desc));
3156 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3157 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003158 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003159
3160 ixgbe_configure_srrctl(adapter, ring);
3161 ixgbe_configure_rscctl(adapter, ring);
3162
Greg Rosee9f98072011-01-26 01:06:07 +00003163 /* If operating in IOV mode set RLPML for X540 */
3164 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3165 hw->mac.type == ixgbe_mac_X540) {
3166 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3167 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3168 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3169 }
3170
Alexander Duyck9e10e042010-08-19 13:40:06 +00003171 if (hw->mac.type == ixgbe_mac_82598EB) {
3172 /*
3173 * enable cache line friendly hardware writes:
3174 * PTHRESH=32 descriptors (half the internal cache),
3175 * this also removes ugly rx_no_buffer_count increment
3176 * HTHRESH=4 descriptors (to minimize latency on fetch)
3177 * WTHRESH=8 burst writeback up to two cache lines
3178 */
3179 rxdctl &= ~0x3FFFFF;
3180 rxdctl |= 0x080420;
3181 }
3182
3183 /* enable receive descriptor ring */
3184 rxdctl |= IXGBE_RXDCTL_ENABLE;
3185 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3186
3187 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08003188 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003189}
3190
Alexander Duyck48654522010-08-19 13:36:27 +00003191static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3192{
3193 struct ixgbe_hw *hw = &adapter->hw;
3194 int p;
3195
3196 /* PSRTYPE must be initialized in non 82598 adapters */
3197 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003198 IXGBE_PSRTYPE_UDPHDR |
3199 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003200 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003201 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003202
3203 if (hw->mac.type == ixgbe_mac_82598EB)
3204 return;
3205
3206 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3207 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3208
3209 for (p = 0; p < adapter->num_rx_pools; p++)
3210 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3211 psrtype);
3212}
3213
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003214static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3215{
3216 struct ixgbe_hw *hw = &adapter->hw;
3217 u32 gcr_ext;
3218 u32 vt_reg_bits;
3219 u32 reg_offset, vf_shift;
3220 u32 vmdctl;
3221
3222 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3223 return;
3224
3225 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3226 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3227 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3228 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3229
3230 vf_shift = adapter->num_vfs % 32;
3231 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3232
3233 /* Enable only the PF's pool for Tx/Rx */
3234 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3235 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3236 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3237 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3238 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3239
3240 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3241 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3242
3243 /*
3244 * Set up VF register offsets for selected VT Mode,
3245 * i.e. 32 or 64 VFs for SR-IOV
3246 */
3247 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3248 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3249 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3250 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3251
3252 /* enable Tx loopback for VF/PF communication */
3253 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003254 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003255 hw->mac.ops.set_mac_anti_spoofing(hw,
3256 (adapter->antispoofing_enabled =
3257 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003258 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003259}
3260
Alexander Duyck477de6e2010-08-19 13:38:11 +00003261static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003262{
Auke Kok9a799d72007-09-15 14:07:45 -07003263 struct ixgbe_hw *hw = &adapter->hw;
3264 struct net_device *netdev = adapter->netdev;
3265 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003266 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003267 struct ixgbe_ring *rx_ring;
3268 int i;
3269 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003270
Auke Kok9a799d72007-09-15 14:07:45 -07003271 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003272 /* On by default */
3273 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3274
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003275 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003276 if (adapter->num_vfs)
3277 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3278
3279 /* Disable packet split due to 82599 erratum #45 */
3280 if (hw->mac.type == ixgbe_mac_82599EB)
3281 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003282
3283 /* Set the RX buffer length according to the mode */
3284 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003285 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003286 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003287 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003288 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003289 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003290 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003291 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3292 }
3293
3294#ifdef IXGBE_FCOE
3295 /* adjust max frame to be able to do baby jumbo for FCoE */
3296 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3297 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3298 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3299
3300#endif /* IXGBE_FCOE */
3301 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3302 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3303 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3304 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3305
3306 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003307 }
3308
Auke Kok9a799d72007-09-15 14:07:45 -07003309 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003310 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3311 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003312 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3313
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003314 /*
3315 * Setup the HW Rx Head and Tail Descriptor Pointers and
3316 * the Base and Length of the Rx Descriptor Ring
3317 */
Auke Kok9a799d72007-09-15 14:07:45 -07003318 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003319 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003320 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003321
Yi Zou6e455b892009-08-06 13:05:44 +00003322 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003323 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003324 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003325 clear_ring_ps_enabled(rx_ring);
3326
3327 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3328 set_ring_rsc_enabled(rx_ring);
3329 else
3330 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003331
Yi Zou63f39bd2009-05-17 12:34:35 +00003332#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003333 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003334 struct ixgbe_ring_feature *f;
3335 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003336 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003337 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003338 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3339 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003340 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003341 } else if (!ring_is_rsc_enabled(rx_ring) &&
3342 !ring_is_ps_enabled(rx_ring)) {
3343 rx_ring->rx_buf_len =
3344 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003345 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003346 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003347#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003348 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003349}
3350
Alexander Duyck73670962010-08-19 13:38:34 +00003351static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3352{
3353 struct ixgbe_hw *hw = &adapter->hw;
3354 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3355
3356 switch (hw->mac.type) {
3357 case ixgbe_mac_82598EB:
3358 /*
3359 * For VMDq support of different descriptor types or
3360 * buffer sizes through the use of multiple SRRCTL
3361 * registers, RDRXCTL.MVMEN must be set to 1
3362 *
3363 * also, the manual doesn't mention it clearly but DCA hints
3364 * will only use queue 0's tags unless this bit is set. Side
3365 * effects of setting this bit are only that SRRCTL must be
3366 * fully programmed [0..15]
3367 */
3368 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3369 break;
3370 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003371 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003372 /* Disable RSC for ACK packets */
3373 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3374 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3375 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3376 /* hardware requires some bits to be set by default */
3377 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3378 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3379 break;
3380 default:
3381 /* We should do nothing since we don't know this hardware */
3382 return;
3383 }
3384
3385 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3386}
3387
Alexander Duyck477de6e2010-08-19 13:38:11 +00003388/**
3389 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3390 * @adapter: board private structure
3391 *
3392 * Configure the Rx unit of the MAC after a reset.
3393 **/
3394static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3395{
3396 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003397 int i;
3398 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003399
3400 /* disable receives while setting up the descriptors */
3401 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3402 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3403
3404 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003405 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003406
Alexander Duyck9e10e042010-08-19 13:40:06 +00003407 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003408 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003409
Alexander Duyck9e10e042010-08-19 13:40:06 +00003410 ixgbe_set_uta(adapter);
3411
Alexander Duyck477de6e2010-08-19 13:38:11 +00003412 /* set_rx_buffer_len must be called before ring initialization */
3413 ixgbe_set_rx_buffer_len(adapter);
3414
3415 /*
3416 * Setup the HW Rx Head and Tail Descriptor Pointers and
3417 * the Base and Length of the Rx Descriptor Ring
3418 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003419 for (i = 0; i < adapter->num_rx_queues; i++)
3420 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003421
Alexander Duyck9e10e042010-08-19 13:40:06 +00003422 /* disable drop enable for 82598 parts */
3423 if (hw->mac.type == ixgbe_mac_82598EB)
3424 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3425
3426 /* enable all receives */
3427 rxctrl |= IXGBE_RXCTRL_RXEN;
3428 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003429}
3430
Auke Kok9a799d72007-09-15 14:07:45 -07003431static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3432{
3433 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003434 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003435 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003436
3437 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003438 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003439 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003440}
3441
3442static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3443{
3444 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003445 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003446 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003447
Auke Kok9a799d72007-09-15 14:07:45 -07003448 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003449 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003450 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003451}
3452
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003453/**
3454 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3455 * @adapter: driver data
3456 */
3457static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3458{
3459 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003460 u32 vlnctrl;
3461
3462 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3463 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3464 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3465}
3466
3467/**
3468 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3469 * @adapter: driver data
3470 */
3471static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3472{
3473 struct ixgbe_hw *hw = &adapter->hw;
3474 u32 vlnctrl;
3475
3476 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3477 vlnctrl |= IXGBE_VLNCTRL_VFE;
3478 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3479 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3480}
3481
3482/**
3483 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3484 * @adapter: driver data
3485 */
3486static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3487{
3488 struct ixgbe_hw *hw = &adapter->hw;
3489 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003490 int i, j;
3491
3492 switch (hw->mac.type) {
3493 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003494 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3495 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003496 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3497 break;
3498 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003499 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003500 for (i = 0; i < adapter->num_rx_queues; i++) {
3501 j = adapter->rx_ring[i]->reg_idx;
3502 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3503 vlnctrl &= ~IXGBE_RXDCTL_VME;
3504 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3505 }
3506 break;
3507 default:
3508 break;
3509 }
3510}
3511
3512/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003513 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003514 * @adapter: driver data
3515 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003516static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003517{
3518 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003519 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003520 int i, j;
3521
3522 switch (hw->mac.type) {
3523 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003524 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3525 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003526 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3527 break;
3528 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003529 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003530 for (i = 0; i < adapter->num_rx_queues; i++) {
3531 j = adapter->rx_ring[i]->reg_idx;
3532 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3533 vlnctrl |= IXGBE_RXDCTL_VME;
3534 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3535 }
3536 break;
3537 default:
3538 break;
3539 }
3540}
3541
Auke Kok9a799d72007-09-15 14:07:45 -07003542static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3543{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003544 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003545
Jesse Grossf62bbb52010-10-20 13:56:10 +00003546 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3547
3548 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3549 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003550}
3551
3552/**
Alexander Duyck28500622010-06-15 09:25:48 +00003553 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3554 * @netdev: network interface device structure
3555 *
3556 * Writes unicast address list to the RAR table.
3557 * Returns: -ENOMEM on failure/insufficient address space
3558 * 0 on no addresses written
3559 * X on writing X addresses to the RAR table
3560 **/
3561static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3562{
3563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3564 struct ixgbe_hw *hw = &adapter->hw;
3565 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003566 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003567 int count = 0;
3568
3569 /* return ENOMEM indicating insufficient memory for addresses */
3570 if (netdev_uc_count(netdev) > rar_entries)
3571 return -ENOMEM;
3572
3573 if (!netdev_uc_empty(netdev) && rar_entries) {
3574 struct netdev_hw_addr *ha;
3575 /* return error if we do not support writing to RAR table */
3576 if (!hw->mac.ops.set_rar)
3577 return -ENOMEM;
3578
3579 netdev_for_each_uc_addr(ha, netdev) {
3580 if (!rar_entries)
3581 break;
3582 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3583 vfn, IXGBE_RAH_AV);
3584 count++;
3585 }
3586 }
3587 /* write the addresses in reverse order to avoid write combining */
3588 for (; rar_entries > 0 ; rar_entries--)
3589 hw->mac.ops.clear_rar(hw, rar_entries);
3590
3591 return count;
3592}
3593
3594/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003595 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003596 * @netdev: network interface device structure
3597 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003598 * The set_rx_method entry point is called whenever the unicast/multicast
3599 * address list or the network interface flags are updated. This routine is
3600 * responsible for configuring the hardware for proper unicast, multicast and
3601 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003602 **/
Greg Rose7f870472010-01-09 02:25:29 +00003603void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003604{
3605 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3606 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003607 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3608 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003609
3610 /* Check for Promiscuous and All Multicast modes */
3611
3612 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3613
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003614 /* set all bits that we expect to always be set */
3615 fctrl |= IXGBE_FCTRL_BAM;
3616 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3617 fctrl |= IXGBE_FCTRL_PMCF;
3618
Alexander Duyck28500622010-06-15 09:25:48 +00003619 /* clear the bits we are changing the status of */
3620 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3621
Auke Kok9a799d72007-09-15 14:07:45 -07003622 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003623 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003624 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003625 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003626 /* don't hardware filter vlans in promisc mode */
3627 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003628 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003629 if (netdev->flags & IFF_ALLMULTI) {
3630 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003631 vmolr |= IXGBE_VMOLR_MPE;
3632 } else {
3633 /*
3634 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003635 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003636 * that we can at least receive multicast traffic
3637 */
3638 hw->mac.ops.update_mc_addr_list(hw, netdev);
3639 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003640 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003641 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003642 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003643 /*
3644 * Write addresses to available RAR registers, if there is not
3645 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003646 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003647 */
3648 count = ixgbe_write_uc_addr_list(netdev);
3649 if (count < 0) {
3650 fctrl |= IXGBE_FCTRL_UPE;
3651 vmolr |= IXGBE_VMOLR_ROPE;
3652 }
3653 }
3654
3655 if (adapter->num_vfs) {
3656 ixgbe_restore_vf_multicasts(adapter);
3657 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3658 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3659 IXGBE_VMOLR_ROPE);
3660 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003661 }
3662
3663 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003664
3665 if (netdev->features & NETIF_F_HW_VLAN_RX)
3666 ixgbe_vlan_strip_enable(adapter);
3667 else
3668 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003669}
3670
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003671static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3672{
3673 int q_idx;
3674 struct ixgbe_q_vector *q_vector;
3675 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3676
3677 /* legacy and MSI only use one vector */
3678 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3679 q_vectors = 1;
3680
3681 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003682 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003683 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003684 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003685 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3686 if (!q_vector->rxr_count || !q_vector->txr_count) {
3687 if (q_vector->txr_count == 1)
3688 napi->poll = &ixgbe_clean_txonly;
3689 else if (q_vector->rxr_count == 1)
3690 napi->poll = &ixgbe_clean_rxonly;
3691 }
3692 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003693
3694 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003695 }
3696}
3697
3698static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3699{
3700 int q_idx;
3701 struct ixgbe_q_vector *q_vector;
3702 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3703
3704 /* legacy and MSI only use one vector */
3705 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3706 q_vectors = 1;
3707
3708 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003709 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003710 napi_disable(&q_vector->napi);
3711 }
3712}
3713
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003714#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003715/*
3716 * ixgbe_configure_dcb - Configure DCB hardware
3717 * @adapter: ixgbe adapter struct
3718 *
3719 * This is called by the driver on open to configure the DCB hardware.
3720 * This is also called by the gennetlink interface when reconfiguring
3721 * the DCB state.
3722 */
3723static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3724{
3725 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003726 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003727
Alexander Duyck67ebd792010-08-19 13:34:04 +00003728 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3729 if (hw->mac.type == ixgbe_mac_82598EB)
3730 netif_set_gso_max_size(adapter->netdev, 65536);
3731 return;
3732 }
3733
3734 if (hw->mac.type == ixgbe_mac_82598EB)
3735 netif_set_gso_max_size(adapter->netdev, 32768);
3736
Alexander Duyck2f90b862008-11-20 20:52:10 -08003737
Alexander Duyck2f90b862008-11-20 20:52:10 -08003738 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003739 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003740
Alexander Duyck2f90b862008-11-20 20:52:10 -08003741 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003742
3743 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003744 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3745#ifdef CONFIG_FCOE
3746 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3747 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3748#endif
3749 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3750 DCB_TX_CONFIG);
3751 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3752 DCB_RX_CONFIG);
3753 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3754 } else {
3755 struct net_device *dev = adapter->netdev;
3756
3757 if (adapter->ixgbe_ieee_ets)
3758 dev->dcbnl_ops->ieee_setets(dev,
3759 adapter->ixgbe_ieee_ets);
3760 if (adapter->ixgbe_ieee_pfc)
3761 dev->dcbnl_ops->ieee_setpfc(dev,
3762 adapter->ixgbe_ieee_pfc);
3763 }
John Fastabend8187cd42011-02-23 05:58:08 +00003764
3765 /* Enable RSS Hash per TC */
3766 if (hw->mac.type != ixgbe_mac_82598EB) {
3767 int i;
3768 u32 reg = 0;
3769
3770 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3771 u8 msb = 0;
3772 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3773
3774 while (cnt >>= 1)
3775 msb++;
3776
3777 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3778 }
3779 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3780 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003781}
3782
3783#endif
John Fastabend80605c652011-05-02 12:34:10 +00003784
3785static void ixgbe_configure_pb(struct ixgbe_adapter *adapter)
3786{
3787 int hdrm = 0;
3788 int num_tc = netdev_get_num_tc(adapter->netdev);
3789 struct ixgbe_hw *hw = &adapter->hw;
3790
3791 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
3792 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
3793 hdrm = 64 << adapter->fdir_pballoc;
3794
3795 hw->mac.ops.set_rxpba(&adapter->hw, num_tc, hdrm, PBA_STRATEGY_EQUAL);
3796}
3797
Auke Kok9a799d72007-09-15 14:07:45 -07003798static void ixgbe_configure(struct ixgbe_adapter *adapter)
3799{
3800 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003801 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003802 int i;
3803
John Fastabend80605c652011-05-02 12:34:10 +00003804 ixgbe_configure_pb(adapter);
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003805#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003806 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003807#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003808
Jesse Grossf62bbb52010-10-20 13:56:10 +00003809 ixgbe_set_rx_mode(netdev);
3810 ixgbe_restore_vlan(adapter);
3811
Yi Zoueacd73f2009-05-13 13:11:06 +00003812#ifdef IXGBE_FCOE
3813 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3814 ixgbe_configure_fcoe(adapter);
3815
3816#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003817 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3818 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003819 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003820 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003821 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3822 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3823 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3824 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003825 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003826
Auke Kok9a799d72007-09-15 14:07:45 -07003827 ixgbe_configure_tx(adapter);
3828 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003829}
3830
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003831static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3832{
3833 switch (hw->phy.type) {
3834 case ixgbe_phy_sfp_avago:
3835 case ixgbe_phy_sfp_ftl:
3836 case ixgbe_phy_sfp_intel:
3837 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003838 case ixgbe_phy_sfp_passive_tyco:
3839 case ixgbe_phy_sfp_passive_unknown:
3840 case ixgbe_phy_sfp_active_unknown:
3841 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003842 return true;
3843 default:
3844 return false;
3845 }
3846}
3847
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003848/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003849 * ixgbe_sfp_link_config - set up SFP+ link
3850 * @adapter: pointer to private adapter struct
3851 **/
3852static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3853{
Alexander Duyck70864002011-04-27 09:13:56 +00003854 /*
3855 * We are assuming the worst case scenerio here, and that
3856 * is that an SFP was inserted/removed after the reset
3857 * but before SFP detection was enabled. As such the best
3858 * solution is to just start searching as soon as we start
3859 */
3860 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3861 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003862
Alexander Duyck70864002011-04-27 09:13:56 +00003863 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003864}
3865
3866/**
3867 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003868 * @hw: pointer to private hardware struct
3869 *
3870 * Returns 0 on success, negative on failure
3871 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003872static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003873{
3874 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003875 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003876 u32 ret = IXGBE_ERR_LINK_SETUP;
3877
3878 if (hw->mac.ops.check_link)
3879 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3880
3881 if (ret)
3882 goto link_cfg_out;
3883
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003884 autoneg = hw->phy.autoneg_advertised;
3885 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003886 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3887 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003888 if (ret)
3889 goto link_cfg_out;
3890
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003891 if (hw->mac.ops.setup_link)
3892 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003893link_cfg_out:
3894 return ret;
3895}
3896
Alexander Duycka34bcff2010-08-19 13:39:20 +00003897static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003898{
Auke Kok9a799d72007-09-15 14:07:45 -07003899 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003900 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003901
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003902 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003903 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3904 IXGBE_GPIE_OCD;
3905 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003906 /*
3907 * use EIAM to auto-mask when MSI-X interrupt is asserted
3908 * this saves a register write for every interrupt
3909 */
3910 switch (hw->mac.type) {
3911 case ixgbe_mac_82598EB:
3912 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3913 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003914 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003915 case ixgbe_mac_X540:
3916 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003917 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3918 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3919 break;
3920 }
3921 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003922 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3923 * specifically only auto mask tx and rx interrupts */
3924 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003925 }
3926
Alexander Duycka34bcff2010-08-19 13:39:20 +00003927 /* XXX: to interrupt immediately for EICS writes, enable this */
3928 /* gpie |= IXGBE_GPIE_EIMEN; */
3929
3930 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3931 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3932 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003933 }
3934
Alexander Duycka34bcff2010-08-19 13:39:20 +00003935 /* Enable fan failure interrupt */
3936 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003937 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003938
Don Skidmore2698b202011-04-13 07:01:52 +00003939 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003940 gpie |= IXGBE_SDP1_GPIEN;
3941 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003942 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003943
3944 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3945}
3946
3947static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3948{
3949 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003950 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003951 u32 ctrl_ext;
3952
3953 ixgbe_get_hw_control(adapter);
3954 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003955
Auke Kok9a799d72007-09-15 14:07:45 -07003956 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3957 ixgbe_configure_msix(adapter);
3958 else
3959 ixgbe_configure_msi_and_legacy(adapter);
3960
Don Skidmorec6ecf392010-12-03 03:31:51 +00003961 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3962 if (hw->mac.ops.enable_tx_laser &&
3963 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003964 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003965 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003966 hw->mac.ops.enable_tx_laser(hw);
3967
Auke Kok9a799d72007-09-15 14:07:45 -07003968 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003969 ixgbe_napi_enable_all(adapter);
3970
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003971 if (ixgbe_is_sfp(hw)) {
3972 ixgbe_sfp_link_config(adapter);
3973 } else {
3974 err = ixgbe_non_sfp_link_config(hw);
3975 if (err)
3976 e_err(probe, "link_config FAILED %d\n", err);
3977 }
3978
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003979 /* clear any pending interrupts, may auto mask */
3980 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003981 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003982
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003983 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003984 * If this adapter has a fan, check to see if we had a failure
3985 * before we enabled the interrupt.
3986 */
3987 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3988 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3989 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003990 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003991 }
3992
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003993 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003994 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003995
Auke Kok9a799d72007-09-15 14:07:45 -07003996 /* bring the link up in the watchdog, this could race with our first
3997 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003998 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3999 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00004000 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00004001
4002 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
4003 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
4004 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
4005 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
4006
Auke Kok9a799d72007-09-15 14:07:45 -07004007 return 0;
4008}
4009
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004010void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
4011{
4012 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00004013 /* put off any impending NetWatchDogTimeout */
4014 adapter->netdev->trans_start = jiffies;
4015
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004016 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00004017 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004018 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00004019 /*
4020 * If SR-IOV enabled then wait a bit before bringing the adapter
4021 * back up to give the VFs time to respond to the reset. The
4022 * two second wait is based upon the watchdog timer cycle in
4023 * the VF driver.
4024 */
4025 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4026 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004027 ixgbe_up(adapter);
4028 clear_bit(__IXGBE_RESETTING, &adapter->state);
4029}
4030
Auke Kok9a799d72007-09-15 14:07:45 -07004031int ixgbe_up(struct ixgbe_adapter *adapter)
4032{
4033 /* hardware has been reset, we need to reload some things */
4034 ixgbe_configure(adapter);
4035
4036 return ixgbe_up_complete(adapter);
4037}
4038
4039void ixgbe_reset(struct ixgbe_adapter *adapter)
4040{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004041 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004042 int err;
4043
Alexander Duyck70864002011-04-27 09:13:56 +00004044 /* lock SFP init bit to prevent race conditions with the watchdog */
4045 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4046 usleep_range(1000, 2000);
4047
4048 /* clear all SFP and link config related flags while holding SFP_INIT */
4049 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4050 IXGBE_FLAG2_SFP_NEEDS_RESET);
4051 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4052
Don Skidmore8ca783a2009-05-26 20:40:47 -07004053 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004054 switch (err) {
4055 case 0:
4056 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004057 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004058 break;
4059 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004060 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004061 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004062 case IXGBE_ERR_EEPROM_VERSION:
4063 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004064 e_dev_warn("This device is a pre-production adapter/LOM. "
4065 "Please be aware there may be issuesassociated with "
4066 "your hardware. If you are experiencing problems "
4067 "please contact your Intel or hardware "
4068 "representative who provided you with this "
4069 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004070 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004071 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004072 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004073 }
Auke Kok9a799d72007-09-15 14:07:45 -07004074
Alexander Duyck70864002011-04-27 09:13:56 +00004075 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4076
Auke Kok9a799d72007-09-15 14:07:45 -07004077 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004078 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4079 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004080}
4081
Auke Kok9a799d72007-09-15 14:07:45 -07004082/**
4083 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004084 * @rx_ring: ring to free buffers from
4085 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004086static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004087{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004088 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004089 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004090 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004091
Alexander Duyck84418e32010-08-19 13:40:54 +00004092 /* ring already cleared, nothing to do */
4093 if (!rx_ring->rx_buffer_info)
4094 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004095
Alexander Duyck84418e32010-08-19 13:40:54 +00004096 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004097 for (i = 0; i < rx_ring->count; i++) {
4098 struct ixgbe_rx_buffer *rx_buffer_info;
4099
4100 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4101 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004102 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004103 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004104 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004105 rx_buffer_info->dma = 0;
4106 }
4107 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004108 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004109 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004110 do {
4111 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004112 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004113 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004114 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004115 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004116 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004117 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004118 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004119 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004120 skb = skb->prev;
4121 dev_kfree_skb(this);
4122 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004123 }
4124 if (!rx_buffer_info->page)
4125 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004126 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004127 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004128 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004129 rx_buffer_info->page_dma = 0;
4130 }
Auke Kok9a799d72007-09-15 14:07:45 -07004131 put_page(rx_buffer_info->page);
4132 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004133 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004134 }
4135
4136 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4137 memset(rx_ring->rx_buffer_info, 0, size);
4138
4139 /* Zero out the descriptor ring */
4140 memset(rx_ring->desc, 0, rx_ring->size);
4141
4142 rx_ring->next_to_clean = 0;
4143 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004144}
4145
4146/**
4147 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004148 * @tx_ring: ring to be cleaned
4149 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004150static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004151{
4152 struct ixgbe_tx_buffer *tx_buffer_info;
4153 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004154 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004155
Alexander Duyck84418e32010-08-19 13:40:54 +00004156 /* ring already cleared, nothing to do */
4157 if (!tx_ring->tx_buffer_info)
4158 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004159
Alexander Duyck84418e32010-08-19 13:40:54 +00004160 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004161 for (i = 0; i < tx_ring->count; i++) {
4162 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004163 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004164 }
4165
4166 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4167 memset(tx_ring->tx_buffer_info, 0, size);
4168
4169 /* Zero out the descriptor ring */
4170 memset(tx_ring->desc, 0, tx_ring->size);
4171
4172 tx_ring->next_to_use = 0;
4173 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004174}
4175
4176/**
Auke Kok9a799d72007-09-15 14:07:45 -07004177 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4178 * @adapter: board private structure
4179 **/
4180static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4181{
4182 int i;
4183
4184 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004185 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004186}
4187
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004188/**
4189 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4190 * @adapter: board private structure
4191 **/
4192static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4193{
4194 int i;
4195
4196 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004197 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004198}
4199
Auke Kok9a799d72007-09-15 14:07:45 -07004200void ixgbe_down(struct ixgbe_adapter *adapter)
4201{
4202 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004203 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004204 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004205 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004206 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004207
4208 /* signal that we are down to the interrupt handler */
4209 set_bit(__IXGBE_DOWN, &adapter->state);
4210
4211 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004212 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4213 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004214
Yi Zou2d39d572011-01-06 14:29:56 +00004215 /* disable all enabled rx queues */
4216 for (i = 0; i < adapter->num_rx_queues; i++)
4217 /* this call also flushes the previous write */
4218 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4219
Don Skidmore032b4322011-03-18 09:32:53 +00004220 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004221
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004222 netif_tx_stop_all_queues(netdev);
4223
Alexander Duyck70864002011-04-27 09:13:56 +00004224 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004225 netif_carrier_off(netdev);
4226 netif_tx_disable(netdev);
4227
4228 ixgbe_irq_disable(adapter);
4229
4230 ixgbe_napi_disable_all(adapter);
4231
Alexander Duyckd034acf2011-04-27 09:25:34 +00004232 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4233 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004234 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4235
4236 del_timer_sync(&adapter->service_timer);
4237
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004238 /* disable receive for all VFs and wait one second */
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004239 if (adapter->num_vfs) {
4240 /* ping all the active vfs to let them know we are going down */
Auke Kok9a799d72007-09-15 14:07:45 -07004241 ixgbe_ping_all_vfs(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004242
Auke Kok9a799d72007-09-15 14:07:45 -07004243 /* Disable all VFTE/VFRE TX/RX */
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004244 ixgbe_disable_tx_rx(adapter);
4245
4246 /* Mark all the VFs as inactive */
4247 for (i = 0 ; i < adapter->num_vfs; i++)
4248 adapter->vfinfo[i].clear_to_send = 0;
4249 }
4250
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004251 /* Cleanup the affinity_hint CPU mask memory and callback */
4252 for (i = 0; i < num_q_vectors; i++) {
4253 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4254 /* clear the affinity_mask in the IRQ descriptor */
4255 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4256 /* release the CPU mask memory */
4257 free_cpumask_var(q_vector->affinity_mask);
4258 }
4259
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004260 /* disable transmits in the hardware now that interrupts are off */
4261 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004262 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004263 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004264 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004265
4266 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004267 switch (hw->mac.type) {
4268 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004269 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004270 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004271 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4272 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004273 break;
4274 default:
4275 break;
4276 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004277
Paul Larson6f4a0e42008-06-24 17:00:56 -07004278 if (!pci_channel_offline(adapter->pdev))
4279 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004280
4281 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4282 if (hw->mac.ops.disable_tx_laser &&
4283 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004284 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004285 (hw->mac.type == ixgbe_mac_82599EB))))
4286 hw->mac.ops.disable_tx_laser(hw);
4287
Auke Kok9a799d72007-09-15 14:07:45 -07004288 ixgbe_clean_all_tx_rings(adapter);
4289 ixgbe_clean_all_rx_rings(adapter);
4290
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004291#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004292 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004293 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004294#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004295}
4296
Auke Kok9a799d72007-09-15 14:07:45 -07004297/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004298 * ixgbe_poll - NAPI Rx polling callback
4299 * @napi: structure for representing this polling device
4300 * @budget: how many packets driver is allowed to clean
4301 *
4302 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004303 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004304static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004305{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004306 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004307 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004308 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004309 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004310
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004311#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004312 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4313 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004314#endif
4315
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004316 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4317 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004318
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004319 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004320 work_done = budget;
4321
David S. Miller53e52c72008-01-07 21:06:12 -08004322 /* If budget not fully consumed, exit the polling mode */
4323 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004324 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004325 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004326 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004327 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004328 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004329 }
Auke Kok9a799d72007-09-15 14:07:45 -07004330 return work_done;
4331}
4332
4333/**
4334 * ixgbe_tx_timeout - Respond to a Tx Hang
4335 * @netdev: network interface device structure
4336 **/
4337static void ixgbe_tx_timeout(struct net_device *netdev)
4338{
4339 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4340
4341 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004342 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004343}
4344
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004345/**
4346 * ixgbe_set_rss_queues: Allocate queues for RSS
4347 * @adapter: board private structure to initialize
4348 *
4349 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4350 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4351 *
4352 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004353static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4354{
4355 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004356 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004357
4358 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004359 f->mask = 0xF;
4360 adapter->num_rx_queues = f->indices;
4361 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004362 ret = true;
4363 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004364 ret = false;
4365 }
4366
4367 return ret;
4368}
4369
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004370/**
4371 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4372 * @adapter: board private structure to initialize
4373 *
4374 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4375 * to the original CPU that initiated the Tx session. This runs in addition
4376 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4377 * Rx load across CPUs using RSS.
4378 *
4379 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004380static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004381{
4382 bool ret = false;
4383 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4384
4385 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4386 f_fdir->mask = 0;
4387
4388 /* Flow Director must have RSS enabled */
4389 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4390 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4391 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4392 adapter->num_tx_queues = f_fdir->indices;
4393 adapter->num_rx_queues = f_fdir->indices;
4394 ret = true;
4395 } else {
4396 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4397 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4398 }
4399 return ret;
4400}
4401
Yi Zou0331a832009-05-17 12:33:52 +00004402#ifdef IXGBE_FCOE
4403/**
4404 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4405 * @adapter: board private structure to initialize
4406 *
4407 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4408 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4409 * rx queues out of the max number of rx queues, instead, it is used as the
4410 * index of the first rx queue used by FCoE.
4411 *
4412 **/
4413static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4414{
Yi Zou0331a832009-05-17 12:33:52 +00004415 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4416
John Fastabende5b64632011-03-08 03:44:52 +00004417 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4418 return false;
4419
4420 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4421#ifdef CONFIG_IXGBE_DCB
4422 int tc;
4423 struct net_device *dev = adapter->netdev;
4424
4425 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4426 f->indices = dev->tc_to_txq[tc].count;
4427 f->mask = dev->tc_to_txq[tc].offset;
4428#endif
4429 } else {
4430 f->indices = min((int)num_online_cpus(), f->indices);
4431
Yi Zou8de8b2e2009-09-03 14:55:50 +00004432 adapter->num_rx_queues = 1;
4433 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004434
Yi Zou0331a832009-05-17 12:33:52 +00004435 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004436 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004437 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4438 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4439 ixgbe_set_fdir_queues(adapter);
4440 else
4441 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004442 }
4443 /* adding FCoE rx rings to the end */
4444 f->mask = adapter->num_rx_queues;
4445 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004446 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004447 }
4448
John Fastabende5b64632011-03-08 03:44:52 +00004449 return true;
4450}
4451#endif /* IXGBE_FCOE */
4452
4453#ifdef CONFIG_IXGBE_DCB
4454static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4455{
4456 bool ret = false;
4457 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
John Fastabend8b1c0b22011-05-03 02:26:48 +00004458 int tcs = netdev_get_num_tc(adapter->netdev);
4459 int max_q, i, q;
John Fastabende5b64632011-03-08 03:44:52 +00004460
John Fastabend8b1c0b22011-05-03 02:26:48 +00004461 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) || !tcs)
John Fastabende5b64632011-03-08 03:44:52 +00004462 return ret;
4463
John Fastabend8b1c0b22011-05-03 02:26:48 +00004464 max_q = adapter->netdev->num_tx_queues / tcs;
4465
John Fastabende5b64632011-03-08 03:44:52 +00004466 f->indices = 0;
John Fastabend8b1c0b22011-05-03 02:26:48 +00004467 for (i = 0; i < tcs; i++) {
4468 q = min((int)num_online_cpus(), max_q);
John Fastabende5b64632011-03-08 03:44:52 +00004469 f->indices += q;
4470 }
4471
4472 f->mask = 0x7 << 3;
4473 adapter->num_rx_queues = f->indices;
4474 adapter->num_tx_queues = f->indices;
4475 ret = true;
4476
4477#ifdef IXGBE_FCOE
4478 /* FCoE enabled queues require special configuration done through
4479 * configure_fcoe() and others. Here we map FCoE indices onto the
4480 * DCB queue pairs allowing FCoE to own configuration later.
4481 */
4482 ixgbe_set_fcoe_queues(adapter);
4483#endif
4484
Yi Zou0331a832009-05-17 12:33:52 +00004485 return ret;
4486}
John Fastabende5b64632011-03-08 03:44:52 +00004487#endif
Yi Zou0331a832009-05-17 12:33:52 +00004488
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004489/**
4490 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4491 * @adapter: board private structure to initialize
4492 *
4493 * IOV doesn't actually use anything, so just NAK the
4494 * request for now and let the other queue routines
4495 * figure out what to do.
4496 */
4497static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4498{
4499 return false;
4500}
4501
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004502/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004503 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004504 * @adapter: board private structure to initialize
4505 *
4506 * This is the top level queue allocation routine. The order here is very
4507 * important, starting with the "most" number of features turned on at once,
4508 * and ending with the smallest set of features. This way large combinations
4509 * can be allocated if they're turned on, and smaller combinations are the
4510 * fallthrough conditions.
4511 *
4512 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004513static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004514{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004515 /* Start with base case */
4516 adapter->num_rx_queues = 1;
4517 adapter->num_tx_queues = 1;
4518 adapter->num_rx_pools = adapter->num_rx_queues;
4519 adapter->num_rx_queues_per_pool = 1;
4520
4521 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004522 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004523
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004524#ifdef CONFIG_IXGBE_DCB
4525 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004526 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004527
4528#endif
John Fastabende5b64632011-03-08 03:44:52 +00004529#ifdef IXGBE_FCOE
4530 if (ixgbe_set_fcoe_queues(adapter))
4531 goto done;
4532
4533#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004534 if (ixgbe_set_fdir_queues(adapter))
4535 goto done;
4536
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004537 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004538 goto done;
4539
4540 /* fallback to base case */
4541 adapter->num_rx_queues = 1;
4542 adapter->num_tx_queues = 1;
4543
4544done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004545 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004546 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004547 return netif_set_real_num_rx_queues(adapter->netdev,
4548 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004549}
4550
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004551static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004552 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004553{
4554 int err, vector_threshold;
4555
4556 /* We'll want at least 3 (vector_threshold):
4557 * 1) TxQ[0] Cleanup
4558 * 2) RxQ[0] Cleanup
4559 * 3) Other (Link Status Change, etc.)
4560 * 4) TCP Timer (optional)
4561 */
4562 vector_threshold = MIN_MSIX_COUNT;
4563
4564 /* The more we get, the more we will assign to Tx/Rx Cleanup
4565 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4566 * Right now, we simply care about how many we'll get; we'll
4567 * set them up later while requesting irq's.
4568 */
4569 while (vectors >= vector_threshold) {
4570 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004571 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004572 if (!err) /* Success in acquiring all requested vectors. */
4573 break;
4574 else if (err < 0)
4575 vectors = 0; /* Nasty failure, quit now */
4576 else /* err == number of vectors we should try again with */
4577 vectors = err;
4578 }
4579
4580 if (vectors < vector_threshold) {
4581 /* Can't allocate enough MSI-X interrupts? Oh well.
4582 * This just means we'll go with either a single MSI
4583 * vector or fall back to legacy interrupts.
4584 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004585 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4586 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004587 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4588 kfree(adapter->msix_entries);
4589 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004590 } else {
4591 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004592 /*
4593 * Adjust for only the vectors we'll use, which is minimum
4594 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4595 * vectors we were allocated.
4596 */
4597 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004598 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004599 }
4600}
4601
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004602/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004603 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004604 * @adapter: board private structure to initialize
4605 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004606 * Cache the descriptor ring offsets for RSS to the assigned rings.
4607 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004608 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004609static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004610{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004611 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004612
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004613 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4614 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004615
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004616 for (i = 0; i < adapter->num_rx_queues; i++)
4617 adapter->rx_ring[i]->reg_idx = i;
4618 for (i = 0; i < adapter->num_tx_queues; i++)
4619 adapter->tx_ring[i]->reg_idx = i;
4620
4621 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004622}
4623
4624#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004625
4626/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004627static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4628 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004629{
4630 struct net_device *dev = adapter->netdev;
4631 struct ixgbe_hw *hw = &adapter->hw;
4632 u8 num_tcs = netdev_get_num_tc(dev);
4633
4634 *tx = 0;
4635 *rx = 0;
4636
4637 switch (hw->mac.type) {
4638 case ixgbe_mac_82598EB:
4639 *tx = tc << 3;
4640 *rx = tc << 2;
4641 break;
4642 case ixgbe_mac_82599EB:
4643 case ixgbe_mac_X540:
4644 if (num_tcs == 8) {
4645 if (tc < 3) {
4646 *tx = tc << 5;
4647 *rx = tc << 4;
4648 } else if (tc < 5) {
4649 *tx = ((tc + 2) << 4);
4650 *rx = tc << 4;
4651 } else if (tc < num_tcs) {
4652 *tx = ((tc + 8) << 3);
4653 *rx = tc << 4;
4654 }
4655 } else if (num_tcs == 4) {
4656 *rx = tc << 5;
4657 switch (tc) {
4658 case 0:
4659 *tx = 0;
4660 break;
4661 case 1:
4662 *tx = 64;
4663 break;
4664 case 2:
4665 *tx = 96;
4666 break;
4667 case 3:
4668 *tx = 112;
4669 break;
4670 default:
4671 break;
4672 }
4673 }
4674 break;
4675 default:
4676 break;
4677 }
4678}
4679
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004680/**
4681 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4682 * @adapter: board private structure to initialize
4683 *
4684 * Cache the descriptor ring offsets for DCB to the assigned rings.
4685 *
4686 **/
4687static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4688{
John Fastabende5b64632011-03-08 03:44:52 +00004689 struct net_device *dev = adapter->netdev;
4690 int i, j, k;
4691 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004692
John Fastabend8b1c0b22011-05-03 02:26:48 +00004693 if (!num_tcs)
Alexander Duyckbd508172010-11-16 19:27:03 -08004694 return false;
4695
John Fastabende5b64632011-03-08 03:44:52 +00004696 for (i = 0, k = 0; i < num_tcs; i++) {
4697 unsigned int tx_s, rx_s;
4698 u16 count = dev->tc_to_txq[i].count;
4699
4700 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4701 for (j = 0; j < count; j++, k++) {
4702 adapter->tx_ring[k]->reg_idx = tx_s + j;
4703 adapter->rx_ring[k]->reg_idx = rx_s + j;
4704 adapter->tx_ring[k]->dcb_tc = i;
4705 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004706 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004707 }
John Fastabende5b64632011-03-08 03:44:52 +00004708
4709 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004710}
4711#endif
4712
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004713/**
4714 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4715 * @adapter: board private structure to initialize
4716 *
4717 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4718 *
4719 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004720static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004721{
4722 int i;
4723 bool ret = false;
4724
4725 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4726 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4727 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4728 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004729 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004730 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004731 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004732 ret = true;
4733 }
4734
4735 return ret;
4736}
4737
Yi Zou0331a832009-05-17 12:33:52 +00004738#ifdef IXGBE_FCOE
4739/**
4740 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4741 * @adapter: board private structure to initialize
4742 *
4743 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4744 *
4745 */
4746static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4747{
Yi Zou0331a832009-05-17 12:33:52 +00004748 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004749 int i;
4750 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004751
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004752 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4753 return false;
4754
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004755 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4756 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4757 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4758 ixgbe_cache_ring_fdir(adapter);
4759 else
4760 ixgbe_cache_ring_rss(adapter);
4761
4762 fcoe_rx_i = f->mask;
4763 fcoe_tx_i = f->mask;
4764 }
4765 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4766 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4767 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4768 }
4769 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004770}
4771
4772#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004773/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004774 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4775 * @adapter: board private structure to initialize
4776 *
4777 * SR-IOV doesn't use any descriptor rings but changes the default if
4778 * no other mapping is used.
4779 *
4780 */
4781static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4782{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004783 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4784 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004785 if (adapter->num_vfs)
4786 return true;
4787 else
4788 return false;
4789}
4790
4791/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004792 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4793 * @adapter: board private structure to initialize
4794 *
4795 * Once we know the feature-set enabled for the device, we'll cache
4796 * the register offset the descriptor ring is assigned to.
4797 *
4798 * Note, the order the various feature calls is important. It must start with
4799 * the "most" features enabled at the same time, then trickle down to the
4800 * least amount of features turned on at once.
4801 **/
4802static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4803{
4804 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004805 adapter->rx_ring[0]->reg_idx = 0;
4806 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004807
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004808 if (ixgbe_cache_ring_sriov(adapter))
4809 return;
4810
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004811#ifdef CONFIG_IXGBE_DCB
4812 if (ixgbe_cache_ring_dcb(adapter))
4813 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004814#endif
John Fastabende5b64632011-03-08 03:44:52 +00004815
4816#ifdef IXGBE_FCOE
4817 if (ixgbe_cache_ring_fcoe(adapter))
4818 return;
4819#endif /* IXGBE_FCOE */
4820
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004821 if (ixgbe_cache_ring_fdir(adapter))
4822 return;
4823
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004824 if (ixgbe_cache_ring_rss(adapter))
4825 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826}
4827
Auke Kok9a799d72007-09-15 14:07:45 -07004828/**
4829 * ixgbe_alloc_queues - Allocate memory for all rings
4830 * @adapter: board private structure to initialize
4831 *
4832 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004833 * number of queues at compile-time. The polling_netdev array is
4834 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004835 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004836static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004837{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004838 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 if (nid < 0 || !node_online(nid))
4841 nid = first_online_node;
4842
4843 for (; tx < adapter->num_tx_queues; tx++) {
4844 struct ixgbe_ring *ring;
4845
4846 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004847 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004848 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004849 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004850 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004851 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004852 ring->queue_index = tx;
4853 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004854 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004855 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004856
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004857 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004858 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004859
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004860 for (; rx < adapter->num_rx_queues; rx++) {
4861 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004862
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004863 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004864 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004865 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004866 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004867 goto err_allocation;
4868 ring->count = adapter->rx_ring_count;
4869 ring->queue_index = rx;
4870 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004871 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004872 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004873
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004874 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004875 }
4876
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004877 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004878
4879 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004880
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004881err_allocation:
4882 while (tx)
4883 kfree(adapter->tx_ring[--tx]);
4884
4885 while (rx)
4886 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004887 return -ENOMEM;
4888}
4889
4890/**
4891 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4892 * @adapter: board private structure to initialize
4893 *
4894 * Attempt to configure the interrupts using the best available
4895 * capabilities of the hardware and the kernel.
4896 **/
Al Virofeea6a52008-11-27 15:34:07 -08004897static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004898{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004899 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004900 int err = 0;
4901 int vector, v_budget;
4902
4903 /*
4904 * It's easy to be greedy for MSI-X vectors, but it really
4905 * doesn't do us much good if we have a lot more vectors
4906 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004907 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004908 */
4909 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004910 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004911
4912 /*
4913 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004914 * hw.mac->max_msix_vectors vectors. With features
4915 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4916 * descriptor queues supported by our device. Thus, we cap it off in
4917 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004918 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004919 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004920
4921 /* A failure in MSI-X entry allocation isn't fatal, but it does
4922 * mean we disable MSI-X capabilities of the adapter. */
4923 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004924 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004925 if (adapter->msix_entries) {
4926 for (vector = 0; vector < v_budget; vector++)
4927 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004928
Alexander Duyck7a921c92009-05-06 10:43:28 +00004929 ixgbe_acquire_msix_vectors(adapter, v_budget);
4930
4931 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4932 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004933 }
David S. Miller26d27842010-05-03 15:18:22 -07004934
Alexander Duyck7a921c92009-05-06 10:43:28 +00004935 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4936 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004937 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4938 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4939 e_err(probe,
4940 "Flow Director is not supported while multiple "
4941 "queues are disabled. Disabling Flow Director\n");
4942 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004943 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4944 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4945 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004946 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4947 ixgbe_disable_sriov(adapter);
4948
Ben Hutchings847f53f2010-09-27 08:28:56 +00004949 err = ixgbe_set_num_queues(adapter);
4950 if (err)
4951 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004952
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004953 err = pci_enable_msi(adapter->pdev);
4954 if (!err) {
4955 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4956 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004957 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4958 "Unable to allocate MSI interrupt, "
4959 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004960 /* reset err */
4961 err = 0;
4962 }
4963
4964out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965 return err;
4966}
4967
Alexander Duyck7a921c92009-05-06 10:43:28 +00004968/**
4969 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4970 * @adapter: board private structure to initialize
4971 *
4972 * We allocate one q_vector per queue interrupt. If allocation fails we
4973 * return -ENOMEM.
4974 **/
4975static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4976{
4977 int q_idx, num_q_vectors;
4978 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004979 int (*poll)(struct napi_struct *, int);
4980
4981 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4982 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004983 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004984 } else {
4985 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004986 poll = &ixgbe_poll;
4987 }
4988
4989 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004990 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004991 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004992 if (!q_vector)
4993 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004994 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004995 if (!q_vector)
4996 goto err_out;
4997 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004998 if (q_vector->txr_count && !q_vector->rxr_count)
4999 q_vector->eitr = adapter->tx_eitr_param;
5000 else
5001 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005002 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005003 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005004 adapter->q_vector[q_idx] = q_vector;
5005 }
5006
5007 return 0;
5008
5009err_out:
5010 while (q_idx) {
5011 q_idx--;
5012 q_vector = adapter->q_vector[q_idx];
5013 netif_napi_del(&q_vector->napi);
5014 kfree(q_vector);
5015 adapter->q_vector[q_idx] = NULL;
5016 }
5017 return -ENOMEM;
5018}
5019
5020/**
5021 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5022 * @adapter: board private structure to initialize
5023 *
5024 * This function frees the memory allocated to the q_vectors. In addition if
5025 * NAPI is enabled it will delete any references to the NAPI struct prior
5026 * to freeing the q_vector.
5027 **/
5028static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5029{
5030 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005031
Alexander Duyck91281fd2009-06-04 16:00:27 +00005032 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005033 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005034 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005035 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005036
5037 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5038 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005039 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005040 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041 kfree(q_vector);
5042 }
5043}
5044
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005045static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005046{
5047 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5048 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5049 pci_disable_msix(adapter->pdev);
5050 kfree(adapter->msix_entries);
5051 adapter->msix_entries = NULL;
5052 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5053 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5054 pci_disable_msi(adapter->pdev);
5055 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005056}
5057
5058/**
5059 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5060 * @adapter: board private structure to initialize
5061 *
5062 * We determine which interrupt scheme to use based on...
5063 * - Kernel support (MSI, MSI-X)
5064 * - which can be user-defined (via MODULE_PARAM)
5065 * - Hardware queue count (num_*_queues)
5066 * - defined by miscellaneous hardware support/features (RSS, etc.)
5067 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005068int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005069{
5070 int err;
5071
5072 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005073 err = ixgbe_set_num_queues(adapter);
5074 if (err)
5075 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005076
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005077 err = ixgbe_set_interrupt_capability(adapter);
5078 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005079 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005080 goto err_set_interrupt;
5081 }
5082
Alexander Duyck7a921c92009-05-06 10:43:28 +00005083 err = ixgbe_alloc_q_vectors(adapter);
5084 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005085 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005086 goto err_alloc_q_vectors;
5087 }
5088
5089 err = ixgbe_alloc_queues(adapter);
5090 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005091 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005092 goto err_alloc_queues;
5093 }
5094
Emil Tantilov849c4542010-06-03 16:53:41 +00005095 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005096 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5097 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005098
5099 set_bit(__IXGBE_DOWN, &adapter->state);
5100
5101 return 0;
5102
Alexander Duyck7a921c92009-05-06 10:43:28 +00005103err_alloc_queues:
5104 ixgbe_free_q_vectors(adapter);
5105err_alloc_q_vectors:
5106 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005107err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005108 return err;
5109}
5110
5111/**
5112 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5113 * @adapter: board private structure to clear interrupt scheme on
5114 *
5115 * We go through and clear interrupt specific resources and reset the structure
5116 * to pre-load conditions
5117 **/
5118void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5119{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005120 int i;
5121
5122 for (i = 0; i < adapter->num_tx_queues; i++) {
5123 kfree(adapter->tx_ring[i]);
5124 adapter->tx_ring[i] = NULL;
5125 }
5126 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005127 struct ixgbe_ring *ring = adapter->rx_ring[i];
5128
5129 /* ixgbe_get_stats64() might access this ring, we must wait
5130 * a grace period before freeing it.
5131 */
Lai Jiangshanbcec8b62011-03-18 11:57:21 +08005132 kfree_rcu(ring, rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005133 adapter->rx_ring[i] = NULL;
5134 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005135
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005136 adapter->num_tx_queues = 0;
5137 adapter->num_rx_queues = 0;
5138
Alexander Duyck7a921c92009-05-06 10:43:28 +00005139 ixgbe_free_q_vectors(adapter);
5140 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005141}
5142
5143/**
5144 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5145 * @adapter: board private structure to initialize
5146 *
5147 * ixgbe_sw_init initializes the Adapter private data structure.
5148 * Fields are initialized based on PCI device information and
5149 * OS network device settings (MTU size).
5150 **/
5151static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5152{
5153 struct ixgbe_hw *hw = &adapter->hw;
5154 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005155 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005156 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005157#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005158 int j;
5159 struct tc_configuration *tc;
5160#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005161 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005162
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005163 /* PCI config space info */
5164
5165 hw->vendor_id = pdev->vendor;
5166 hw->device_id = pdev->device;
5167 hw->revision_id = pdev->revision;
5168 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5169 hw->subsystem_device_id = pdev->subsystem_device;
5170
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005171 /* Set capability flags */
5172 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5173 adapter->ring_feature[RING_F_RSS].indices = rss;
5174 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005175 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005176 switch (hw->mac.type) {
5177 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005178 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5179 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005180 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005181 break;
5182 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005183 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005184 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005185 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5186 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005187 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5188 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005189 /* n-tuple support exists, always init our spinlock */
5190 spin_lock_init(&adapter->fdir_perfect_lock);
5191 /* Flow Director hash filters enabled */
5192 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5193 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005194 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005195 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005196 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005197#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005198 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5199 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5200 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005201#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005202 /* Default traffic class to use for FCoE */
5203 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005204 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005205#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005206#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005207 break;
5208 default:
5209 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005210 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005211
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005212#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005213 /* Configure DCB traffic classes */
5214 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5215 tc = &adapter->dcb_cfg.tc_config[j];
5216 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5217 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5218 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5219 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5220 tc->dcb_pfc = pfc_disabled;
5221 }
5222 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5223 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005224 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005225 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005226 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005227 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005228 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005229
5230#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005231
5232 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005233 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005234 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005235#ifdef CONFIG_DCB
5236 adapter->last_lfc_mode = hw->fc.current_mode;
5237#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005238 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5239 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005240 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5241 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005242 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005243
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005244 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005245 adapter->rx_itr_setting = 1;
5246 adapter->rx_eitr_param = 20000;
5247 adapter->tx_itr_setting = 1;
5248 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005249
5250 /* set defaults for eitr in MegaBytes */
5251 adapter->eitr_low = 10;
5252 adapter->eitr_high = 20;
5253
5254 /* set default ring sizes */
5255 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5256 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5257
Auke Kok9a799d72007-09-15 14:07:45 -07005258 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005259 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005260 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005261 return -EIO;
5262 }
5263
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005264 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005265 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5266
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005267 /* get assigned NUMA node */
5268 adapter->node = dev_to_node(&pdev->dev);
5269
Auke Kok9a799d72007-09-15 14:07:45 -07005270 set_bit(__IXGBE_DOWN, &adapter->state);
5271
5272 return 0;
5273}
5274
5275/**
5276 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005277 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005278 *
5279 * Return 0 on success, negative on failure
5280 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005281int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005282{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005283 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005284 int size;
5285
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005286 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005287 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005288 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005289 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005290 if (!tx_ring->tx_buffer_info)
5291 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005292
5293 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005294 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005295 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005296
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005297 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005298 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005299 if (!tx_ring->desc)
5300 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005301
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005302 tx_ring->next_to_use = 0;
5303 tx_ring->next_to_clean = 0;
5304 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005305 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005306
5307err:
5308 vfree(tx_ring->tx_buffer_info);
5309 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005310 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005311 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005312}
5313
5314/**
Alexander Duyck69888672008-09-11 20:05:39 -07005315 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5316 * @adapter: board private structure
5317 *
5318 * If this function returns with an error, then it's possible one or
5319 * more of the rings is populated (while the rest are not). It is the
5320 * callers duty to clean those orphaned rings.
5321 *
5322 * Return 0 on success, negative on failure
5323 **/
5324static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5325{
5326 int i, err = 0;
5327
5328 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005329 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005330 if (!err)
5331 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005332 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005333 break;
5334 }
5335
5336 return err;
5337}
5338
5339/**
Auke Kok9a799d72007-09-15 14:07:45 -07005340 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005341 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005342 *
5343 * Returns 0 on success, negative on failure
5344 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005345int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005346{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005347 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005348 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005349
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005350 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005351 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005352 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005353 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005354 if (!rx_ring->rx_buffer_info)
5355 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005356
Auke Kok9a799d72007-09-15 14:07:45 -07005357 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005358 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5359 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005360
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005361 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005362 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005363
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005364 if (!rx_ring->desc)
5365 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005366
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005367 rx_ring->next_to_clean = 0;
5368 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005369
5370 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005371err:
5372 vfree(rx_ring->rx_buffer_info);
5373 rx_ring->rx_buffer_info = NULL;
5374 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005375 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005376}
5377
5378/**
Alexander Duyck69888672008-09-11 20:05:39 -07005379 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5380 * @adapter: board private structure
5381 *
5382 * If this function returns with an error, then it's possible one or
5383 * more of the rings is populated (while the rest are not). It is the
5384 * callers duty to clean those orphaned rings.
5385 *
5386 * Return 0 on success, negative on failure
5387 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005388static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5389{
5390 int i, err = 0;
5391
5392 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005394 if (!err)
5395 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005396 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005397 break;
5398 }
5399
5400 return err;
5401}
5402
5403/**
Auke Kok9a799d72007-09-15 14:07:45 -07005404 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005405 * @tx_ring: Tx descriptor ring for a specific queue
5406 *
5407 * Free all transmit software resources
5408 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005409void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005410{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005411 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005412
5413 vfree(tx_ring->tx_buffer_info);
5414 tx_ring->tx_buffer_info = NULL;
5415
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005416 /* if not set, then don't free */
5417 if (!tx_ring->desc)
5418 return;
5419
5420 dma_free_coherent(tx_ring->dev, tx_ring->size,
5421 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005422
5423 tx_ring->desc = NULL;
5424}
5425
5426/**
5427 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5428 * @adapter: board private structure
5429 *
5430 * Free all transmit software resources
5431 **/
5432static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5433{
5434 int i;
5435
5436 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005437 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005438 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005439}
5440
5441/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005442 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005443 * @rx_ring: ring to clean the resources from
5444 *
5445 * Free all receive software resources
5446 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005447void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005448{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005449 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005450
5451 vfree(rx_ring->rx_buffer_info);
5452 rx_ring->rx_buffer_info = NULL;
5453
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005454 /* if not set, then don't free */
5455 if (!rx_ring->desc)
5456 return;
5457
5458 dma_free_coherent(rx_ring->dev, rx_ring->size,
5459 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005460
5461 rx_ring->desc = NULL;
5462}
5463
5464/**
5465 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5466 * @adapter: board private structure
5467 *
5468 * Free all receive software resources
5469 **/
5470static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5471{
5472 int i;
5473
5474 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005475 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005476 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005477}
5478
5479/**
Auke Kok9a799d72007-09-15 14:07:45 -07005480 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5481 * @netdev: network interface device structure
5482 * @new_mtu: new value for maximum frame size
5483 *
5484 * Returns 0 on success, negative on failure
5485 **/
5486static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5487{
5488 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005489 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005490 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5491
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005492 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005493 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5494 hw->mac.type != ixgbe_mac_X540) {
5495 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5496 return -EINVAL;
5497 } else {
5498 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5499 return -EINVAL;
5500 }
Auke Kok9a799d72007-09-15 14:07:45 -07005501
Emil Tantilov396e7992010-07-01 20:05:12 +00005502 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005503 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005504 netdev->mtu = new_mtu;
5505
John Fastabend16b61be2010-11-16 19:26:44 -08005506 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5507 hw->fc.low_water = FC_LOW_WATER(max_frame);
5508
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005509 if (netif_running(netdev))
5510 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005511
5512 return 0;
5513}
5514
5515/**
5516 * ixgbe_open - Called when a network interface is made active
5517 * @netdev: network interface device structure
5518 *
5519 * Returns 0 on success, negative value on failure
5520 *
5521 * The open entry point is called when a network interface is made
5522 * active by the system (IFF_UP). At this point all resources needed
5523 * for transmit and receive operations are allocated, the interrupt
5524 * handler is registered with the OS, the watchdog timer is started,
5525 * and the stack is notified that the interface is ready.
5526 **/
5527static int ixgbe_open(struct net_device *netdev)
5528{
5529 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5530 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005531
Auke Kok4bebfaa2008-02-11 09:26:01 -08005532 /* disallow open during test */
5533 if (test_bit(__IXGBE_TESTING, &adapter->state))
5534 return -EBUSY;
5535
Jesse Brandeburg54386462009-04-17 20:44:27 +00005536 netif_carrier_off(netdev);
5537
Auke Kok9a799d72007-09-15 14:07:45 -07005538 /* allocate transmit descriptors */
5539 err = ixgbe_setup_all_tx_resources(adapter);
5540 if (err)
5541 goto err_setup_tx;
5542
Auke Kok9a799d72007-09-15 14:07:45 -07005543 /* allocate receive descriptors */
5544 err = ixgbe_setup_all_rx_resources(adapter);
5545 if (err)
5546 goto err_setup_rx;
5547
5548 ixgbe_configure(adapter);
5549
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005550 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005551 if (err)
5552 goto err_req_irq;
5553
Auke Kok9a799d72007-09-15 14:07:45 -07005554 err = ixgbe_up_complete(adapter);
5555 if (err)
5556 goto err_up;
5557
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005558 netif_tx_start_all_queues(netdev);
5559
Auke Kok9a799d72007-09-15 14:07:45 -07005560 return 0;
5561
5562err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005563 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005564 ixgbe_free_irq(adapter);
5565err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005566err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005567 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005568err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005569 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005570 ixgbe_reset(adapter);
5571
5572 return err;
5573}
5574
5575/**
5576 * ixgbe_close - Disables a network interface
5577 * @netdev: network interface device structure
5578 *
5579 * Returns 0, this is not allowed to fail
5580 *
5581 * The close entry point is called when an interface is de-activated
5582 * by the OS. The hardware is still under the drivers control, but
5583 * needs to be disabled. A global MAC reset is issued to stop the
5584 * hardware, and all transmit and receive resources are freed.
5585 **/
5586static int ixgbe_close(struct net_device *netdev)
5587{
5588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005589
5590 ixgbe_down(adapter);
5591 ixgbe_free_irq(adapter);
5592
5593 ixgbe_free_all_tx_resources(adapter);
5594 ixgbe_free_all_rx_resources(adapter);
5595
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005596 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005597
5598 return 0;
5599}
5600
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005601#ifdef CONFIG_PM
5602static int ixgbe_resume(struct pci_dev *pdev)
5603{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005604 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5605 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005606 u32 err;
5607
5608 pci_set_power_state(pdev, PCI_D0);
5609 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005610 /*
5611 * pci_restore_state clears dev->state_saved so call
5612 * pci_save_state to restore it.
5613 */
5614 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005615
5616 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005617 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005618 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005619 return err;
5620 }
5621 pci_set_master(pdev);
5622
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005623 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005624
5625 err = ixgbe_init_interrupt_scheme(adapter);
5626 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005627 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628 return err;
5629 }
5630
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005631 ixgbe_reset(adapter);
5632
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005633 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5634
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005635 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005636 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005637 if (err)
5638 return err;
5639 }
5640
5641 netif_device_attach(netdev);
5642
5643 return 0;
5644}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005645#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005646
5647static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005648{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005649 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5650 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005651 struct ixgbe_hw *hw = &adapter->hw;
5652 u32 ctrl, fctrl;
5653 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005654#ifdef CONFIG_PM
5655 int retval = 0;
5656#endif
5657
5658 netif_device_detach(netdev);
5659
5660 if (netif_running(netdev)) {
5661 ixgbe_down(adapter);
5662 ixgbe_free_irq(adapter);
5663 ixgbe_free_all_tx_resources(adapter);
5664 ixgbe_free_all_rx_resources(adapter);
5665 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005666
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005667 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005668#ifdef CONFIG_DCB
5669 kfree(adapter->ixgbe_ieee_pfc);
5670 kfree(adapter->ixgbe_ieee_ets);
5671#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005672
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005673#ifdef CONFIG_PM
5674 retval = pci_save_state(pdev);
5675 if (retval)
5676 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005677
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005678#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005679 if (wufc) {
5680 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005681
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005682 /* turn on all-multi mode if wake on multicast is enabled */
5683 if (wufc & IXGBE_WUFC_MC) {
5684 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5685 fctrl |= IXGBE_FCTRL_MPE;
5686 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5687 }
5688
5689 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5690 ctrl |= IXGBE_CTRL_GIO_DIS;
5691 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5692
5693 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5694 } else {
5695 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5696 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5697 }
5698
Alexander Duyckbd508172010-11-16 19:27:03 -08005699 switch (hw->mac.type) {
5700 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005701 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005702 break;
5703 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005704 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005705 pci_wake_from_d3(pdev, !!wufc);
5706 break;
5707 default:
5708 break;
5709 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005710
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005711 *enable_wake = !!wufc;
5712
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005713 ixgbe_release_hw_control(adapter);
5714
5715 pci_disable_device(pdev);
5716
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005717 return 0;
5718}
5719
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005720#ifdef CONFIG_PM
5721static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5722{
5723 int retval;
5724 bool wake;
5725
5726 retval = __ixgbe_shutdown(pdev, &wake);
5727 if (retval)
5728 return retval;
5729
5730 if (wake) {
5731 pci_prepare_to_sleep(pdev);
5732 } else {
5733 pci_wake_from_d3(pdev, false);
5734 pci_set_power_state(pdev, PCI_D3hot);
5735 }
5736
5737 return 0;
5738}
5739#endif /* CONFIG_PM */
5740
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005741static void ixgbe_shutdown(struct pci_dev *pdev)
5742{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005743 bool wake;
5744
5745 __ixgbe_shutdown(pdev, &wake);
5746
5747 if (system_state == SYSTEM_POWER_OFF) {
5748 pci_wake_from_d3(pdev, wake);
5749 pci_set_power_state(pdev, PCI_D3hot);
5750 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005751}
5752
5753/**
Auke Kok9a799d72007-09-15 14:07:45 -07005754 * ixgbe_update_stats - Update the board statistics counters.
5755 * @adapter: board private structure
5756 **/
5757void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5758{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005759 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005760 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005761 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005762 u64 total_mpc = 0;
5763 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005764 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5765 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5766 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005767
Don Skidmored08935c2010-06-11 13:20:29 +00005768 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5769 test_bit(__IXGBE_RESETTING, &adapter->state))
5770 return;
5771
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005772 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005773 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005774 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005775 for (i = 0; i < 16; i++)
5776 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005777 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005778 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005779 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5780 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005781 }
5782 adapter->rsc_total_count = rsc_count;
5783 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005784 }
5785
Alexander Duyck5b7da512010-11-16 19:26:50 -08005786 for (i = 0; i < adapter->num_rx_queues; i++) {
5787 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5788 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5789 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5790 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5791 bytes += rx_ring->stats.bytes;
5792 packets += rx_ring->stats.packets;
5793 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005794 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005795 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5796 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5797 netdev->stats.rx_bytes = bytes;
5798 netdev->stats.rx_packets = packets;
5799
5800 bytes = 0;
5801 packets = 0;
5802 /* gather some stats to the adapter struct that are per queue */
5803 for (i = 0; i < adapter->num_tx_queues; i++) {
5804 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5805 restart_queue += tx_ring->tx_stats.restart_queue;
5806 tx_busy += tx_ring->tx_stats.tx_busy;
5807 bytes += tx_ring->stats.bytes;
5808 packets += tx_ring->stats.packets;
5809 }
5810 adapter->restart_queue = restart_queue;
5811 adapter->tx_busy = tx_busy;
5812 netdev->stats.tx_bytes = bytes;
5813 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005814
Joe Perches7ca647b2010-09-07 21:35:40 +00005815 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005816 for (i = 0; i < 8; i++) {
5817 /* for packet buffers not used, the register should read 0 */
5818 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5819 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005820 hwstats->mpc[i] += mpc;
5821 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005822 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005823 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5824 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5825 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5826 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5827 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005828 switch (hw->mac.type) {
5829 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005830 hwstats->pxonrxc[i] +=
5831 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005832 break;
5833 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005834 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005835 hwstats->pxonrxc[i] +=
5836 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005837 break;
5838 default:
5839 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005840 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005841 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5842 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005843 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005844 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005845 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005846 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005847
John Fastabendc84d3242010-11-16 19:27:12 -08005848 ixgbe_update_xoff_received(adapter);
5849
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005850 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005851 switch (hw->mac.type) {
5852 case ixgbe_mac_82598EB:
5853 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005854 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5855 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5856 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5857 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005858 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005859 /* OS2BMC stats are X540 only*/
5860 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5861 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5862 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5863 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5864 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005865 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005866 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005867 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005868 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005869 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005870 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005871 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005872 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5873 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005874#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005875 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5876 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5877 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5878 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5879 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5880 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005881#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005882 break;
5883 default:
5884 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005885 }
Auke Kok9a799d72007-09-15 14:07:45 -07005886 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005887 hwstats->bprc += bprc;
5888 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005889 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005890 hwstats->mprc -= bprc;
5891 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5892 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5893 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5894 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5895 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5896 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5897 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5898 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005899 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005900 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005901 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005902 hwstats->lxofftxc += lxoff;
5903 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5904 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5905 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005906 /*
5907 * 82598 errata - tx of flow control packets is included in tx counters
5908 */
5909 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005910 hwstats->gptc -= xon_off_tot;
5911 hwstats->mptc -= xon_off_tot;
5912 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5913 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5914 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5915 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5916 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5917 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5918 hwstats->ptc64 -= xon_off_tot;
5919 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5920 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5921 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5922 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5923 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5924 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005925
5926 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005927 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005928
5929 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005930 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005931 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005932 netdev->stats.rx_length_errors = hwstats->rlec;
5933 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005934 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005935}
5936
5937/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005938 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5939 * @adapter - pointer to the device adapter structure
Auke Kok9a799d72007-09-15 14:07:45 -07005940 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005941static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07005942{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005943 struct ixgbe_hw *hw = &adapter->hw;
5944 int i;
5945
Alexander Duyckd034acf2011-04-27 09:25:34 +00005946 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5947 return;
5948
5949 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5950
5951 /* if interface is down do nothing */
5952 if (test_bit(__IXGBE_DOWN, &adapter->state))
5953 return;
5954
5955 /* do nothing if we are not using signature filters */
5956 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5957 return;
5958
5959 adapter->fdir_overflow++;
5960
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005961 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5962 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005963 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005964 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005965 /* re-enable flow director interrupts */
5966 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005967 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005968 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00005969 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005970 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005971}
5972
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005973/**
5974 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
5975 * @adapter - pointer to the device adapter structure
5976 *
5977 * This function serves two purposes. First it strobes the interrupt lines
5978 * in order to make certain interrupts are occuring. Secondly it sets the
5979 * bits needed to check for TX hangs. As a result we should immediately
5980 * determine if a hang has occured.
5981 */
5982static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
5983{
Auke Kok9a799d72007-09-15 14:07:45 -07005984 struct ixgbe_hw *hw = &adapter->hw;
5985 u64 eics = 0;
5986 int i;
5987
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005988 /* If we're down or resetting, just bail */
5989 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5990 test_bit(__IXGBE_RESETTING, &adapter->state))
5991 return;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005992
Alexander Duyck93c52dd2011-04-22 04:07:54 +00005993 /* Force detection of hung controller */
5994 if (netif_carrier_ok(adapter->netdev)) {
5995 for (i = 0; i < adapter->num_tx_queues; i++)
5996 set_check_for_tx_hang(adapter->tx_ring[i]);
5997 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00005998
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005999 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00006000 /*
6001 * for legacy and MSI interrupts don't set any bits
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006002 * that are enabled for EIAM, because this operation
Alexander Duyckfe49f042009-06-04 16:00:09 +00006003 * would set *both* EIMS and EICS for any bit in EIAM
6004 */
6005 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6006 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006007 } else {
6008 /* get one bit for every active tx/rx interrupt vector */
6009 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6010 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6011 if (qv->rxr_count || qv->txr_count)
6012 eics |= ((u64)1 << i);
6013 }
Alexander Duyckfe49f042009-06-04 16:00:09 +00006014 }
6015
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006016 /* Cause software interrupt to ensure rings are cleaned */
Alexander Duyckfe49f042009-06-04 16:00:09 +00006017 ixgbe_irq_rearm_queues(adapter, eics);
6018
Alexander Duyckfe49f042009-06-04 16:00:09 +00006019}
6020
6021/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006022 * ixgbe_watchdog_update_link - update the link status
6023 * @adapter - pointer to the device adapter structure
6024 * @link_speed - pointer to a u32 to store the link_speed
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006025 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006026static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006027{
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006028 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006029 u32 link_speed = adapter->link_speed;
6030 bool link_up = adapter->link_up;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006031 int i;
6032
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006033 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6034 return;
6035
6036 if (hw->mac.ops.check_link) {
6037 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006038 } else {
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006039 /* always assume link is up, if no check link function */
6040 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6041 link_up = true;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006042 }
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006043 if (link_up) {
6044 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6045 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6046 hw->mac.ops.fc_enable(hw, i);
6047 } else {
6048 hw->mac.ops.fc_enable(hw, 0);
6049 }
6050 }
6051
6052 if (link_up ||
6053 time_after(jiffies, (adapter->link_check_timeout +
6054 IXGBE_TRY_LINK_TIMEOUT))) {
6055 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6056 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6057 IXGBE_WRITE_FLUSH(hw);
6058 }
6059
6060 adapter->link_up = link_up;
6061 adapter->link_speed = link_speed;
6062}
6063
6064/**
6065 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6066 * print link up message
6067 * @adapter - pointer to the device adapter structure
6068 **/
6069static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6070{
6071 struct net_device *netdev = adapter->netdev;
6072 struct ixgbe_hw *hw = &adapter->hw;
6073 u32 link_speed = adapter->link_speed;
6074 bool flow_rx, flow_tx;
6075
6076 /* only continue if link was previously down */
6077 if (netif_carrier_ok(netdev))
6078 return;
6079
6080 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6081
6082 switch (hw->mac.type) {
6083 case ixgbe_mac_82598EB: {
6084 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6085 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6086 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6087 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6088 }
6089 break;
6090 case ixgbe_mac_X540:
6091 case ixgbe_mac_82599EB: {
6092 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6093 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6094 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6095 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6096 }
6097 break;
6098 default:
6099 flow_tx = false;
6100 flow_rx = false;
6101 break;
6102 }
6103 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6104 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6105 "10 Gbps" :
6106 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6107 "1 Gbps" :
6108 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6109 "100 Mbps" :
6110 "unknown speed"))),
6111 ((flow_rx && flow_tx) ? "RX/TX" :
6112 (flow_rx ? "RX" :
6113 (flow_tx ? "TX" : "None"))));
6114
6115 netif_carrier_on(netdev);
6116#ifdef HAVE_IPLINK_VF_CONFIG
6117 ixgbe_check_vf_rate_limit(adapter);
6118#endif /* HAVE_IPLINK_VF_CONFIG */
6119}
6120
6121/**
6122 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6123 * print link down message
6124 * @adapter - pointer to the adapter structure
6125 **/
6126static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6127{
6128 struct net_device *netdev = adapter->netdev;
6129 struct ixgbe_hw *hw = &adapter->hw;
6130
6131 adapter->link_up = false;
6132 adapter->link_speed = 0;
6133
6134 /* only continue if link was up previously */
6135 if (!netif_carrier_ok(netdev))
6136 return;
6137
6138 /* poll for SFP+ cable when link is down */
6139 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6140 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6141
6142 e_info(drv, "NIC Link is Down\n");
6143 netif_carrier_off(netdev);
6144}
6145
6146/**
6147 * ixgbe_watchdog_flush_tx - flush queues on link down
6148 * @adapter - pointer to the device adapter structure
6149 **/
6150static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6151{
6152 int i;
6153 int some_tx_pending = 0;
6154
6155 if (!netif_carrier_ok(adapter->netdev)) {
6156 for (i = 0; i < adapter->num_tx_queues; i++) {
6157 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6158 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6159 some_tx_pending = 1;
6160 break;
6161 }
6162 }
6163
6164 if (some_tx_pending) {
6165 /* We've lost link, so the controller stops DMA,
6166 * but we've got queued Tx work that's never going
6167 * to get done, so reset controller to flush Tx.
6168 * (Do the reset outside of interrupt context).
6169 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006170 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006171 }
6172 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006173}
6174
Greg Rosea985b6c32010-11-18 03:02:52 +00006175static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6176{
6177 u32 ssvpc;
6178
6179 /* Do not perform spoof check for 82598 */
6180 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6181 return;
6182
6183 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6184
6185 /*
6186 * ssvpc register is cleared on read, if zero then no
6187 * spoofed packets in the last interval.
6188 */
6189 if (!ssvpc)
6190 return;
6191
6192 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6193}
6194
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006195/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006196 * ixgbe_watchdog_subtask - check and bring link up
6197 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006198 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006199static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006200{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006201 /* if interface is down do nothing */
6202 if (test_bit(__IXGBE_DOWN, &adapter->state))
6203 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006204
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006205 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006206
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006207 if (adapter->link_up)
6208 ixgbe_watchdog_link_is_up(adapter);
6209 else
6210 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006211
Greg Rosea985b6c32010-11-18 03:02:52 +00006212 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006213 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006214
6215 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006216}
6217
Alexander Duyck70864002011-04-27 09:13:56 +00006218/**
6219 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6220 * @adapter - the ixgbe adapter structure
6221 **/
6222static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6223{
6224 struct ixgbe_hw *hw = &adapter->hw;
6225 s32 err;
6226
6227 /* not searching for SFP so there is nothing to do here */
6228 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6229 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6230 return;
6231
6232 /* someone else is in init, wait until next service event */
6233 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6234 return;
6235
6236 err = hw->phy.ops.identify_sfp(hw);
6237 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6238 goto sfp_out;
6239
6240 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6241 /* If no cable is present, then we need to reset
6242 * the next time we find a good cable. */
6243 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6244 }
6245
6246 /* exit on error */
6247 if (err)
6248 goto sfp_out;
6249
6250 /* exit if reset not needed */
6251 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6252 goto sfp_out;
6253
6254 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6255
6256 /*
6257 * A module may be identified correctly, but the EEPROM may not have
6258 * support for that module. setup_sfp() will fail in that case, so
6259 * we should not allow that module to load.
6260 */
6261 if (hw->mac.type == ixgbe_mac_82598EB)
6262 err = hw->phy.ops.reset(hw);
6263 else
6264 err = hw->mac.ops.setup_sfp(hw);
6265
6266 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6267 goto sfp_out;
6268
6269 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6270 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6271
6272sfp_out:
6273 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6274
6275 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6276 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6277 e_dev_err("failed to initialize because an unsupported "
6278 "SFP+ module type was detected.\n");
6279 e_dev_err("Reload the driver after installing a "
6280 "supported module.\n");
6281 unregister_netdev(adapter->netdev);
6282 }
6283}
6284
6285/**
6286 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6287 * @adapter - the ixgbe adapter structure
6288 **/
6289static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6290{
6291 struct ixgbe_hw *hw = &adapter->hw;
6292 u32 autoneg;
6293 bool negotiation;
6294
6295 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6296 return;
6297
6298 /* someone else is in init, wait until next service event */
6299 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6300 return;
6301
6302 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6303
6304 autoneg = hw->phy.autoneg_advertised;
6305 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6306 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6307 hw->mac.autotry_restart = false;
6308 if (hw->mac.ops.setup_link)
6309 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6310
6311 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6312 adapter->link_check_timeout = jiffies;
6313 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6314}
6315
6316/**
6317 * ixgbe_service_timer - Timer Call-back
6318 * @data: pointer to adapter cast into an unsigned long
6319 **/
6320static void ixgbe_service_timer(unsigned long data)
6321{
6322 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6323 unsigned long next_event_offset;
6324
6325 /* poll faster when waiting for link */
6326 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6327 next_event_offset = HZ / 10;
6328 else
6329 next_event_offset = HZ * 2;
6330
6331 /* Reset the timer */
6332 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6333
6334 ixgbe_service_event_schedule(adapter);
6335}
6336
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006337static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6338{
6339 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6340 return;
6341
6342 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6343
6344 /* If we're already down or resetting, just bail */
6345 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6346 test_bit(__IXGBE_RESETTING, &adapter->state))
6347 return;
6348
6349 ixgbe_dump(adapter);
6350 netdev_err(adapter->netdev, "Reset adapter\n");
6351 adapter->tx_timeout_count++;
6352
6353 ixgbe_reinit_locked(adapter);
6354}
6355
Alexander Duyck70864002011-04-27 09:13:56 +00006356/**
6357 * ixgbe_service_task - manages and runs subtasks
6358 * @work: pointer to work_struct containing our data
6359 **/
6360static void ixgbe_service_task(struct work_struct *work)
6361{
6362 struct ixgbe_adapter *adapter = container_of(work,
6363 struct ixgbe_adapter,
6364 service_task);
6365
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006366 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006367 ixgbe_sfp_detection_subtask(adapter);
6368 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006369 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006370 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006371 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006372 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006373
6374 ixgbe_service_event_complete(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006375}
6376
Auke Kok9a799d72007-09-15 14:07:45 -07006377static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006378 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006379 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006380{
6381 struct ixgbe_adv_tx_context_desc *context_desc;
6382 unsigned int i;
6383 int err;
6384 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006385 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6386 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006387
6388 if (skb_is_gso(skb)) {
6389 if (skb_header_cloned(skb)) {
6390 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6391 if (err)
6392 return err;
6393 }
6394 l4len = tcp_hdrlen(skb);
6395 *hdr_len += l4len;
6396
Hao Zheng5e09a102010-11-11 13:47:59 +00006397 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006398 struct iphdr *iph = ip_hdr(skb);
6399 iph->tot_len = 0;
6400 iph->check = 0;
6401 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006402 iph->daddr, 0,
6403 IPPROTO_TCP,
6404 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006405 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006406 ipv6_hdr(skb)->payload_len = 0;
6407 tcp_hdr(skb)->check =
6408 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006409 &ipv6_hdr(skb)->daddr,
6410 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006411 }
6412
6413 i = tx_ring->next_to_use;
6414
6415 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006416 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006417
6418 /* VLAN MACLEN IPLEN */
6419 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6420 vlan_macip_lens |=
6421 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6422 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006423 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006424 *hdr_len += skb_network_offset(skb);
6425 vlan_macip_lens |=
6426 (skb_transport_header(skb) - skb_network_header(skb));
6427 *hdr_len +=
6428 (skb_transport_header(skb) - skb_network_header(skb));
6429 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6430 context_desc->seqnum_seed = 0;
6431
6432 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006433 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006434 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006435
Hao Zheng5e09a102010-11-11 13:47:59 +00006436 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006437 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6438 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6439 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6440
6441 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006442 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006443 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6444 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006445 /* use index 1 for TSO */
6446 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006447 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6448
6449 tx_buffer_info->time_stamp = jiffies;
6450 tx_buffer_info->next_to_watch = i;
6451
6452 i++;
6453 if (i == tx_ring->count)
6454 i = 0;
6455 tx_ring->next_to_use = i;
6456
6457 return true;
6458 }
6459 return false;
6460}
6461
Hao Zheng5e09a102010-11-11 13:47:59 +00006462static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6463 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006464{
6465 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006466
6467 switch (protocol) {
6468 case cpu_to_be16(ETH_P_IP):
6469 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6470 switch (ip_hdr(skb)->protocol) {
6471 case IPPROTO_TCP:
6472 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6473 break;
6474 case IPPROTO_SCTP:
6475 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6476 break;
6477 }
6478 break;
6479 case cpu_to_be16(ETH_P_IPV6):
6480 /* XXX what about other V6 headers?? */
6481 switch (ipv6_hdr(skb)->nexthdr) {
6482 case IPPROTO_TCP:
6483 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6484 break;
6485 case IPPROTO_SCTP:
6486 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6487 break;
6488 }
6489 break;
6490 default:
6491 if (unlikely(net_ratelimit()))
6492 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006493 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006494 break;
6495 }
6496
6497 return rtn;
6498}
6499
Auke Kok9a799d72007-09-15 14:07:45 -07006500static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006501 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006502 struct sk_buff *skb, u32 tx_flags,
6503 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006504{
6505 struct ixgbe_adv_tx_context_desc *context_desc;
6506 unsigned int i;
6507 struct ixgbe_tx_buffer *tx_buffer_info;
6508 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6509
6510 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6511 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6512 i = tx_ring->next_to_use;
6513 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006514 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006515
6516 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6517 vlan_macip_lens |=
6518 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6519 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006520 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006521 if (skb->ip_summed == CHECKSUM_PARTIAL)
6522 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006523 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006524
6525 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6526 context_desc->seqnum_seed = 0;
6527
6528 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006529 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006530
Joe Perches7ca647b2010-09-07 21:35:40 +00006531 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006532 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006533
6534 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006535 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006536 context_desc->mss_l4len_idx = 0;
6537
6538 tx_buffer_info->time_stamp = jiffies;
6539 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006540
Auke Kok9a799d72007-09-15 14:07:45 -07006541 i++;
6542 if (i == tx_ring->count)
6543 i = 0;
6544 tx_ring->next_to_use = i;
6545
6546 return true;
6547 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006548
Auke Kok9a799d72007-09-15 14:07:45 -07006549 return false;
6550}
6551
6552static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006553 struct ixgbe_ring *tx_ring,
6554 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006555 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006556{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006557 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006558 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006559 unsigned int len;
6560 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006561 unsigned int offset = 0, size, count = 0, i;
6562 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6563 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006564 unsigned int bytecount = skb->len;
6565 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006566
6567 i = tx_ring->next_to_use;
6568
Yi Zoueacd73f2009-05-13 13:11:06 +00006569 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6570 /* excluding fcoe_crc_eof for FCoE */
6571 total -= sizeof(struct fcoe_crc_eof);
6572
6573 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006574 while (len) {
6575 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6576 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6577
6578 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006579 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006580 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006581 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006582 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006583 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006584 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006585 tx_buffer_info->time_stamp = jiffies;
6586 tx_buffer_info->next_to_watch = i;
6587
6588 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006589 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006590 offset += size;
6591 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006592
6593 if (len) {
6594 i++;
6595 if (i == tx_ring->count)
6596 i = 0;
6597 }
Auke Kok9a799d72007-09-15 14:07:45 -07006598 }
6599
6600 for (f = 0; f < nr_frags; f++) {
6601 struct skb_frag_struct *frag;
6602
6603 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006604 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006605 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006606
6607 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006608 i++;
6609 if (i == tx_ring->count)
6610 i = 0;
6611
Auke Kok9a799d72007-09-15 14:07:45 -07006612 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6613 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6614
6615 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006616 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006617 frag->page,
6618 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006619 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006620 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006621 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006622 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006623 tx_buffer_info->time_stamp = jiffies;
6624 tx_buffer_info->next_to_watch = i;
6625
6626 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006627 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006628 offset += size;
6629 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006630 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006631 if (total == 0)
6632 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006633 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006634
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006635 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6636 gso_segs = skb_shinfo(skb)->gso_segs;
6637#ifdef IXGBE_FCOE
6638 /* adjust for FCoE Sequence Offload */
6639 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6640 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6641 skb_shinfo(skb)->gso_size);
6642#endif /* IXGBE_FCOE */
6643 bytecount += (gso_segs - 1) * hdr_len;
6644
6645 /* multiply data chunks by size of headers */
6646 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6647 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006648 tx_ring->tx_buffer_info[i].skb = skb;
6649 tx_ring->tx_buffer_info[first].next_to_watch = i;
6650
6651 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006652
6653dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006654 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006655
6656 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6657 tx_buffer_info->dma = 0;
6658 tx_buffer_info->time_stamp = 0;
6659 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006660 if (count)
6661 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006662
6663 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006664 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006665 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006666 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006667 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006668 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006669 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006670 }
6671
Anton Blancharde44d38e2010-02-03 13:12:51 +00006672 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006673}
6674
Alexander Duyck84ea2592010-11-16 19:26:49 -08006675static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006676 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006677{
6678 union ixgbe_adv_tx_desc *tx_desc = NULL;
6679 struct ixgbe_tx_buffer *tx_buffer_info;
6680 u32 olinfo_status = 0, cmd_type_len = 0;
6681 unsigned int i;
6682 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6683
6684 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6685
6686 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6687
6688 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6689 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6690
6691 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6692 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6693
6694 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006695 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006696
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006697 /* use index 1 context for tso */
6698 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006699 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6700 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006701 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006702
6703 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6704 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006705 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006706
Yi Zoueacd73f2009-05-13 13:11:06 +00006707 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6708 olinfo_status |= IXGBE_ADVTXD_CC;
6709 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6710 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6711 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6712 }
6713
Auke Kok9a799d72007-09-15 14:07:45 -07006714 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6715
6716 i = tx_ring->next_to_use;
6717 while (count--) {
6718 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006719 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006720 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6721 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006722 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006723 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006724 i++;
6725 if (i == tx_ring->count)
6726 i = 0;
6727 }
6728
6729 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6730
6731 /*
6732 * Force memory writes to complete before letting h/w
6733 * know there are new descriptors to fetch. (Only
6734 * applicable for weak-ordered memory model archs,
6735 * such as IA-64).
6736 */
6737 wmb();
6738
6739 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006740 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006741}
6742
Alexander Duyck69830522011-01-06 14:29:58 +00006743static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6744 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006745{
Alexander Duyck69830522011-01-06 14:29:58 +00006746 struct ixgbe_q_vector *q_vector = ring->q_vector;
6747 union ixgbe_atr_hash_dword input = { .dword = 0 };
6748 union ixgbe_atr_hash_dword common = { .dword = 0 };
6749 union {
6750 unsigned char *network;
6751 struct iphdr *ipv4;
6752 struct ipv6hdr *ipv6;
6753 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006754 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006755 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006756
Alexander Duyck69830522011-01-06 14:29:58 +00006757 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6758 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006759 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006760
Alexander Duyck69830522011-01-06 14:29:58 +00006761 /* do nothing if sampling is disabled */
6762 if (!ring->atr_sample_rate)
6763 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006764
Alexander Duyck69830522011-01-06 14:29:58 +00006765 ring->atr_count++;
6766
6767 /* snag network header to get L4 type and address */
6768 hdr.network = skb_network_header(skb);
6769
6770 /* Currently only IPv4/IPv6 with TCP is supported */
6771 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6772 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6773 (protocol != __constant_htons(ETH_P_IP) ||
6774 hdr.ipv4->protocol != IPPROTO_TCP))
6775 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006776
6777 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006778
Alexander Duyck69830522011-01-06 14:29:58 +00006779 /* skip this packet since the socket is closing */
6780 if (th->fin)
6781 return;
6782
6783 /* sample on all syn packets or once every atr sample count */
6784 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6785 return;
6786
6787 /* reset sample count */
6788 ring->atr_count = 0;
6789
6790 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6791
6792 /*
6793 * src and dst are inverted, think how the receiver sees them
6794 *
6795 * The input is broken into two sections, a non-compressed section
6796 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6797 * is XORed together and stored in the compressed dword.
6798 */
6799 input.formatted.vlan_id = vlan_id;
6800
6801 /*
6802 * since src port and flex bytes occupy the same word XOR them together
6803 * and write the value to source port portion of compressed dword
6804 */
6805 if (vlan_id)
6806 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6807 else
6808 common.port.src ^= th->dest ^ protocol;
6809 common.port.dst ^= th->source;
6810
6811 if (protocol == __constant_htons(ETH_P_IP)) {
6812 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6813 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6814 } else {
6815 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6816 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6817 hdr.ipv6->saddr.s6_addr32[1] ^
6818 hdr.ipv6->saddr.s6_addr32[2] ^
6819 hdr.ipv6->saddr.s6_addr32[3] ^
6820 hdr.ipv6->daddr.s6_addr32[0] ^
6821 hdr.ipv6->daddr.s6_addr32[1] ^
6822 hdr.ipv6->daddr.s6_addr32[2] ^
6823 hdr.ipv6->daddr.s6_addr32[3];
6824 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006825
6826 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006827 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6828 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006829}
6830
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006831static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006832{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006833 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006834 /* Herbert's original patch had:
6835 * smp_mb__after_netif_stop_queue();
6836 * but since that doesn't exist yet, just open code it. */
6837 smp_mb();
6838
6839 /* We need to check again in a case another CPU has just
6840 * made room available. */
6841 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6842 return -EBUSY;
6843
6844 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006845 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006846 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006847 return 0;
6848}
6849
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006850static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006851{
6852 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6853 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006854 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006855}
6856
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006857static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6858{
6859 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006860 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006861#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006862 __be16 protocol;
6863
6864 protocol = vlan_get_protocol(skb);
6865
John Fastabende5b64632011-03-08 03:44:52 +00006866 if (((protocol == htons(ETH_P_FCOE)) ||
6867 (protocol == htons(ETH_P_FIP))) &&
6868 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6869 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6870 txq += adapter->ring_feature[RING_F_FCOE].mask;
6871 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006872 }
6873#endif
6874
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006875 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6876 while (unlikely(txq >= dev->real_num_tx_queues))
6877 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006878 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006879 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006880
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006881 return skb_tx_hash(dev, skb);
6882}
6883
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006884netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006885 struct ixgbe_adapter *adapter,
6886 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006887{
Auke Kok9a799d72007-09-15 14:07:45 -07006888 unsigned int first;
6889 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006890 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006891 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006892 int count = 0;
6893 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006894 __be16 protocol;
6895
6896 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006897
Jesse Grosseab6d182010-10-20 13:56:03 +00006898 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006899 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006900 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6901 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006902 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006903 }
6904 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6905 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006906 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6907 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006908 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006909 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6910 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006911 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006912
Yi Zou09ad1cc2009-09-03 14:56:10 +00006913#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006914 /* for FCoE with DCB, we force the priority to what
6915 * was specified by the switch */
6916 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006917 (protocol == htons(ETH_P_FCOE)))
6918 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006919#endif
6920
Yi Zoueacd73f2009-05-13 13:11:06 +00006921 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006922 if (skb_is_gso(skb) ||
6923 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006924 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6925 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006926 count++;
6927
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006928 count += TXD_USE_COUNT(skb_headlen(skb));
6929 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006930 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6931
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006932 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006933 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006934 return NETDEV_TX_BUSY;
6935 }
Auke Kok9a799d72007-09-15 14:07:45 -07006936
Auke Kok9a799d72007-09-15 14:07:45 -07006937 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006938 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6939#ifdef IXGBE_FCOE
6940 /* setup tx offload for FCoE */
6941 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6942 if (tso < 0) {
6943 dev_kfree_skb_any(skb);
6944 return NETDEV_TX_OK;
6945 }
6946 if (tso)
6947 tx_flags |= IXGBE_TX_FLAGS_FSO;
6948#endif /* IXGBE_FCOE */
6949 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006950 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006951 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006952 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6953 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006954 if (tso < 0) {
6955 dev_kfree_skb_any(skb);
6956 return NETDEV_TX_OK;
6957 }
6958
6959 if (tso)
6960 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006961 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6962 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006963 (skb->ip_summed == CHECKSUM_PARTIAL))
6964 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006965 }
6966
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006967 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006968 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006969 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006970 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6971 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006972 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006973 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006974
Alexander Duyck44df32c2009-03-31 21:34:23 +00006975 } else {
6976 dev_kfree_skb_any(skb);
6977 tx_ring->tx_buffer_info[first].time_stamp = 0;
6978 tx_ring->next_to_use = first;
6979 }
Auke Kok9a799d72007-09-15 14:07:45 -07006980
6981 return NETDEV_TX_OK;
6982}
6983
Alexander Duyck84418e32010-08-19 13:40:54 +00006984static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6985{
6986 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6987 struct ixgbe_ring *tx_ring;
6988
6989 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006990 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006991}
6992
Auke Kok9a799d72007-09-15 14:07:45 -07006993/**
Auke Kok9a799d72007-09-15 14:07:45 -07006994 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6995 * @netdev: network interface device structure
6996 * @p: pointer to an address structure
6997 *
6998 * Returns 0 on success, negative on failure
6999 **/
7000static int ixgbe_set_mac(struct net_device *netdev, void *p)
7001{
7002 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007003 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07007004 struct sockaddr *addr = p;
7005
7006 if (!is_valid_ether_addr(addr->sa_data))
7007 return -EADDRNOTAVAIL;
7008
7009 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007010 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007011
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007012 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7013 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07007014
7015 return 0;
7016}
7017
Ben Hutchings6b73e102009-04-29 08:08:58 +00007018static int
7019ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7020{
7021 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7022 struct ixgbe_hw *hw = &adapter->hw;
7023 u16 value;
7024 int rc;
7025
7026 if (prtad != hw->phy.mdio.prtad)
7027 return -EINVAL;
7028 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7029 if (!rc)
7030 rc = value;
7031 return rc;
7032}
7033
7034static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7035 u16 addr, u16 value)
7036{
7037 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7038 struct ixgbe_hw *hw = &adapter->hw;
7039
7040 if (prtad != hw->phy.mdio.prtad)
7041 return -EINVAL;
7042 return hw->phy.ops.write_reg(hw, addr, devad, value);
7043}
7044
7045static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7046{
7047 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7048
7049 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7050}
7051
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007052/**
7053 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007054 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007055 * @netdev: network interface device structure
7056 *
7057 * Returns non-zero on failure
7058 **/
7059static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7060{
7061 int err = 0;
7062 struct ixgbe_adapter *adapter = netdev_priv(dev);
7063 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7064
7065 if (is_valid_ether_addr(mac->san_addr)) {
7066 rtnl_lock();
7067 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7068 rtnl_unlock();
7069 }
7070 return err;
7071}
7072
7073/**
7074 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007075 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007076 * @netdev: network interface device structure
7077 *
7078 * Returns non-zero on failure
7079 **/
7080static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7081{
7082 int err = 0;
7083 struct ixgbe_adapter *adapter = netdev_priv(dev);
7084 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7085
7086 if (is_valid_ether_addr(mac->san_addr)) {
7087 rtnl_lock();
7088 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7089 rtnl_unlock();
7090 }
7091 return err;
7092}
7093
Auke Kok9a799d72007-09-15 14:07:45 -07007094#ifdef CONFIG_NET_POLL_CONTROLLER
7095/*
7096 * Polling 'interrupt' - used by things like netconsole to send skbs
7097 * without having to re-enable interrupts. It's not called while
7098 * the interrupt routine is executing.
7099 */
7100static void ixgbe_netpoll(struct net_device *netdev)
7101{
7102 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007103 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007104
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007105 /* if interface is down do nothing */
7106 if (test_bit(__IXGBE_DOWN, &adapter->state))
7107 return;
7108
Auke Kok9a799d72007-09-15 14:07:45 -07007109 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007110 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7111 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7112 for (i = 0; i < num_q_vectors; i++) {
7113 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7114 ixgbe_msix_clean_many(0, q_vector);
7115 }
7116 } else {
7117 ixgbe_intr(adapter->pdev->irq, netdev);
7118 }
Auke Kok9a799d72007-09-15 14:07:45 -07007119 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007120}
7121#endif
7122
Eric Dumazetde1036b2010-10-20 23:00:04 +00007123static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7124 struct rtnl_link_stats64 *stats)
7125{
7126 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7127 int i;
7128
Eric Dumazet1a515022010-11-16 19:26:42 -08007129 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007130 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007131 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007132 u64 bytes, packets;
7133 unsigned int start;
7134
Eric Dumazet1a515022010-11-16 19:26:42 -08007135 if (ring) {
7136 do {
7137 start = u64_stats_fetch_begin_bh(&ring->syncp);
7138 packets = ring->stats.packets;
7139 bytes = ring->stats.bytes;
7140 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7141 stats->rx_packets += packets;
7142 stats->rx_bytes += bytes;
7143 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007144 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007145
7146 for (i = 0; i < adapter->num_tx_queues; i++) {
7147 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7148 u64 bytes, packets;
7149 unsigned int start;
7150
7151 if (ring) {
7152 do {
7153 start = u64_stats_fetch_begin_bh(&ring->syncp);
7154 packets = ring->stats.packets;
7155 bytes = ring->stats.bytes;
7156 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7157 stats->tx_packets += packets;
7158 stats->tx_bytes += bytes;
7159 }
7160 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007161 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007162 /* following stats updated by ixgbe_watchdog_task() */
7163 stats->multicast = netdev->stats.multicast;
7164 stats->rx_errors = netdev->stats.rx_errors;
7165 stats->rx_length_errors = netdev->stats.rx_length_errors;
7166 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7167 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7168 return stats;
7169}
7170
John Fastabend8b1c0b22011-05-03 02:26:48 +00007171/* ixgbe_validate_rtr - verify 802.1Qp to Rx packet buffer mapping is valid.
7172 * #adapter: pointer to ixgbe_adapter
7173 * @tc: number of traffic classes currently enabled
7174 *
7175 * Configure a valid 802.1Qp to Rx packet buffer mapping ie confirm
7176 * 802.1Q priority maps to a packet buffer that exists.
7177 */
7178static void ixgbe_validate_rtr(struct ixgbe_adapter *adapter, u8 tc)
7179{
7180 struct ixgbe_hw *hw = &adapter->hw;
7181 u32 reg, rsave;
7182 int i;
7183
7184 /* 82598 have a static priority to TC mapping that can not
7185 * be changed so no validation is needed.
7186 */
7187 if (hw->mac.type == ixgbe_mac_82598EB)
7188 return;
7189
7190 reg = IXGBE_READ_REG(hw, IXGBE_RTRUP2TC);
7191 rsave = reg;
7192
7193 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
7194 u8 up2tc = reg >> (i * IXGBE_RTRUP2TC_UP_SHIFT);
7195
7196 /* If up2tc is out of bounds default to zero */
7197 if (up2tc > tc)
7198 reg &= ~(0x7 << IXGBE_RTRUP2TC_UP_SHIFT);
7199 }
7200
7201 if (reg != rsave)
7202 IXGBE_WRITE_REG(hw, IXGBE_RTRUP2TC, reg);
7203
7204 return;
7205}
7206
7207
7208/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
7209 * classes.
7210 *
7211 * @netdev: net device to configure
7212 * @tc: number of traffic classes to enable
7213 */
7214int ixgbe_setup_tc(struct net_device *dev, u8 tc)
7215{
7216 unsigned int q, i, offset = 0;
7217 struct ixgbe_adapter *adapter = netdev_priv(dev);
7218 struct ixgbe_hw *hw = &adapter->hw;
7219 int max_q = adapter->netdev->num_tx_queues / tc;
7220
7221 /* If DCB is anabled do not remove traffic classes, multiple
7222 * traffic classes are required to implement DCB
7223 */
7224 if (!tc && (adapter->flags & IXGBE_FLAG_DCB_ENABLED))
7225 return 0;
7226
7227 /* Hardware supports up to 8 traffic classes */
7228 if (tc > MAX_TRAFFIC_CLASS ||
7229 (hw->mac.type == ixgbe_mac_82598EB && tc < MAX_TRAFFIC_CLASS))
7230 return -EINVAL;
7231
7232 /* Hardware has to reinitialize queues and interrupts to
7233 * match packet buffer alignment. Unfortunantly, the
7234 * hardware is not flexible enough to do this dynamically.
7235 */
7236 if (netif_running(dev))
7237 ixgbe_close(dev);
7238 ixgbe_clear_interrupt_scheme(adapter);
7239
7240 if (tc)
7241 netdev_set_num_tc(dev, tc);
7242 else
7243 netdev_reset_tc(dev);
7244
7245 /* Partition Tx queues evenly amongst traffic classes */
7246 for (i = 0; i < tc; i++) {
7247 q = min((int)num_online_cpus(), max_q);
7248 netdev_set_prio_tc_map(dev, i, i);
7249 netdev_set_tc_queue(dev, i, q, offset);
7250 offset += q;
7251 }
7252
7253 ixgbe_init_interrupt_scheme(adapter);
7254 ixgbe_validate_rtr(adapter, tc);
7255 if (netif_running(dev))
7256 ixgbe_open(dev);
7257
7258 return 0;
7259}
Eric Dumazetde1036b2010-10-20 23:00:04 +00007260
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007261static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007262 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007263 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007264 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007265 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007266 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007267 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7268 .ndo_validate_addr = eth_validate_addr,
7269 .ndo_set_mac_address = ixgbe_set_mac,
7270 .ndo_change_mtu = ixgbe_change_mtu,
7271 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007272 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7273 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007274 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007275 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7276 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7277 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7278 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007279 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007280 .ndo_setup_tc = ixgbe_setup_tc,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007281#ifdef CONFIG_NET_POLL_CONTROLLER
7282 .ndo_poll_controller = ixgbe_netpoll,
7283#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007284#ifdef IXGBE_FCOE
7285 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007286 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007287 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007288 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7289 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007290 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007291#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007292};
7293
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007294static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7295 const struct ixgbe_info *ii)
7296{
7297#ifdef CONFIG_PCI_IOV
7298 struct ixgbe_hw *hw = &adapter->hw;
7299 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007300 int num_vf_macvlans, i;
7301 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007302
Greg Rose3377eba792010-12-07 08:16:45 +00007303 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007304 return;
7305
7306 /* The 82599 supports up to 64 VFs per physical function
7307 * but this implementation limits allocation to 63 so that
7308 * basic networking resources are still available to the
7309 * physical function
7310 */
7311 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7312 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7313 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7314 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007315 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007316 goto err_novfs;
7317 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007318
7319 num_vf_macvlans = hw->mac.num_rar_entries -
7320 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7321
7322 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7323 sizeof(struct vf_macvlans),
7324 GFP_KERNEL);
7325 if (mv_list) {
7326 /* Initialize list of VF macvlans */
7327 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7328 for (i = 0; i < num_vf_macvlans; i++) {
7329 mv_list->vf = -1;
7330 mv_list->free = true;
7331 mv_list->rar_entry = hw->mac.num_rar_entries -
7332 (i + adapter->num_vfs + 1);
7333 list_add(&mv_list->l, &adapter->vf_mvs.l);
7334 mv_list++;
7335 }
7336 }
7337
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007338 /* If call to enable VFs succeeded then allocate memory
7339 * for per VF control structures.
7340 */
7341 adapter->vfinfo =
7342 kcalloc(adapter->num_vfs,
7343 sizeof(struct vf_data_storage), GFP_KERNEL);
7344 if (adapter->vfinfo) {
7345 /* Now that we're sure SR-IOV is enabled
7346 * and memory allocated set up the mailbox parameters
7347 */
7348 ixgbe_init_mbx_params_pf(hw);
7349 memcpy(&hw->mbx.ops, ii->mbx_ops,
7350 sizeof(hw->mbx.ops));
7351
7352 /* Disable RSC when in SR-IOV mode */
7353 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7354 IXGBE_FLAG2_RSC_ENABLED);
7355 return;
7356 }
7357
7358 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007359 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7360 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007361 pci_disable_sriov(adapter->pdev);
7362
7363err_novfs:
7364 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7365 adapter->num_vfs = 0;
7366#endif /* CONFIG_PCI_IOV */
7367}
7368
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007369/**
Auke Kok9a799d72007-09-15 14:07:45 -07007370 * ixgbe_probe - Device Initialization Routine
7371 * @pdev: PCI device information struct
7372 * @ent: entry in ixgbe_pci_tbl
7373 *
7374 * Returns 0 on success, negative on failure
7375 *
7376 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7377 * The OS initialization, configuring of the adapter private structure,
7378 * and a hardware reset occur.
7379 **/
7380static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007381 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007382{
7383 struct net_device *netdev;
7384 struct ixgbe_adapter *adapter = NULL;
7385 struct ixgbe_hw *hw;
7386 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007387 static int cards_found;
7388 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007389 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007390 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007391#ifdef IXGBE_FCOE
7392 u16 device_caps;
7393#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007394 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007395
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007396 /* Catch broken hardware that put the wrong VF device ID in
7397 * the PCIe SR-IOV capability.
7398 */
7399 if (pdev->is_virtfn) {
7400 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7401 pci_name(pdev), pdev->vendor, pdev->device);
7402 return -EINVAL;
7403 }
7404
gouji-new9ce77662009-05-06 10:44:45 +00007405 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007406 if (err)
7407 return err;
7408
Nick Nunley1b507732010-04-27 13:10:27 +00007409 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7410 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007411 pci_using_dac = 1;
7412 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007413 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007414 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007415 err = dma_set_coherent_mask(&pdev->dev,
7416 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007417 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007418 dev_err(&pdev->dev,
7419 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007420 goto err_dma;
7421 }
7422 }
7423 pci_using_dac = 0;
7424 }
7425
gouji-new9ce77662009-05-06 10:44:45 +00007426 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007427 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007428 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007429 dev_err(&pdev->dev,
7430 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007431 goto err_pci_reg;
7432 }
7433
Frans Pop19d5afd2009-10-02 10:04:12 -07007434 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007435
Auke Kok9a799d72007-09-15 14:07:45 -07007436 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007437 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007438
John Fastabendc85a2612010-02-25 23:15:21 +00007439 if (ii->mac == ixgbe_mac_82598EB)
7440 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7441 else
7442 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7443
John Fastabende5b64632011-03-08 03:44:52 +00007444#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007445 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007446#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007447 indices += min_t(unsigned int, num_possible_cpus(),
7448 IXGBE_MAX_FCOE_INDICES);
7449#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007450 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007451 if (!netdev) {
7452 err = -ENOMEM;
7453 goto err_alloc_etherdev;
7454 }
7455
Auke Kok9a799d72007-09-15 14:07:45 -07007456 SET_NETDEV_DEV(netdev, &pdev->dev);
7457
Auke Kok9a799d72007-09-15 14:07:45 -07007458 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007459 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007460
7461 adapter->netdev = netdev;
7462 adapter->pdev = pdev;
7463 hw = &adapter->hw;
7464 hw->back = adapter;
7465 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7466
Jeff Kirsher05857982008-09-11 19:57:00 -07007467 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007468 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007469 if (!hw->hw_addr) {
7470 err = -EIO;
7471 goto err_ioremap;
7472 }
7473
7474 for (i = 1; i <= 5; i++) {
7475 if (pci_resource_len(pdev, i) == 0)
7476 continue;
7477 }
7478
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007479 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007480 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007481 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007482 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007483
Auke Kok9a799d72007-09-15 14:07:45 -07007484 adapter->bd_number = cards_found;
7485
Auke Kok9a799d72007-09-15 14:07:45 -07007486 /* Setup hw api */
7487 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007488 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007489
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007490 /* EEPROM */
7491 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7492 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7493 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7494 if (!(eec & (1 << 8)))
7495 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7496
7497 /* PHY */
7498 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007499 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007500 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7501 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7502 hw->phy.mdio.mmds = 0;
7503 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7504 hw->phy.mdio.dev = netdev;
7505 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7506 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007507
Don Skidmore8ca783a2009-05-26 20:40:47 -07007508 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007509
7510 /* setup the private structure */
7511 err = ixgbe_sw_init(adapter);
7512 if (err)
7513 goto err_sw_init;
7514
Don Skidmoree86bff02010-02-11 04:14:08 +00007515 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007516 switch (adapter->hw.mac.type) {
7517 case ixgbe_mac_82599EB:
7518 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007519 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007520 break;
7521 default:
7522 break;
7523 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007524
Don Skidmorebf069c92009-05-07 10:39:54 +00007525 /*
7526 * If there is a fan on this device and it has failed log the
7527 * failure.
7528 */
7529 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7530 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7531 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007532 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007533 }
7534
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007535 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007536 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007537 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007538 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007539 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7540 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007541 err = 0;
7542 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007543 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007544 "module type was detected.\n");
7545 e_dev_err("Reload the driver after installing a supported "
7546 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007547 goto err_sw_init;
7548 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007549 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007550 goto err_sw_init;
7551 }
7552
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007553 ixgbe_probe_vf(adapter, ii);
7554
Emil Tantilov396e7992010-07-01 20:05:12 +00007555 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007556 NETIF_F_IP_CSUM |
7557 NETIF_F_HW_VLAN_TX |
7558 NETIF_F_HW_VLAN_RX |
7559 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007560
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007561 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007562 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007563 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007564 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007565 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007566
Don Skidmore58be7662011-04-12 09:42:11 +00007567 switch (adapter->hw.mac.type) {
7568 case ixgbe_mac_82599EB:
7569 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007570 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007571 break;
7572 default:
7573 break;
7574 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007575
Jeff Kirsherad31c402008-06-05 04:05:30 -07007576 netdev->vlan_features |= NETIF_F_TSO;
7577 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007578 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007579 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007580 netdev->vlan_features |= NETIF_F_SG;
7581
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007582 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7583 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7584 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007585
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007586#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007587 netdev->dcbnl_ops = &dcbnl_ops;
7588#endif
7589
Yi Zoueacd73f2009-05-13 13:11:06 +00007590#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007591 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007592 if (hw->mac.ops.get_device_caps) {
7593 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007594 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7595 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007596 }
7597 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007598 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7599 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7600 netdev->vlan_features |= NETIF_F_FSO;
7601 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7602 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007603#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007604 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007605 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007606 netdev->vlan_features |= NETIF_F_HIGHDMA;
7607 }
Auke Kok9a799d72007-09-15 14:07:45 -07007608
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007609 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007610 netdev->features |= NETIF_F_LRO;
7611
Auke Kok9a799d72007-09-15 14:07:45 -07007612 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007613 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007614 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007615 err = -EIO;
7616 goto err_eeprom;
7617 }
7618
7619 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7620 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7621
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007622 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007623 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007624 err = -EIO;
7625 goto err_eeprom;
7626 }
7627
Don Skidmorec6ecf392010-12-03 03:31:51 +00007628 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7629 if (hw->mac.ops.disable_tx_laser &&
7630 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007631 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007632 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007633 hw->mac.ops.disable_tx_laser(hw);
7634
Alexander Duyck70864002011-04-27 09:13:56 +00007635 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7636 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007637
Alexander Duyck70864002011-04-27 09:13:56 +00007638 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7639 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007640
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007641 err = ixgbe_init_interrupt_scheme(adapter);
7642 if (err)
7643 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007644
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007645 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7646 netdev->features &= ~NETIF_F_RXHASH;
7647
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007648 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007649 case IXGBE_DEV_ID_82599_SFP:
7650 /* Only this subdevice supports WOL */
7651 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7652 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7653 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7654 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007655 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7656 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007657 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7658 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7659 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7660 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007661 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007662 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007663 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007664 break;
7665 default:
7666 adapter->wol = 0;
7667 break;
7668 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007669 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7670
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007671 /* pick up the PCI bus settings for reporting later */
7672 hw->mac.ops.get_bus_info(hw);
7673
Auke Kok9a799d72007-09-15 14:07:45 -07007674 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007675 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007676 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7677 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007678 "Unknown"),
7679 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7680 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7681 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7682 "Unknown"),
7683 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007684
7685 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7686 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007687 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007688 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007689 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007690 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007691 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007692 else
Don Skidmore289700db2010-12-03 03:32:58 +00007693 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7694 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007695
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007696 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007697 e_dev_warn("PCI-Express bandwidth available for this card is "
7698 "not sufficient for optimal performance.\n");
7699 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7700 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007701 }
7702
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007703 /* save off EEPROM version number */
7704 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7705
Auke Kok9a799d72007-09-15 14:07:45 -07007706 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007707 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007708
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007709 if (err == IXGBE_ERR_EEPROM_VERSION) {
7710 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007711 e_dev_warn("This device is a pre-production adapter/LOM. "
7712 "Please be aware there may be issues associated "
7713 "with your hardware. If you are experiencing "
7714 "problems please contact your Intel or hardware "
7715 "representative who provided you with this "
7716 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007717 }
Auke Kok9a799d72007-09-15 14:07:45 -07007718 strcpy(netdev->name, "eth%d");
7719 err = register_netdev(netdev);
7720 if (err)
7721 goto err_register;
7722
Jesse Brandeburg54386462009-04-17 20:44:27 +00007723 /* carrier off reporting is important to ethtool even BEFORE open */
7724 netif_carrier_off(netdev);
7725
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007726#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007727 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007728 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007729 ixgbe_setup_dca(adapter);
7730 }
7731#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007732 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007733 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007734 for (i = 0; i < adapter->num_vfs; i++)
7735 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7736 }
7737
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007738 /* add san mac addr to netdev */
7739 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007740
Emil Tantilov849c4542010-06-03 16:53:41 +00007741 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007742 cards_found++;
7743 return 0;
7744
7745err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007746 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007747 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007748err_sw_init:
7749err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007750 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7751 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007752 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007753 iounmap(hw->hw_addr);
7754err_ioremap:
7755 free_netdev(netdev);
7756err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007757 pci_release_selected_regions(pdev,
7758 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007759err_pci_reg:
7760err_dma:
7761 pci_disable_device(pdev);
7762 return err;
7763}
7764
7765/**
7766 * ixgbe_remove - Device Removal Routine
7767 * @pdev: PCI device information struct
7768 *
7769 * ixgbe_remove is called by the PCI subsystem to alert the driver
7770 * that it should release a PCI device. The could be caused by a
7771 * Hot-Plug event, or because the driver is going to be removed from
7772 * memory.
7773 **/
7774static void __devexit ixgbe_remove(struct pci_dev *pdev)
7775{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007776 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7777 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007778
7779 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007780 cancel_work_sync(&adapter->service_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007781
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007782#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007783 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7784 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7785 dca_remove_requester(&pdev->dev);
7786 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7787 }
7788
7789#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007790#ifdef IXGBE_FCOE
7791 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7792 ixgbe_cleanup_fcoe(adapter);
7793
7794#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007795
7796 /* remove the added san mac */
7797 ixgbe_del_sanmac_netdev(netdev);
7798
Donald Skidmorec4900be2008-11-20 21:11:42 -08007799 if (netdev->reg_state == NETREG_REGISTERED)
7800 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007801
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007802 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7803 ixgbe_disable_sriov(adapter);
7804
Alexander Duyck7a921c92009-05-06 10:43:28 +00007805 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007806
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007807 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007808
7809 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007810 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007811 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007812
Emil Tantilov849c4542010-06-03 16:53:41 +00007813 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007814
Auke Kok9a799d72007-09-15 14:07:45 -07007815 free_netdev(netdev);
7816
Frans Pop19d5afd2009-10-02 10:04:12 -07007817 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007818
Auke Kok9a799d72007-09-15 14:07:45 -07007819 pci_disable_device(pdev);
7820}
7821
7822/**
7823 * ixgbe_io_error_detected - called when PCI error is detected
7824 * @pdev: Pointer to PCI device
7825 * @state: The current pci connection state
7826 *
7827 * This function is called after a PCI bus error affecting
7828 * this device has been detected.
7829 */
7830static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007831 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007832{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007833 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7834 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007835
7836 netif_device_detach(netdev);
7837
Breno Leitao3044b8d2009-05-06 10:44:26 +00007838 if (state == pci_channel_io_perm_failure)
7839 return PCI_ERS_RESULT_DISCONNECT;
7840
Auke Kok9a799d72007-09-15 14:07:45 -07007841 if (netif_running(netdev))
7842 ixgbe_down(adapter);
7843 pci_disable_device(pdev);
7844
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007845 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007846 return PCI_ERS_RESULT_NEED_RESET;
7847}
7848
7849/**
7850 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7851 * @pdev: Pointer to PCI device
7852 *
7853 * Restart the card from scratch, as if from a cold-boot.
7854 */
7855static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7856{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007857 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007858 pci_ers_result_t result;
7859 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007860
gouji-new9ce77662009-05-06 10:44:45 +00007861 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007862 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007863 result = PCI_ERS_RESULT_DISCONNECT;
7864 } else {
7865 pci_set_master(pdev);
7866 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007867 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007868
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007869 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007870
7871 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007872 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007873 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007874 }
Auke Kok9a799d72007-09-15 14:07:45 -07007875
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007876 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7877 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007878 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7879 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007880 /* non-fatal, continue */
7881 }
Auke Kok9a799d72007-09-15 14:07:45 -07007882
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007883 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007884}
7885
7886/**
7887 * ixgbe_io_resume - called when traffic can start flowing again.
7888 * @pdev: Pointer to PCI device
7889 *
7890 * This callback is called when the error recovery driver tells us that
7891 * its OK to resume normal operation.
7892 */
7893static void ixgbe_io_resume(struct pci_dev *pdev)
7894{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007895 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7896 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007897
7898 if (netif_running(netdev)) {
7899 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007900 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007901 return;
7902 }
7903 }
7904
7905 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007906}
7907
7908static struct pci_error_handlers ixgbe_err_handler = {
7909 .error_detected = ixgbe_io_error_detected,
7910 .slot_reset = ixgbe_io_slot_reset,
7911 .resume = ixgbe_io_resume,
7912};
7913
7914static struct pci_driver ixgbe_driver = {
7915 .name = ixgbe_driver_name,
7916 .id_table = ixgbe_pci_tbl,
7917 .probe = ixgbe_probe,
7918 .remove = __devexit_p(ixgbe_remove),
7919#ifdef CONFIG_PM
7920 .suspend = ixgbe_suspend,
7921 .resume = ixgbe_resume,
7922#endif
7923 .shutdown = ixgbe_shutdown,
7924 .err_handler = &ixgbe_err_handler
7925};
7926
7927/**
7928 * ixgbe_init_module - Driver Registration Routine
7929 *
7930 * ixgbe_init_module is the first routine called when the driver is
7931 * loaded. All it does is register with the PCI subsystem.
7932 **/
7933static int __init ixgbe_init_module(void)
7934{
7935 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007936 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007937 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007938
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007939#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007940 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007941#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007942
Auke Kok9a799d72007-09-15 14:07:45 -07007943 ret = pci_register_driver(&ixgbe_driver);
7944 return ret;
7945}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007946
Auke Kok9a799d72007-09-15 14:07:45 -07007947module_init(ixgbe_init_module);
7948
7949/**
7950 * ixgbe_exit_module - Driver Exit Cleanup Routine
7951 *
7952 * ixgbe_exit_module is called just before the driver is removed
7953 * from memory.
7954 **/
7955static void __exit ixgbe_exit_module(void)
7956{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007957#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007958 dca_unregister_notify(&dca_notifier);
7959#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007960 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007961 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007962}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007963
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007964#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007965static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007966 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007967{
7968 int ret_val;
7969
7970 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007971 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007972
7973 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7974}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007975
Alexander Duyckb4533682009-03-31 21:32:42 +00007976#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007977
Auke Kok9a799d72007-09-15 14:07:45 -07007978module_exit(ixgbe_exit_module);
7979
7980/* ixgbe_main.c */