blob: 4be2af22d69b7b1dc866cba462e2001557515361 [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>
35#include <linux/ip.h>
36#include <linux/tcp.h>
Lucy Liu60127862009-07-22 14:07:33 +000037#include <linux/pkt_sched.h>
Auke Kok9a799d72007-09-15 14:07:45 -070038#include <linux/ipv6.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090039#include <linux/slab.h>
Auke Kok9a799d72007-09-15 14:07:45 -070040#include <net/checksum.h>
41#include <net/ip6_checksum.h>
42#include <linux/ethtool.h>
43#include <linux/if_vlan.h>
Yi Zoueacd73f2009-05-13 13:11:06 +000044#include <scsi/fc/fc_fcoe.h>
Auke Kok9a799d72007-09-15 14:07:45 -070045
46#include "ixgbe.h"
47#include "ixgbe_common.h"
Don Skidmoreee5f7842009-11-06 12:56:20 +000048#include "ixgbe_dcb_82599.h"
Greg Rose1cdd1ec2010-01-09 02:26:46 +000049#include "ixgbe_sriov.h"
Auke Kok9a799d72007-09-15 14:07:45 -070050
51char ixgbe_driver_name[] = "ixgbe";
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070052static const char ixgbe_driver_string[] =
Joe Perchese8e9f692010-09-07 21:34:53 +000053 "Intel(R) 10 Gigabit PCI Express Network Driver";
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000054#define MAJ 3
Don Skidmorec89c7112011-04-14 07:40:11 +000055#define MIN 3
56#define BUILD 8
Jeff Kirsher75e3d3c2011-03-17 18:11:38 +000057#define KFIX 2
58#define DRV_VERSION __stringify(MAJ) "." __stringify(MIN) "." \
59 __stringify(BUILD) "-k" __stringify(KFIX)
Stephen Hemminger9c8eb722007-10-29 10:46:24 -070060const char ixgbe_driver_version[] = DRV_VERSION;
Don Skidmorea52055e2011-02-23 09:58:39 +000061static const char ixgbe_copyright[] =
62 "Copyright (c) 1999-2011 Intel Corporation.";
Auke Kok9a799d72007-09-15 14:07:45 -070063
64static const struct ixgbe_info *ixgbe_info_tbl[] = {
Peter P Waskiewiczb4617242008-09-11 20:04:46 -070065 [board_82598] = &ixgbe_82598_info,
PJ Waskiewicze8e26352009-02-27 15:45:05 +000066 [board_82599] = &ixgbe_82599_info,
Don Skidmorefe15e8e12010-11-16 19:27:16 -080067 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070068};
69
70/* ixgbe_pci_tbl - PCI Device ID Table
71 *
72 * Wildcard entries (PCI_ANY_ID) should come last
73 * Last entry must be all 0s
74 *
75 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
76 * Class, Class Mask, private data (not used) }
77 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000078static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
80 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070082 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
86 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
88 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070090 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
92 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
94 board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
96 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070097 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
98 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
100 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
102 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
104 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
106 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
108 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
110 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
112 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
114 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
116 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
118 board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
120 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
122 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
124 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000126 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
128 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700129
130 /* required last entry */
131 {0, }
132};
133MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
134
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400135#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800136static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000137 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800138static struct notifier_block dca_notifier = {
139 .notifier_call = ixgbe_notify_dca,
140 .next = NULL,
141 .priority = 0
142};
143#endif
144
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000145#ifdef CONFIG_PCI_IOV
146static unsigned int max_vfs;
147module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000148MODULE_PARM_DESC(max_vfs,
149 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000150#endif /* CONFIG_PCI_IOV */
151
Auke Kok9a799d72007-09-15 14:07:45 -0700152MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
153MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
154MODULE_LICENSE("GPL");
155MODULE_VERSION(DRV_VERSION);
156
157#define DEFAULT_DEBUG_LEVEL_SHIFT 3
158
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000159static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
160{
161 struct ixgbe_hw *hw = &adapter->hw;
162 u32 gcr;
163 u32 gpie;
164 u32 vmdctl;
165
166#ifdef CONFIG_PCI_IOV
167 /* disable iov and allow time for transactions to clear */
168 pci_disable_sriov(adapter->pdev);
169#endif
170
171 /* turn off device IOV mode */
172 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
173 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
174 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
175 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
176 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
177 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
178
179 /* set default pool back to 0 */
180 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
181 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
182 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
183
184 /* take a breather then clean up driver data */
185 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000186
187 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000188 adapter->vfinfo = NULL;
189
190 adapter->num_vfs = 0;
191 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
192}
193
Alexander Duyck70864002011-04-27 09:13:56 +0000194static void ixgbe_service_event_schedule(struct ixgbe_adapter *adapter)
195{
196 if (!test_bit(__IXGBE_DOWN, &adapter->state) &&
197 !test_and_set_bit(__IXGBE_SERVICE_SCHED, &adapter->state))
198 schedule_work(&adapter->service_task);
199}
200
201static void ixgbe_service_event_complete(struct ixgbe_adapter *adapter)
202{
203 BUG_ON(!test_bit(__IXGBE_SERVICE_SCHED, &adapter->state));
204
205 /* flush memory to make sure state is correct before next watchog */
206 smp_mb__before_clear_bit();
207 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
208}
209
Taku Izumidcd79ae2010-04-27 14:39:53 +0000210struct ixgbe_reg_info {
211 u32 ofs;
212 char *name;
213};
214
215static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
216
217 /* General Registers */
218 {IXGBE_CTRL, "CTRL"},
219 {IXGBE_STATUS, "STATUS"},
220 {IXGBE_CTRL_EXT, "CTRL_EXT"},
221
222 /* Interrupt Registers */
223 {IXGBE_EICR, "EICR"},
224
225 /* RX Registers */
226 {IXGBE_SRRCTL(0), "SRRCTL"},
227 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
228 {IXGBE_RDLEN(0), "RDLEN"},
229 {IXGBE_RDH(0), "RDH"},
230 {IXGBE_RDT(0), "RDT"},
231 {IXGBE_RXDCTL(0), "RXDCTL"},
232 {IXGBE_RDBAL(0), "RDBAL"},
233 {IXGBE_RDBAH(0), "RDBAH"},
234
235 /* TX Registers */
236 {IXGBE_TDBAL(0), "TDBAL"},
237 {IXGBE_TDBAH(0), "TDBAH"},
238 {IXGBE_TDLEN(0), "TDLEN"},
239 {IXGBE_TDH(0), "TDH"},
240 {IXGBE_TDT(0), "TDT"},
241 {IXGBE_TXDCTL(0), "TXDCTL"},
242
243 /* List Terminator */
244 {}
245};
246
247
248/*
249 * ixgbe_regdump - register printout routine
250 */
251static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
252{
253 int i = 0, j = 0;
254 char rname[16];
255 u32 regs[64];
256
257 switch (reginfo->ofs) {
258 case IXGBE_SRRCTL(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
261 break;
262 case IXGBE_DCA_RXCTRL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
265 break;
266 case IXGBE_RDLEN(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
269 break;
270 case IXGBE_RDH(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
273 break;
274 case IXGBE_RDT(0):
275 for (i = 0; i < 64; i++)
276 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
277 break;
278 case IXGBE_RXDCTL(0):
279 for (i = 0; i < 64; i++)
280 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
281 break;
282 case IXGBE_RDBAL(0):
283 for (i = 0; i < 64; i++)
284 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
285 break;
286 case IXGBE_RDBAH(0):
287 for (i = 0; i < 64; i++)
288 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
289 break;
290 case IXGBE_TDBAL(0):
291 for (i = 0; i < 64; i++)
292 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
293 break;
294 case IXGBE_TDBAH(0):
295 for (i = 0; i < 64; i++)
296 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
297 break;
298 case IXGBE_TDLEN(0):
299 for (i = 0; i < 64; i++)
300 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
301 break;
302 case IXGBE_TDH(0):
303 for (i = 0; i < 64; i++)
304 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
305 break;
306 case IXGBE_TDT(0):
307 for (i = 0; i < 64; i++)
308 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
309 break;
310 case IXGBE_TXDCTL(0):
311 for (i = 0; i < 64; i++)
312 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
313 break;
314 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000315 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000316 IXGBE_READ_REG(hw, reginfo->ofs));
317 return;
318 }
319
320 for (i = 0; i < 8; i++) {
321 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000322 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000323 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000324 pr_cont(" %08x", regs[i*8+j]);
325 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000326 }
327
328}
329
330/*
331 * ixgbe_dump - Print registers, tx-rings and rx-rings
332 */
333static void ixgbe_dump(struct ixgbe_adapter *adapter)
334{
335 struct net_device *netdev = adapter->netdev;
336 struct ixgbe_hw *hw = &adapter->hw;
337 struct ixgbe_reg_info *reginfo;
338 int n = 0;
339 struct ixgbe_ring *tx_ring;
340 struct ixgbe_tx_buffer *tx_buffer_info;
341 union ixgbe_adv_tx_desc *tx_desc;
342 struct my_u0 { u64 a; u64 b; } *u0;
343 struct ixgbe_ring *rx_ring;
344 union ixgbe_adv_rx_desc *rx_desc;
345 struct ixgbe_rx_buffer *rx_buffer_info;
346 u32 staterr;
347 int i = 0;
348
349 if (!netif_msg_hw(adapter))
350 return;
351
352 /* Print netdevice Info */
353 if (netdev) {
354 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000355 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000356 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000357 pr_info("%-15s %016lX %016lX %016lX\n",
358 netdev->name,
359 netdev->state,
360 netdev->trans_start,
361 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 }
363
364 /* Print Registers */
365 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000366 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000367 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
368 reginfo->name; reginfo++) {
369 ixgbe_regdump(hw, reginfo);
370 }
371
372 /* Print TX Ring Summary */
373 if (!netdev || !netif_running(netdev))
374 goto exit;
375
376 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000377 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000378 for (n = 0; n < adapter->num_tx_queues; n++) {
379 tx_ring = adapter->tx_ring[n];
380 tx_buffer_info =
381 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000382 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000383 n, tx_ring->next_to_use, tx_ring->next_to_clean,
384 (u64)tx_buffer_info->dma,
385 tx_buffer_info->length,
386 tx_buffer_info->next_to_watch,
387 (u64)tx_buffer_info->time_stamp);
388 }
389
390 /* Print TX Rings */
391 if (!netif_msg_tx_done(adapter))
392 goto rx_ring_summary;
393
394 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
395
396 /* Transmit Descriptor Formats
397 *
398 * Advanced Transmit Descriptor
399 * +--------------------------------------------------------------+
400 * 0 | Buffer Address [63:0] |
401 * +--------------------------------------------------------------+
402 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
403 * +--------------------------------------------------------------+
404 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
405 */
406
407 for (n = 0; n < adapter->num_tx_queues; n++) {
408 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000409 pr_info("------------------------------------\n");
410 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
411 pr_info("------------------------------------\n");
412 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000413 "[PlPOIdStDDt Ln] [bi->dma ] "
414 "leng ntw timestamp bi->skb\n");
415
416 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000417 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000418 tx_buffer_info = &tx_ring->tx_buffer_info[i];
419 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000420 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000421 " %04X %3X %016llX %p", i,
422 le64_to_cpu(u0->a),
423 le64_to_cpu(u0->b),
424 (u64)tx_buffer_info->dma,
425 tx_buffer_info->length,
426 tx_buffer_info->next_to_watch,
427 (u64)tx_buffer_info->time_stamp,
428 tx_buffer_info->skb);
429 if (i == tx_ring->next_to_use &&
430 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000431 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000432 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000433 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000434 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000435 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 else
Joe Perchesc7689572010-09-07 21:35:17 +0000437 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000438
439 if (netif_msg_pktdata(adapter) &&
440 tx_buffer_info->dma != 0)
441 print_hex_dump(KERN_INFO, "",
442 DUMP_PREFIX_ADDRESS, 16, 1,
443 phys_to_virt(tx_buffer_info->dma),
444 tx_buffer_info->length, true);
445 }
446 }
447
448 /* Print RX Rings Summary */
449rx_ring_summary:
450 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000451 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000452 for (n = 0; n < adapter->num_rx_queues; n++) {
453 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000454 pr_info("%5d %5X %5X\n",
455 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000456 }
457
458 /* Print RX Rings */
459 if (!netif_msg_rx_status(adapter))
460 goto exit;
461
462 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
463
464 /* Advanced Receive Descriptor (Read) Format
465 * 63 1 0
466 * +-----------------------------------------------------+
467 * 0 | Packet Buffer Address [63:1] |A0/NSE|
468 * +----------------------------------------------+------+
469 * 8 | Header Buffer Address [63:1] | DD |
470 * +-----------------------------------------------------+
471 *
472 *
473 * Advanced Receive Descriptor (Write-Back) Format
474 *
475 * 63 48 47 32 31 30 21 20 16 15 4 3 0
476 * +------------------------------------------------------+
477 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
478 * | Checksum Ident | | | | Type | Type |
479 * +------------------------------------------------------+
480 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
481 * +------------------------------------------------------+
482 * 63 48 47 32 31 20 19 0
483 */
484 for (n = 0; n < adapter->num_rx_queues; n++) {
485 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000486 pr_info("------------------------------------\n");
487 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
488 pr_info("------------------------------------\n");
489 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000490 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
491 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000492 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000493 "[vl er S cks ln] ---------------- [bi->skb] "
494 "<-- Adv Rx Write-Back format\n");
495
496 for (i = 0; i < rx_ring->count; i++) {
497 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000498 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000499 u0 = (struct my_u0 *)rx_desc;
500 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
501 if (staterr & IXGBE_RXD_STAT_DD) {
502 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000503 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000504 "%016llX ---------------- %p", i,
505 le64_to_cpu(u0->a),
506 le64_to_cpu(u0->b),
507 rx_buffer_info->skb);
508 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000509 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000510 "%016llX %016llX %p", i,
511 le64_to_cpu(u0->a),
512 le64_to_cpu(u0->b),
513 (u64)rx_buffer_info->dma,
514 rx_buffer_info->skb);
515
516 if (netif_msg_pktdata(adapter)) {
517 print_hex_dump(KERN_INFO, "",
518 DUMP_PREFIX_ADDRESS, 16, 1,
519 phys_to_virt(rx_buffer_info->dma),
520 rx_ring->rx_buf_len, true);
521
522 if (rx_ring->rx_buf_len
523 < IXGBE_RXBUFFER_2048)
524 print_hex_dump(KERN_INFO, "",
525 DUMP_PREFIX_ADDRESS, 16, 1,
526 phys_to_virt(
527 rx_buffer_info->page_dma +
528 rx_buffer_info->page_offset
529 ),
530 PAGE_SIZE/2, true);
531 }
532 }
533
534 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000535 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000536 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000537 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000538 else
Joe Perchesc7689572010-09-07 21:35:17 +0000539 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000540
541 }
542 }
543
544exit:
545 return;
546}
547
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800548static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
549{
550 u32 ctrl_ext;
551
552 /* Let firmware take over control of h/w */
553 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
554 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000555 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800556}
557
558static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
559{
560 u32 ctrl_ext;
561
562 /* Let firmware know the driver has taken over */
563 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
564 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000565 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800566}
Auke Kok9a799d72007-09-15 14:07:45 -0700567
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000568/*
569 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
570 * @adapter: pointer to adapter struct
571 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
572 * @queue: queue to map the corresponding interrupt to
573 * @msix_vector: the vector to map to the corresponding queue
574 *
575 */
576static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000577 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700578{
579 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000580 struct ixgbe_hw *hw = &adapter->hw;
581 switch (hw->mac.type) {
582 case ixgbe_mac_82598EB:
583 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
584 if (direction == -1)
585 direction = 0;
586 index = (((direction * 64) + queue) >> 2) & 0x1F;
587 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
588 ivar &= ~(0xFF << (8 * (queue & 0x3)));
589 ivar |= (msix_vector << (8 * (queue & 0x3)));
590 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
591 break;
592 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800593 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000594 if (direction == -1) {
595 /* other causes */
596 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
597 index = ((queue & 1) * 8);
598 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
599 ivar &= ~(0xFF << index);
600 ivar |= (msix_vector << index);
601 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
602 break;
603 } else {
604 /* tx or rx causes */
605 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
606 index = ((16 * (queue & 1)) + (8 * direction));
607 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
608 ivar &= ~(0xFF << index);
609 ivar |= (msix_vector << index);
610 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
611 break;
612 }
613 default:
614 break;
615 }
Auke Kok9a799d72007-09-15 14:07:45 -0700616}
617
Alexander Duyckfe49f042009-06-04 16:00:09 +0000618static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000619 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000620{
621 u32 mask;
622
Alexander Duyckbd508172010-11-16 19:27:03 -0800623 switch (adapter->hw.mac.type) {
624 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000625 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
626 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800627 break;
628 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800629 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000630 mask = (qmask & 0xFFFFFFFF);
631 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
632 mask = (qmask >> 32);
633 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800634 break;
635 default:
636 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000637 }
638}
639
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800640void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
641 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700642{
Alexander Duycke5a43542009-12-02 16:46:56 +0000643 if (tx_buffer_info->dma) {
644 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800645 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000646 tx_buffer_info->dma,
647 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000648 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000649 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800650 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000651 tx_buffer_info->dma,
652 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000653 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000654 tx_buffer_info->dma = 0;
655 }
Auke Kok9a799d72007-09-15 14:07:45 -0700656 if (tx_buffer_info->skb) {
657 dev_kfree_skb_any(tx_buffer_info->skb);
658 tx_buffer_info->skb = NULL;
659 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000660 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700661 /* tx_buffer_info must be completely set up in the transmit path */
662}
663
Yi Zou26f23d82009-11-06 12:56:00 +0000664/**
John Fastabendc84d3242010-11-16 19:27:12 -0800665 * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class
666 * @adapter: driver private struct
667 * @index: reg idx of queue to query (0-127)
Yi Zou26f23d82009-11-06 12:56:00 +0000668 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300669 * Helper function to determine the traffic index for a particular
John Fastabendc84d3242010-11-16 19:27:12 -0800670 * register index.
Yi Zou26f23d82009-11-06 12:56:00 +0000671 *
John Fastabendc84d3242010-11-16 19:27:12 -0800672 * Returns : a tc index for use in range 0-7, or 0-3
Yi Zou26f23d82009-11-06 12:56:00 +0000673 */
Don Skidmore3b2ee942011-01-28 02:28:26 +0000674static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx)
Yi Zou26f23d82009-11-06 12:56:00 +0000675{
John Fastabendc84d3242010-11-16 19:27:12 -0800676 int tc = -1;
John Fastabende5b64632011-03-08 03:44:52 +0000677 int dcb_i = netdev_get_num_tc(adapter->netdev);
Yi Zou26f23d82009-11-06 12:56:00 +0000678
John Fastabendc84d3242010-11-16 19:27:12 -0800679 /* if DCB is not enabled the queues have no TC */
680 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
681 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000682
John Fastabendc84d3242010-11-16 19:27:12 -0800683 /* check valid range */
684 if (reg_idx >= adapter->hw.mac.max_tx_queues)
685 return tc;
686
687 switch (adapter->hw.mac.type) {
688 case ixgbe_mac_82598EB:
689 tc = reg_idx >> 2;
690 break;
691 default:
692 if (dcb_i != 4 && dcb_i != 8)
PJ Waskiewicz6837e892010-01-06 17:50:29 +0000693 break;
John Fastabendc84d3242010-11-16 19:27:12 -0800694
695 /* if VMDq is enabled the lowest order bits determine TC */
696 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
697 IXGBE_FLAG_VMDQ_ENABLED)) {
698 tc = reg_idx & (dcb_i - 1);
Alexander Duyckbd508172010-11-16 19:27:03 -0800699 break;
Yi Zou26f23d82009-11-06 12:56:00 +0000700 }
John Fastabendc84d3242010-11-16 19:27:12 -0800701
702 /*
703 * Convert the reg_idx into the correct TC. This bitmask
704 * targets the last full 32 ring traffic class and assigns
705 * it a value of 1. From there the rest of the rings are
706 * based on shifting the mask further up to include the
707 * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i
708 * will only ever be 8 or 4 and that reg_idx will never
709 * be greater then 128. The code without the power of 2
710 * optimizations would be:
711 * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32)
712 */
713 tc = ((reg_idx & 0X1F) + 0x20) * dcb_i;
714 tc >>= 9 - (reg_idx >> 5);
Yi Zou26f23d82009-11-06 12:56:00 +0000715 }
John Fastabendc84d3242010-11-16 19:27:12 -0800716
717 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000718}
719
John Fastabendc84d3242010-11-16 19:27:12 -0800720static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700721{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700722 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800723 struct ixgbe_hw_stats *hwstats = &adapter->stats;
724 u32 data = 0;
725 u32 xoff[8] = {0};
726 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700727
John Fastabendc84d3242010-11-16 19:27:12 -0800728 if ((hw->fc.current_mode == ixgbe_fc_full) ||
729 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
730 switch (hw->mac.type) {
731 case ixgbe_mac_82598EB:
732 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
733 break;
734 default:
735 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
736 }
737 hwstats->lxoffrxc += data;
738
739 /* refill credits (no tx hang) if we received xoff */
740 if (!data)
741 return;
742
743 for (i = 0; i < adapter->num_tx_queues; i++)
744 clear_bit(__IXGBE_HANG_CHECK_ARMED,
745 &adapter->tx_ring[i]->state);
746 return;
747 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
748 return;
749
750 /* update stats for each tc, only valid with PFC enabled */
751 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
752 switch (hw->mac.type) {
753 case ixgbe_mac_82598EB:
754 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
755 break;
756 default:
757 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
758 }
759 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700760 }
761
John Fastabendc84d3242010-11-16 19:27:12 -0800762 /* disarm tx queues that have received xoff frames */
763 for (i = 0; i < adapter->num_tx_queues; i++) {
764 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
765 u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx);
766
767 if (xoff[tc])
768 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
769 }
770}
771
772static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
773{
774 return ring->tx_stats.completed;
775}
776
777static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
778{
779 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
780 struct ixgbe_hw *hw = &adapter->hw;
781
782 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
783 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
784
785 if (head != tail)
786 return (head < tail) ?
787 tail - head : (tail + ring->count - head);
788
789 return 0;
790}
791
792static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
793{
794 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
795 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
796 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
797 bool ret = false;
798
799 clear_check_for_tx_hang(tx_ring);
800
801 /*
802 * Check for a hung queue, but be thorough. This verifies
803 * that a transmit has been completed since the previous
804 * check AND there is at least one packet pending. The
805 * ARMED bit is set to indicate a potential hang. The
806 * bit is cleared if a pause frame is received to remove
807 * false hang detection due to PFC or 802.3x frames. By
808 * requiring this to fail twice we avoid races with
809 * pfc clearing the ARMED bit and conditions where we
810 * run the check_tx_hang logic with a transmit completion
811 * pending but without time to complete it yet.
812 */
813 if ((tx_done_old == tx_done) && tx_pending) {
814 /* make sure it is true for two checks in a row */
815 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
816 &tx_ring->state);
817 } else {
818 /* update completed stats and continue */
819 tx_ring->tx_stats.tx_done_old = tx_done;
820 /* reset the countdown */
821 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
822 }
823
824 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700825}
826
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700827#define IXGBE_MAX_TXD_PWR 14
828#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800829
830/* Tx Descriptors needed, worst case */
831#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
832 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
833#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700834 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800835
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000836/**
837 * ixgbe_tx_timeout_reset - initiate reset due to Tx timeout
838 * @adapter: driver private struct
839 **/
840static void ixgbe_tx_timeout_reset(struct ixgbe_adapter *adapter)
841{
842
843 /* Do the reset outside of interrupt context */
844 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
845 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
846 ixgbe_service_event_schedule(adapter);
847 }
848}
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700849
Auke Kok9a799d72007-09-15 14:07:45 -0700850/**
851 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000852 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700853 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700854 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000855static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000856 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700857{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000858 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800859 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
860 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700861 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800862 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700863
864 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800865 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000866 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800867
868 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000869 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800870 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000871 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800872 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000873 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700874 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700875
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800876 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800877 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800878
Auke Kok9a799d72007-09-15 14:07:45 -0700879 i++;
880 if (i == tx_ring->count)
881 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800882
883 if (cleaned && tx_buffer_info->skb) {
884 total_bytes += tx_buffer_info->bytecount;
885 total_packets += tx_buffer_info->gso_segs;
886 }
887
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800888 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800889 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700890 }
891
John Fastabendc84d3242010-11-16 19:27:12 -0800892 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800893 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000894 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800895 }
896
Auke Kok9a799d72007-09-15 14:07:45 -0700897 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800898 tx_ring->total_bytes += total_bytes;
899 tx_ring->total_packets += total_packets;
900 u64_stats_update_begin(&tx_ring->syncp);
901 tx_ring->stats.packets += total_packets;
902 tx_ring->stats.bytes += total_bytes;
903 u64_stats_update_end(&tx_ring->syncp);
904
John Fastabendc84d3242010-11-16 19:27:12 -0800905 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800906 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800907 struct ixgbe_hw *hw = &adapter->hw;
908 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
909 e_err(drv, "Detected Tx Unit Hang\n"
910 " Tx Queue <%d>\n"
911 " TDH, TDT <%x>, <%x>\n"
912 " next_to_use <%x>\n"
913 " next_to_clean <%x>\n"
914 "tx_buffer_info[next_to_clean]\n"
915 " time_stamp <%lx>\n"
916 " jiffies <%lx>\n",
917 tx_ring->queue_index,
918 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
919 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
920 tx_ring->next_to_use, eop,
921 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
922
923 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
924
925 e_info(probe,
926 "tx hang %d detected on queue %d, resetting adapter\n",
927 adapter->tx_timeout_count + 1, tx_ring->queue_index);
928
929 /* schedule immediate reset if we believe we hung */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +0000930 ixgbe_tx_timeout_reset(adapter);
Alexander Duyckb9537992010-11-16 19:26:58 -0800931
932 /* the adapter is about to reset, no point in enabling stuff */
933 return true;
934 }
Auke Kok9a799d72007-09-15 14:07:45 -0700935
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800936#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800937 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Joe Perchese8e9f692010-09-07 21:34:53 +0000938 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800939 /* Make sure that anybody stopping the queue after this
940 * sees the new next_to_clean.
941 */
942 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800943 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800944 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800945 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800946 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800947 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800948 }
Auke Kok9a799d72007-09-15 14:07:45 -0700949
Eric Dumazet807540b2010-09-23 05:40:09 +0000950 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700951}
952
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400953#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800954static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800955 struct ixgbe_ring *rx_ring,
956 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800957{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800959 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800960 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800961
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800962 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
963 switch (hw->mac.type) {
964 case ixgbe_mac_82598EB:
965 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
966 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
967 break;
968 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800969 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800970 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
971 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
972 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
973 break;
974 default:
975 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800976 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800977 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
978 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
979 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800980 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800981}
982
983static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800984 struct ixgbe_ring *tx_ring,
985 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800986{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000987 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800988 u32 txctrl;
989 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800990
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800991 switch (hw->mac.type) {
992 case ixgbe_mac_82598EB:
993 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
994 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
995 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
996 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800997 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
998 break;
999 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001000 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001001 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
1002 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
1003 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
1004 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
1005 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001006 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
1007 break;
1008 default:
1009 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001010 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001011}
1012
1013static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1014{
1015 struct ixgbe_adapter *adapter = q_vector->adapter;
1016 int cpu = get_cpu();
1017 long r_idx;
1018 int i;
1019
1020 if (q_vector->cpu == cpu)
1021 goto out_no_update;
1022
1023 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1024 for (i = 0; i < q_vector->txr_count; i++) {
1025 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
1026 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1027 r_idx + 1);
1028 }
1029
1030 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1031 for (i = 0; i < q_vector->rxr_count; i++) {
1032 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1033 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1034 r_idx + 1);
1035 }
1036
1037 q_vector->cpu = cpu;
1038out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001039 put_cpu();
1040}
1041
1042static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1043{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001044 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001045 int i;
1046
1047 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1048 return;
1049
Alexander Duycke35ec122009-05-21 13:07:12 +00001050 /* always use CB2 mode, difference is masked in the CB driver */
1051 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1052
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001053 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1054 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1055 else
1056 num_q_vectors = 1;
1057
1058 for (i = 0; i < num_q_vectors; i++) {
1059 adapter->q_vector[i]->cpu = -1;
1060 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001061 }
1062}
1063
1064static int __ixgbe_notify_dca(struct device *dev, void *data)
1065{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001066 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001067 unsigned long event = *(unsigned long *)data;
1068
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001069 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1070 return 0;
1071
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001072 switch (event) {
1073 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001074 /* if we're already enabled, don't do it again */
1075 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1076 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001077 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001078 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001079 ixgbe_setup_dca(adapter);
1080 break;
1081 }
1082 /* Fall Through since DCA is disabled. */
1083 case DCA_PROVIDER_REMOVE:
1084 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1085 dca_remove_requester(dev);
1086 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1087 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1088 }
1089 break;
1090 }
1091
Denis V. Lunev652f0932008-03-27 14:39:17 +03001092 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001093}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001094#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001095
1096static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1097 struct sk_buff *skb)
1098{
1099 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1100}
1101
Auke Kok9a799d72007-09-15 14:07:45 -07001102/**
1103 * ixgbe_receive_skb - Send a completed packet up the stack
1104 * @adapter: board private structure
1105 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001106 * @status: hardware indication of status of receive
1107 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1108 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001109 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001110static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001111 struct sk_buff *skb, u8 status,
1112 struct ixgbe_ring *ring,
1113 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001114{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001115 struct ixgbe_adapter *adapter = q_vector->adapter;
1116 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001117 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1118 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001119
Jesse Grossf62bbb52010-10-20 13:56:10 +00001120 if (is_vlan && (tag & VLAN_VID_MASK))
1121 __vlan_hwaccel_put_tag(skb, tag);
1122
1123 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1124 napi_gro_receive(napi, skb);
1125 else
1126 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001127}
1128
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001129/**
1130 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1131 * @adapter: address of board private structure
1132 * @status_err: hardware indication of status of receive
1133 * @skb: skb currently being received and modified
1134 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001135static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001136 union ixgbe_adv_rx_desc *rx_desc,
1137 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001138{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001139 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1140
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001141 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001142
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001143 /* Rx csum disabled */
1144 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001145 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001146
1147 /* if IP and error */
1148 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1149 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001150 adapter->hw_csum_rx_error++;
1151 return;
1152 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001153
1154 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1155 return;
1156
1157 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001158 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1159
1160 /*
1161 * 82599 errata, UDP frames with a 0 checksum can be marked as
1162 * checksum errors.
1163 */
1164 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1165 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1166 return;
1167
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001168 adapter->hw_csum_rx_error++;
1169 return;
1170 }
1171
Auke Kok9a799d72007-09-15 14:07:45 -07001172 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001173 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001174}
1175
Alexander Duyck84ea2592010-11-16 19:26:49 -08001176static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001177{
1178 /*
1179 * Force memory writes to complete before letting h/w
1180 * know there are new descriptors to fetch. (Only
1181 * applicable for weak-ordered memory model archs,
1182 * such as IA-64).
1183 */
1184 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001185 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001186}
1187
Auke Kok9a799d72007-09-15 14:07:45 -07001188/**
1189 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001190 * @rx_ring: ring to place buffers on
1191 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001192 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001193void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001194{
Auke Kok9a799d72007-09-15 14:07:45 -07001195 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001196 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001197 struct sk_buff *skb;
1198 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001199
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001200 /* do nothing if no valid netdev defined */
1201 if (!rx_ring->netdev)
1202 return;
1203
Auke Kok9a799d72007-09-15 14:07:45 -07001204 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001205 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001206 bi = &rx_ring->rx_buffer_info[i];
1207 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001208
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001209 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001210 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001211 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001212 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001213 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001214 goto no_buffers;
1215 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001216 /* initialize queue mapping */
1217 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001218 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001219 }
Auke Kok9a799d72007-09-15 14:07:45 -07001220
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001221 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001222 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001223 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001224 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001225 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001226 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001227 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001228 bi->dma = 0;
1229 goto no_buffers;
1230 }
Auke Kok9a799d72007-09-15 14:07:45 -07001231 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001232
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001233 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001234 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001235 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001236 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001237 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001238 goto no_buffers;
1239 }
1240 }
1241
1242 if (!bi->page_dma) {
1243 /* use a half page if we're re-using */
1244 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001245 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001246 bi->page,
1247 bi->page_offset,
1248 PAGE_SIZE / 2,
1249 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001250 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001251 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001252 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001253 bi->page_dma = 0;
1254 goto no_buffers;
1255 }
1256 }
1257
1258 /* Refresh the desc even if buffer_addrs didn't change
1259 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001260 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1261 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001262 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001263 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001264 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001265 }
1266
1267 i++;
1268 if (i == rx_ring->count)
1269 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001270 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001271
Auke Kok9a799d72007-09-15 14:07:45 -07001272no_buffers:
1273 if (rx_ring->next_to_use != i) {
1274 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001275 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001276 }
1277}
1278
Alexander Duyckc267fc12010-11-16 19:27:00 -08001279static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001280{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001281 /* HW will not DMA in data larger than the given buffer, even if it
1282 * parses the (NFS, of course) header to be larger. In that case, it
1283 * fills the header buffer and spills the rest into the page.
1284 */
1285 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1286 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1287 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1288 if (hlen > IXGBE_RX_HDR_SIZE)
1289 hlen = IXGBE_RX_HDR_SIZE;
1290 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001291}
1292
Alexander Duyckf8212f92009-04-27 22:42:37 +00001293/**
1294 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1295 * @skb: pointer to the last skb in the rsc queue
1296 *
1297 * This function changes a queue full of hw rsc buffers into a completed
1298 * packet. It uses the ->prev pointers to find the first packet and then
1299 * turns it into the frag list owner.
1300 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001301static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001302{
1303 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001304 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001305
1306 while (skb->prev) {
1307 struct sk_buff *prev = skb->prev;
1308 frag_list_size += skb->len;
1309 skb->prev = NULL;
1310 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001311 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001312 }
1313
1314 skb_shinfo(skb)->frag_list = skb->next;
1315 skb->next = NULL;
1316 skb->len += frag_list_size;
1317 skb->data_len += frag_list_size;
1318 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001319 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1320
Alexander Duyckf8212f92009-04-27 22:42:37 +00001321 return skb;
1322}
1323
Alexander Duyckaa801752010-11-16 19:27:02 -08001324static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1325{
1326 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1327 IXGBE_RXDADV_RSCCNT_MASK);
1328}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001329
Alexander Duyckc267fc12010-11-16 19:27:00 -08001330static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001331 struct ixgbe_ring *rx_ring,
1332 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001333{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001334 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001335 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1336 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1337 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001338 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001339 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001340#ifdef IXGBE_FCOE
1341 int ddp_bytes = 0;
1342#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001343 u32 staterr;
1344 u16 i;
1345 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001346 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001347
1348 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001349 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001350 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001351
1352 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001353 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001354
Milton Miller3c945e52010-02-19 17:44:42 +00001355 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001356
Alexander Duyckc267fc12010-11-16 19:27:00 -08001357 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1358
Auke Kok9a799d72007-09-15 14:07:45 -07001359 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001360 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001361 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001362
Alexander Duyckc267fc12010-11-16 19:27:00 -08001363 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001364 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001365
1366 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001367 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001368 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001369 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001370 !(staterr & IXGBE_RXD_STAT_EOP) &&
1371 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001372 /*
1373 * When HWRSC is enabled, delay unmapping
1374 * of the first packet. It carries the
1375 * header information, HW may still
1376 * access the header after the writeback.
1377 * Only unmap it when EOP is reached
1378 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001379 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001380 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001381 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001382 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001383 rx_buffer_info->dma,
1384 rx_ring->rx_buf_len,
1385 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001386 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001387 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001388
1389 if (ring_is_ps_enabled(rx_ring)) {
1390 hlen = ixgbe_get_hlen(rx_desc);
1391 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1392 } else {
1393 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1394 }
1395
1396 skb_put(skb, hlen);
1397 } else {
1398 /* assume packet split since header is unmapped */
1399 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001400 }
1401
1402 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001403 dma_unmap_page(rx_ring->dev,
1404 rx_buffer_info->page_dma,
1405 PAGE_SIZE / 2,
1406 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001407 rx_buffer_info->page_dma = 0;
1408 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001409 rx_buffer_info->page,
1410 rx_buffer_info->page_offset,
1411 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001412
Alexander Duyckc267fc12010-11-16 19:27:00 -08001413 if ((page_count(rx_buffer_info->page) == 1) &&
1414 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001415 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001416 else
1417 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001418
1419 skb->len += upper_len;
1420 skb->data_len += upper_len;
1421 skb->truesize += upper_len;
1422 }
1423
1424 i++;
1425 if (i == rx_ring->count)
1426 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001427
Alexander Duyck31f05a22010-08-19 13:40:31 +00001428 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001429 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001430 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001431
Alexander Duyckaa801752010-11-16 19:27:02 -08001432 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001433 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1434 IXGBE_RXDADV_NEXTP_SHIFT;
1435 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001436 } else {
1437 next_buffer = &rx_ring->rx_buffer_info[i];
1438 }
1439
Alexander Duyckc267fc12010-11-16 19:27:00 -08001440 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001441 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001442 rx_buffer_info->skb = next_buffer->skb;
1443 rx_buffer_info->dma = next_buffer->dma;
1444 next_buffer->skb = skb;
1445 next_buffer->dma = 0;
1446 } else {
1447 skb->next = next_buffer->skb;
1448 skb->next->prev = skb;
1449 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001450 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001451 goto next_desc;
1452 }
1453
Alexander Duyckaa801752010-11-16 19:27:02 -08001454 if (skb->prev) {
1455 skb = ixgbe_transform_rsc_queue(skb);
1456 /* if we got here without RSC the packet is invalid */
1457 if (!pkt_is_rsc) {
1458 __pskb_trim(skb, 0);
1459 rx_buffer_info->skb = skb;
1460 goto next_desc;
1461 }
1462 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001463
1464 if (ring_is_rsc_enabled(rx_ring)) {
1465 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1466 dma_unmap_single(rx_ring->dev,
1467 IXGBE_RSC_CB(skb)->dma,
1468 rx_ring->rx_buf_len,
1469 DMA_FROM_DEVICE);
1470 IXGBE_RSC_CB(skb)->dma = 0;
1471 IXGBE_RSC_CB(skb)->delay_unmap = false;
1472 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001473 }
1474 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001475 if (ring_is_ps_enabled(rx_ring))
1476 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001477 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001478 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001479 rx_ring->rx_stats.rsc_count +=
1480 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001481 rx_ring->rx_stats.rsc_flush++;
1482 }
1483
1484 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001485 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001486 /* trim packet back to size 0 and recycle it */
1487 __pskb_trim(skb, 0);
1488 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001489 goto next_desc;
1490 }
1491
Don Skidmore8bae1b22009-07-23 18:00:39 +00001492 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001493 if (adapter->netdev->features & NETIF_F_RXHASH)
1494 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001495
1496 /* probably a little skewed due to removing CRC */
1497 total_rx_bytes += skb->len;
1498 total_rx_packets++;
1499
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001500 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001501#ifdef IXGBE_FCOE
1502 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001503 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1504 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1505 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001506 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001507 }
Yi Zou332d4a72009-05-13 13:11:53 +00001508#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001509 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001510
1511next_desc:
1512 rx_desc->wb.upper.status_error = 0;
1513
Alexander Duyckc267fc12010-11-16 19:27:00 -08001514 (*work_done)++;
1515 if (*work_done >= work_to_do)
1516 break;
1517
Auke Kok9a799d72007-09-15 14:07:45 -07001518 /* return some buffers to hardware, one at a time is too slow */
1519 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001520 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001521 cleaned_count = 0;
1522 }
1523
1524 /* use prefetched values */
1525 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001526 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001527 }
1528
Auke Kok9a799d72007-09-15 14:07:45 -07001529 rx_ring->next_to_clean = i;
1530 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1531
1532 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001533 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001534
Yi Zou3d8fd382009-06-08 14:38:44 +00001535#ifdef IXGBE_FCOE
1536 /* include DDPed FCoE data */
1537 if (ddp_bytes > 0) {
1538 unsigned int mss;
1539
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001540 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001541 sizeof(struct fc_frame_header) -
1542 sizeof(struct fcoe_crc_eof);
1543 if (mss > 512)
1544 mss &= ~511;
1545 total_rx_bytes += ddp_bytes;
1546 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1547 }
1548#endif /* IXGBE_FCOE */
1549
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001550 rx_ring->total_packets += total_rx_packets;
1551 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001552 u64_stats_update_begin(&rx_ring->syncp);
1553 rx_ring->stats.packets += total_rx_packets;
1554 rx_ring->stats.bytes += total_rx_bytes;
1555 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001556}
1557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001558static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001559/**
1560 * ixgbe_configure_msix - Configure MSI-X hardware
1561 * @adapter: board private structure
1562 *
1563 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1564 * interrupts.
1565 **/
1566static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1567{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001568 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001569 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001570 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001571
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001572 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1573
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001574 /*
1575 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001576 * corresponding register.
1577 */
1578 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001579 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001580 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001581 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001582 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001583
1584 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001585 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1586 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001587 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001588 adapter->num_rx_queues,
1589 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001590 }
1591 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001592 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001593
1594 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001595 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1596 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001597 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001598 adapter->num_tx_queues,
1599 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001600 }
1601
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001602 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001603 /* tx only */
1604 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001605 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001606 /* rx or mixed */
1607 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001608
Alexander Duyckfe49f042009-06-04 16:00:09 +00001609 ixgbe_write_eitr(q_vector);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001610 /* If Flow Director is enabled, set interrupt affinity */
1611 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1612 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1613 /*
1614 * Allocate the affinity_hint cpumask, assign the mask
1615 * for this vector, and set our affinity_hint for
1616 * this irq.
1617 */
1618 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1619 GFP_KERNEL))
1620 return;
1621 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1622 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1623 q_vector->affinity_mask);
1624 }
Auke Kok9a799d72007-09-15 14:07:45 -07001625 }
1626
Alexander Duyckbd508172010-11-16 19:27:03 -08001627 switch (adapter->hw.mac.type) {
1628 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001629 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001630 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001631 break;
1632 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001633 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001634 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001635 break;
1636
1637 default:
1638 break;
1639 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001641
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001642 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001643 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001644 if (adapter->num_vfs)
1645 mask &= ~(IXGBE_EIMS_OTHER |
1646 IXGBE_EIMS_MAILBOX |
1647 IXGBE_EIMS_LSC);
1648 else
1649 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001650 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001651}
1652
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001653enum latency_range {
1654 lowest_latency = 0,
1655 low_latency = 1,
1656 bulk_latency = 2,
1657 latency_invalid = 255
1658};
1659
1660/**
1661 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1662 * @adapter: pointer to adapter
1663 * @eitr: eitr setting (ints per sec) to give last timeslice
1664 * @itr_setting: current throttle rate in ints/second
1665 * @packets: the number of packets during this measurement interval
1666 * @bytes: the number of bytes during this measurement interval
1667 *
1668 * Stores a new ITR value based on packets and byte
1669 * counts during the last interrupt. The advantage of per interrupt
1670 * computation is faster updates and more accurate ITR for the current
1671 * traffic pattern. Constants in this function were computed
1672 * based on theoretical maximum wire speed and thresholds were set based
1673 * on testing data as well as attempting to minimize response time
1674 * while increasing bulk throughput.
1675 * this functionality is controlled by the InterruptThrottleRate module
1676 * parameter (see ixgbe_param.c)
1677 **/
1678static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001679 u32 eitr, u8 itr_setting,
1680 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001681{
1682 unsigned int retval = itr_setting;
1683 u32 timepassed_us;
1684 u64 bytes_perint;
1685
1686 if (packets == 0)
1687 goto update_itr_done;
1688
1689
1690 /* simple throttlerate management
1691 * 0-20MB/s lowest (100000 ints/s)
1692 * 20-100MB/s low (20000 ints/s)
1693 * 100-1249MB/s bulk (8000 ints/s)
1694 */
1695 /* what was last interrupt timeslice? */
1696 timepassed_us = 1000000/eitr;
1697 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1698
1699 switch (itr_setting) {
1700 case lowest_latency:
1701 if (bytes_perint > adapter->eitr_low)
1702 retval = low_latency;
1703 break;
1704 case low_latency:
1705 if (bytes_perint > adapter->eitr_high)
1706 retval = bulk_latency;
1707 else if (bytes_perint <= adapter->eitr_low)
1708 retval = lowest_latency;
1709 break;
1710 case bulk_latency:
1711 if (bytes_perint <= adapter->eitr_high)
1712 retval = low_latency;
1713 break;
1714 }
1715
1716update_itr_done:
1717 return retval;
1718}
1719
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001720/**
1721 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001722 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001723 *
1724 * This function is made to be called by ethtool and by the driver
1725 * when it needs to update EITR registers at runtime. Hardware
1726 * specific quirks/differences are taken care of here.
1727 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001728void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001729{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001730 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001731 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001732 int v_idx = q_vector->v_idx;
1733 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1734
Alexander Duyckbd508172010-11-16 19:27:03 -08001735 switch (adapter->hw.mac.type) {
1736 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001737 /* must write high and low 16 bits to reset counter */
1738 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001739 break;
1740 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001741 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001742 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001743 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001744 * max interrupt rate, but there is an errata where it can
1745 * not be zero with RSC
1746 */
1747 if (itr_reg == 8 &&
1748 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1749 itr_reg = 0;
1750
1751 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001752 * set the WDIS bit to not clear the timer bits and cause an
1753 * immediate assertion of the interrupt
1754 */
1755 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001756 break;
1757 default:
1758 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001759 }
1760 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1761}
1762
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001763static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1764{
1765 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001766 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001767 u32 new_itr;
1768 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001769
1770 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1771 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001772 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001773 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001774 q_vector->tx_itr,
1775 tx_ring->total_packets,
1776 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001777 /* if the result for this queue would decrease interrupt
1778 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001779 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001780 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001781 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001782 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001783 }
1784
1785 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1786 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001787 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001788 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001789 q_vector->rx_itr,
1790 rx_ring->total_packets,
1791 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001792 /* if the result for this queue would decrease interrupt
1793 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001794 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001795 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001796 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001797 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001798 }
1799
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001800 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001801
1802 switch (current_itr) {
1803 /* counts and packets in update_itr are dependent on these numbers */
1804 case lowest_latency:
1805 new_itr = 100000;
1806 break;
1807 case low_latency:
1808 new_itr = 20000; /* aka hwitr = ~200 */
1809 break;
1810 case bulk_latency:
1811 default:
1812 new_itr = 8000;
1813 break;
1814 }
1815
1816 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001817 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001818 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001819
1820 /* save the algorithm value here, not the smoothed one */
1821 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001822
1823 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001824 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001825}
1826
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001827/**
Alexander Duyckf0f97782011-04-22 04:08:09 +00001828 * ixgbe_check_overtemp_subtask - check for over tempurature
1829 * @adapter: pointer to adapter
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001830 **/
Alexander Duyckf0f97782011-04-22 04:08:09 +00001831static void ixgbe_check_overtemp_subtask(struct ixgbe_adapter *adapter)
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001832{
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001833 struct ixgbe_hw *hw = &adapter->hw;
1834 u32 eicr = adapter->interrupt_event;
1835
Alexander Duyckf0f97782011-04-22 04:08:09 +00001836 if (test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perches7ca647b2010-09-07 21:35:40 +00001837 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001838
Alexander Duyckf0f97782011-04-22 04:08:09 +00001839 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1840 !(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_EVENT))
1841 return;
1842
1843 adapter->flags2 &= ~IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1844
Joe Perches7ca647b2010-09-07 21:35:40 +00001845 switch (hw->device_id) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00001846 case IXGBE_DEV_ID_82599_T3_LOM:
1847 /*
1848 * Since the warning interrupt is for both ports
1849 * we don't have to check if:
1850 * - This interrupt wasn't for our port.
1851 * - We may have missed the interrupt so always have to
1852 * check if we got a LSC
1853 */
1854 if (!(eicr & IXGBE_EICR_GPI_SDP0) &&
1855 !(eicr & IXGBE_EICR_LSC))
1856 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001857
Alexander Duyckf0f97782011-04-22 04:08:09 +00001858 if (!(eicr & IXGBE_EICR_LSC) && hw->mac.ops.check_link) {
1859 u32 autoneg;
1860 bool link_up = false;
1861
Joe Perches7ca647b2010-09-07 21:35:40 +00001862 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1863
Alexander Duyckf0f97782011-04-22 04:08:09 +00001864 if (link_up)
1865 return;
1866 }
1867
1868 /* Check if this is not due to overtemp */
1869 if (hw->phy.ops.check_overtemp(hw) != IXGBE_ERR_OVERTEMP)
1870 return;
1871
1872 break;
Joe Perches7ca647b2010-09-07 21:35:40 +00001873 default:
1874 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1875 return;
1876 break;
1877 }
1878 e_crit(drv,
1879 "Network adapter has been stopped because it has over heated. "
1880 "Restart the computer. If the problem persists, "
1881 "power off the system and replace the adapter\n");
Alexander Duyckf0f97782011-04-22 04:08:09 +00001882
1883 adapter->interrupt_event = 0;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001884}
1885
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001886static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1887{
1888 struct ixgbe_hw *hw = &adapter->hw;
1889
1890 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1891 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001892 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001893 /* write to clear the interrupt */
1894 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1895 }
1896}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001897
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001898static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1899{
1900 struct ixgbe_hw *hw = &adapter->hw;
1901
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001902 if (eicr & IXGBE_EICR_GPI_SDP2) {
1903 /* Clear the interrupt */
1904 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001905 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1906 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1907 ixgbe_service_event_schedule(adapter);
1908 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001909 }
1910
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001911 if (eicr & IXGBE_EICR_GPI_SDP1) {
1912 /* Clear the interrupt */
1913 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001914 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1915 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1916 ixgbe_service_event_schedule(adapter);
1917 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001918 }
1919}
1920
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001921static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1922{
1923 struct ixgbe_hw *hw = &adapter->hw;
1924
1925 adapter->lsc_int++;
1926 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1927 adapter->link_check_timeout = jiffies;
1928 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1929 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001930 IXGBE_WRITE_FLUSH(hw);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00001931 ixgbe_service_event_schedule(adapter);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001932 }
1933}
1934
Auke Kok9a799d72007-09-15 14:07:45 -07001935static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1936{
1937 struct net_device *netdev = data;
1938 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1939 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001940 u32 eicr;
1941
1942 /*
1943 * Workaround for Silicon errata. Use clear-by-write instead
1944 * of clear-by-read. Reading with EICS will return the
1945 * interrupt causes without clearing, which later be done
1946 * with the write to EICR.
1947 */
1948 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1949 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001950
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001951 if (eicr & IXGBE_EICR_LSC)
1952 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001953
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001954 if (eicr & IXGBE_EICR_MAILBOX)
1955 ixgbe_msg_task(adapter);
1956
Alexander Duyckbd508172010-11-16 19:27:03 -08001957 switch (hw->mac.type) {
1958 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001959 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001960 /* Handle Flow Director Full threshold interrupt */
1961 if (eicr & IXGBE_EICR_FLOW_DIR) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001962 int reinit_count = 0;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001963 int i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001964 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckd034acf2011-04-27 09:25:34 +00001965 struct ixgbe_ring *ring = adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001966 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckd034acf2011-04-27 09:25:34 +00001967 &ring->state))
1968 reinit_count++;
1969 }
1970 if (reinit_count) {
1971 /* no more flow director interrupts until after init */
1972 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_FLOW_DIR);
1973 eicr &= ~IXGBE_EICR_FLOW_DIR;
1974 adapter->flags2 |= IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
1975 ixgbe_service_event_schedule(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001976 }
1977 }
Alexander Duyckf0f97782011-04-22 04:08:09 +00001978 ixgbe_check_sfp_event(adapter, eicr);
1979 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1980 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1981 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1982 adapter->interrupt_event = eicr;
1983 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
1984 ixgbe_service_event_schedule(adapter);
1985 }
1986 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001987 break;
1988 default:
1989 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001990 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001991
1992 ixgbe_check_fan_failure(adapter, eicr);
1993
Alexander Duyck70864002011-04-27 09:13:56 +00001994 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001995 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001996 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1997 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001998
1999 return IRQ_HANDLED;
2000}
2001
Alexander Duyckfe49f042009-06-04 16:00:09 +00002002static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
2003 u64 qmask)
2004{
2005 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002006 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002007
Alexander Duyckbd508172010-11-16 19:27:03 -08002008 switch (hw->mac.type) {
2009 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002010 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002011 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
2012 break;
2013 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002014 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002015 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002016 if (mask)
2017 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002018 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002019 if (mask)
2020 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
2021 break;
2022 default:
2023 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002024 }
2025 /* skip the flush */
2026}
2027
2028static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002029 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00002030{
2031 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08002032 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002033
Alexander Duyckbd508172010-11-16 19:27:03 -08002034 switch (hw->mac.type) {
2035 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002036 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002037 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2038 break;
2039 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002040 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002041 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002042 if (mask)
2043 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002044 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002045 if (mask)
2046 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2047 break;
2048 default:
2049 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002050 }
2051 /* skip the flush */
2052}
2053
Auke Kok9a799d72007-09-15 14:07:45 -07002054static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2055{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002056 struct ixgbe_q_vector *q_vector = data;
2057 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002058 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002059 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002060
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002061 if (!q_vector->txr_count)
2062 return IRQ_HANDLED;
2063
2064 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2065 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002066 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002067 tx_ring->total_bytes = 0;
2068 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002069 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002070 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002071 }
2072
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002073 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002074 napi_schedule(&q_vector->napi);
2075
Auke Kok9a799d72007-09-15 14:07:45 -07002076 return IRQ_HANDLED;
2077}
2078
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002079/**
2080 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2081 * @irq: unused
2082 * @data: pointer to our q_vector struct for this interrupt vector
2083 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002084static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2085{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002086 struct ixgbe_q_vector *q_vector = data;
2087 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002088 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002089 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002090 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002091
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002092#ifdef CONFIG_IXGBE_DCA
2093 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2094 ixgbe_update_dca(q_vector);
2095#endif
2096
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002097 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002098 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002099 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002100 rx_ring->total_bytes = 0;
2101 rx_ring->total_packets = 0;
2102 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002103 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002104 }
2105
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002106 if (!q_vector->rxr_count)
2107 return IRQ_HANDLED;
2108
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002109 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002110 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002111
Auke Kok9a799d72007-09-15 14:07:45 -07002112 return IRQ_HANDLED;
2113}
2114
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002115static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2116{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002117 struct ixgbe_q_vector *q_vector = data;
2118 struct ixgbe_adapter *adapter = q_vector->adapter;
2119 struct ixgbe_ring *ring;
2120 int r_idx;
2121 int i;
2122
2123 if (!q_vector->txr_count && !q_vector->rxr_count)
2124 return IRQ_HANDLED;
2125
2126 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2127 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002128 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002129 ring->total_bytes = 0;
2130 ring->total_packets = 0;
2131 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002132 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002133 }
2134
2135 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2136 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002137 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002138 ring->total_bytes = 0;
2139 ring->total_packets = 0;
2140 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002141 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002142 }
2143
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002144 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002145 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002146
2147 return IRQ_HANDLED;
2148}
2149
2150/**
2151 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2152 * @napi: napi struct with our devices info in it
2153 * @budget: amount of work driver is allowed to do this pass, in packets
2154 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002155 * This function is optimized for cleaning one queue only on a single
2156 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002157 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002158static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2159{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002160 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002161 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002162 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002163 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002164 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002165 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002166
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002167#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002168 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002169 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002170#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002171
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002172 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2173 rx_ring = adapter->rx_ring[r_idx];
2174
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002175 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002176
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002177 /* If all Rx work done, exit the polling mode */
2178 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002179 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002180 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002181 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002182 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002183 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002184 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002185 }
2186
2187 return work_done;
2188}
2189
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002190/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002191 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002192 * @napi: napi struct with our devices info in it
2193 * @budget: amount of work driver is allowed to do this pass, in packets
2194 *
2195 * This function will clean more than one rx queue associated with a
2196 * q_vector.
2197 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002198static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002199{
2200 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002201 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002202 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002203 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002204 int work_done = 0, i;
2205 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002206 bool tx_clean_complete = true;
2207
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002208#ifdef CONFIG_IXGBE_DCA
2209 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2210 ixgbe_update_dca(q_vector);
2211#endif
2212
Alexander Duyck91281fd2009-06-04 16:00:27 +00002213 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2214 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002215 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002216 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2217 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002218 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002219 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002220
2221 /* attempt to distribute budget to each queue fairly, but don't allow
2222 * the budget to go below 1 because we'll exit polling */
2223 budget /= (q_vector->rxr_count ?: 1);
2224 budget = max(budget, 1);
2225 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2226 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002227 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002228 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002229 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002230 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002231 }
2232
2233 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002234 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002235 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002236 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002237 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002238 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002239 ixgbe_set_itr_msix(q_vector);
2240 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002241 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002242 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002243 return 0;
2244 }
2245
2246 return work_done;
2247}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002248
2249/**
2250 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2251 * @napi: napi struct with our devices info in it
2252 * @budget: amount of work driver is allowed to do this pass, in packets
2253 *
2254 * This function is optimized for cleaning one queue only on a single
2255 * q_vector!!!
2256 **/
2257static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2258{
2259 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002260 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002261 struct ixgbe_adapter *adapter = q_vector->adapter;
2262 struct ixgbe_ring *tx_ring = NULL;
2263 int work_done = 0;
2264 long r_idx;
2265
Alexander Duyck91281fd2009-06-04 16:00:27 +00002266#ifdef CONFIG_IXGBE_DCA
2267 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002268 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002269#endif
2270
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002271 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2272 tx_ring = adapter->tx_ring[r_idx];
2273
Alexander Duyck91281fd2009-06-04 16:00:27 +00002274 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2275 work_done = budget;
2276
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002277 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002278 if (work_done < budget) {
2279 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002280 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002281 ixgbe_set_itr_msix(q_vector);
2282 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002283 ixgbe_irq_enable_queues(adapter,
2284 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002285 }
2286
2287 return work_done;
2288}
2289
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002290static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002291 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002292{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002293 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002294 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002295
2296 set_bit(r_idx, q_vector->rxr_idx);
2297 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002298 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002299}
Auke Kok9a799d72007-09-15 14:07:45 -07002300
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002301static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002302 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002303{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002304 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002305 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002306
2307 set_bit(t_idx, q_vector->txr_idx);
2308 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002309 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002310}
Auke Kok9a799d72007-09-15 14:07:45 -07002311
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002312/**
2313 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2314 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002315 *
2316 * This function maps descriptor rings to the queue-specific vectors
2317 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2318 * one vector per ring/queue, but on a constrained vector budget, we
2319 * group the rings as "efficiently" as possible. You would add new
2320 * mapping configurations in here.
2321 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002322static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002323{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002324 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002325 int v_start = 0;
2326 int rxr_idx = 0, txr_idx = 0;
2327 int rxr_remaining = adapter->num_rx_queues;
2328 int txr_remaining = adapter->num_tx_queues;
2329 int i, j;
2330 int rqpv, tqpv;
2331 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002332
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002333 /* No mapping required if MSI-X is disabled. */
2334 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002335 goto out;
2336
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002337 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2338
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002339 /*
2340 * The ideal configuration...
2341 * We have enough vectors to map one per queue.
2342 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002343 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2345 map_vector_to_rxq(adapter, v_start, rxr_idx);
2346
2347 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2348 map_vector_to_txq(adapter, v_start, txr_idx);
2349
2350 goto out;
2351 }
2352
2353 /*
2354 * If we don't have enough vectors for a 1-to-1
2355 * mapping, we'll have to group them so there are
2356 * multiple queues per vector.
2357 */
2358 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002359 for (i = v_start; i < q_vectors; i++) {
2360 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002361 for (j = 0; j < rqpv; j++) {
2362 map_vector_to_rxq(adapter, i, rxr_idx);
2363 rxr_idx++;
2364 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002365 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002366 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002367 for (j = 0; j < tqpv; j++) {
2368 map_vector_to_txq(adapter, i, txr_idx);
2369 txr_idx++;
2370 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002371 }
Auke Kok9a799d72007-09-15 14:07:45 -07002372 }
Auke Kok9a799d72007-09-15 14:07:45 -07002373out:
Auke Kok9a799d72007-09-15 14:07:45 -07002374 return err;
2375}
2376
2377/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002378 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2379 * @adapter: board private structure
2380 *
2381 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2382 * interrupts from the kernel.
2383 **/
2384static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2385{
2386 struct net_device *netdev = adapter->netdev;
2387 irqreturn_t (*handler)(int, void *);
2388 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002389 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002390
2391 /* Decrement for Other and TCP Timer vectors */
2392 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2393
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002394 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002395 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002396 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002397
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002398#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2399 ? &ixgbe_msix_clean_many : \
2400 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2401 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2402 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002403 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002404 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2405 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002406
Joe Perchese8e9f692010-09-07 21:34:53 +00002407 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002408 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2409 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002410 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002411 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2412 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002413 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002414 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2415 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002416 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002417 } else {
2418 /* skip this unused q_vector */
2419 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002420 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002421 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002422 handler, 0, q_vector->name,
2423 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002424 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002425 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002426 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002427 goto free_queue_irqs;
2428 }
2429 }
2430
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002431 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002432 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002433 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002434 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002435 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002436 goto free_queue_irqs;
2437 }
2438
2439 return 0;
2440
2441free_queue_irqs:
2442 for (i = vector - 1; i >= 0; i--)
2443 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002444 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002445 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2446 pci_disable_msix(adapter->pdev);
2447 kfree(adapter->msix_entries);
2448 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002449 return err;
2450}
2451
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002452static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2453{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002454 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002455 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2456 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002457 u32 new_itr = q_vector->eitr;
2458 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002459
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002460 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002461 q_vector->tx_itr,
2462 tx_ring->total_packets,
2463 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002464 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002465 q_vector->rx_itr,
2466 rx_ring->total_packets,
2467 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002468
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002469 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002470
2471 switch (current_itr) {
2472 /* counts and packets in update_itr are dependent on these numbers */
2473 case lowest_latency:
2474 new_itr = 100000;
2475 break;
2476 case low_latency:
2477 new_itr = 20000; /* aka hwitr = ~200 */
2478 break;
2479 case bulk_latency:
2480 new_itr = 8000;
2481 break;
2482 default:
2483 break;
2484 }
2485
2486 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002487 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002488 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002489
Alexander Duyck125601b2010-11-16 19:27:08 -08002490 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002491 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002492
2493 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002494 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002495}
2496
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002497/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002498 * ixgbe_irq_enable - Enable default interrupt generation settings
2499 * @adapter: board private structure
2500 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002501static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2502 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002503{
2504 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002505
2506 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002507 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2508 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002509 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2510 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002511 switch (adapter->hw.mac.type) {
2512 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002513 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002514 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002515 mask |= IXGBE_EIMS_GPI_SDP1;
2516 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002517 if (adapter->num_vfs)
2518 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002519 break;
2520 default:
2521 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002522 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002523 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2524 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2525 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002526
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002527 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002528 if (queues)
2529 ixgbe_irq_enable_queues(adapter, ~0);
2530 if (flush)
2531 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002532
2533 if (adapter->num_vfs > 32) {
2534 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2535 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2536 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002537}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002538
2539/**
2540 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002541 * @irq: interrupt number
2542 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002543 **/
2544static irqreturn_t ixgbe_intr(int irq, void *data)
2545{
2546 struct net_device *netdev = data;
2547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2548 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002549 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002550 u32 eicr;
2551
Don Skidmore54037502009-02-21 15:42:56 -08002552 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002553 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002554 * before the read of EICR.
2555 */
2556 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2557
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002558 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2559 * therefore no explict interrupt disable is necessary */
2560 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002561 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002562 /*
2563 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002564 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002565 * have disabled interrupts due to EIAM
2566 * finish the workaround of silicon errata on 82598. Unmask
2567 * the interrupt that we masked before the EICR read.
2568 */
2569 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2570 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002571 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002572 }
Auke Kok9a799d72007-09-15 14:07:45 -07002573
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002574 if (eicr & IXGBE_EICR_LSC)
2575 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002576
Alexander Duyckbd508172010-11-16 19:27:03 -08002577 switch (hw->mac.type) {
2578 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002579 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002580 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2581 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
Alexander Duyckf0f97782011-04-22 04:08:09 +00002582 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
2583 adapter->interrupt_event = eicr;
2584 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_EVENT;
2585 ixgbe_service_event_schedule(adapter);
2586 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002587 }
2588 break;
2589 default:
2590 break;
2591 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002592
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002593 ixgbe_check_fan_failure(adapter, eicr);
2594
Alexander Duyck7a921c92009-05-06 10:43:28 +00002595 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002596 adapter->tx_ring[0]->total_packets = 0;
2597 adapter->tx_ring[0]->total_bytes = 0;
2598 adapter->rx_ring[0]->total_packets = 0;
2599 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002600 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002601 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002602 }
2603
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002604 /*
2605 * re-enable link(maybe) and non-queue interrupts, no flush.
2606 * ixgbe_poll will re-enable the queue interrupts
2607 */
2608
2609 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2610 ixgbe_irq_enable(adapter, false, false);
2611
Auke Kok9a799d72007-09-15 14:07:45 -07002612 return IRQ_HANDLED;
2613}
2614
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002615static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2616{
2617 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2618
2619 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002620 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002621 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2622 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2623 q_vector->rxr_count = 0;
2624 q_vector->txr_count = 0;
2625 }
2626}
2627
Auke Kok9a799d72007-09-15 14:07:45 -07002628/**
2629 * ixgbe_request_irq - initialize interrupts
2630 * @adapter: board private structure
2631 *
2632 * Attempts to configure interrupts using the best available
2633 * capabilities of the hardware and kernel.
2634 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002635static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002636{
2637 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002638 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002639
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002640 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2641 err = ixgbe_request_msix_irqs(adapter);
2642 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002643 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Joe Perchese8e9f692010-09-07 21:34:53 +00002644 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002645 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002646 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Joe Perchese8e9f692010-09-07 21:34:53 +00002647 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002648 }
2649
Auke Kok9a799d72007-09-15 14:07:45 -07002650 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002651 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002652
Auke Kok9a799d72007-09-15 14:07:45 -07002653 return err;
2654}
2655
2656static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2657{
2658 struct net_device *netdev = adapter->netdev;
2659
2660 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002661 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002662
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002663 q_vectors = adapter->num_msix_vectors;
2664
2665 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002666 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002667
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002668 i--;
2669 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002670 /* free only the irqs that were actually requested */
2671 if (!adapter->q_vector[i]->rxr_count &&
2672 !adapter->q_vector[i]->txr_count)
2673 continue;
2674
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002675 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002676 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002677 }
2678
2679 ixgbe_reset_q_vectors(adapter);
2680 } else {
2681 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002682 }
2683}
2684
2685/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002686 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2687 * @adapter: board private structure
2688 **/
2689static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2690{
Alexander Duyckbd508172010-11-16 19:27:03 -08002691 switch (adapter->hw.mac.type) {
2692 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002693 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002694 break;
2695 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002696 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002697 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2698 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002699 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002700 if (adapter->num_vfs > 32)
2701 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002702 break;
2703 default:
2704 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002705 }
2706 IXGBE_WRITE_FLUSH(&adapter->hw);
2707 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2708 int i;
2709 for (i = 0; i < adapter->num_msix_vectors; i++)
2710 synchronize_irq(adapter->msix_entries[i].vector);
2711 } else {
2712 synchronize_irq(adapter->pdev->irq);
2713 }
2714}
2715
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002716/**
Auke Kok9a799d72007-09-15 14:07:45 -07002717 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2718 *
2719 **/
2720static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2721{
Auke Kok9a799d72007-09-15 14:07:45 -07002722 struct ixgbe_hw *hw = &adapter->hw;
2723
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002724 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002725 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002726
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002727 ixgbe_set_ivar(adapter, 0, 0, 0);
2728 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002729
2730 map_vector_to_rxq(adapter, 0, 0);
2731 map_vector_to_txq(adapter, 0, 0);
2732
Emil Tantilov396e7992010-07-01 20:05:12 +00002733 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002734}
2735
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002736/**
2737 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2738 * @adapter: board private structure
2739 * @ring: structure containing ring specific data
2740 *
2741 * Configure the Tx descriptor ring after a reset.
2742 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002743void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2744 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002745{
2746 struct ixgbe_hw *hw = &adapter->hw;
2747 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002748 int wait_loop = 10;
2749 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002750 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002751
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002752 /* disable queue to avoid issues while updating state */
2753 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2754 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2755 txdctl & ~IXGBE_TXDCTL_ENABLE);
2756 IXGBE_WRITE_FLUSH(hw);
2757
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002758 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002759 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002760 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2761 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2762 ring->count * sizeof(union ixgbe_adv_tx_desc));
2763 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2764 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002765 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002766
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002767 /* configure fetching thresholds */
2768 if (adapter->rx_itr_setting == 0) {
2769 /* cannot set wthresh when itr==0 */
2770 txdctl &= ~0x007F0000;
2771 } else {
2772 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2773 txdctl |= (8 << 16);
2774 }
2775 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2776 /* PThresh workaround for Tx hang with DFP enabled. */
2777 txdctl |= 32;
2778 }
2779
2780 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002781 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2782 adapter->atr_sample_rate) {
2783 ring->atr_sample_rate = adapter->atr_sample_rate;
2784 ring->atr_count = 0;
2785 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2786 } else {
2787 ring->atr_sample_rate = 0;
2788 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002789
John Fastabendc84d3242010-11-16 19:27:12 -08002790 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2791
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002792 /* enable queue */
2793 txdctl |= IXGBE_TXDCTL_ENABLE;
2794 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2795
2796 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2797 if (hw->mac.type == ixgbe_mac_82598EB &&
2798 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2799 return;
2800
2801 /* poll to verify queue is enabled */
2802 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002803 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002804 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2805 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2806 if (!wait_loop)
2807 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002808}
2809
Alexander Duyck120ff942010-08-19 13:34:50 +00002810static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2811{
2812 struct ixgbe_hw *hw = &adapter->hw;
2813 u32 rttdcs;
2814 u32 mask;
2815
2816 if (hw->mac.type == ixgbe_mac_82598EB)
2817 return;
2818
2819 /* disable the arbiter while setting MTQC */
2820 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2821 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2822 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2823
2824 /* set transmit pool layout */
2825 mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
2826 switch (adapter->flags & mask) {
2827
2828 case (IXGBE_FLAG_SRIOV_ENABLED):
2829 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2830 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2831 break;
2832
2833 case (IXGBE_FLAG_DCB_ENABLED):
2834 /* We enable 8 traffic classes, DCB only */
2835 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2836 (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
2837 break;
2838
2839 default:
2840 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2841 break;
2842 }
2843
2844 /* re-enable the arbiter */
2845 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2846 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2847}
2848
Auke Kok9a799d72007-09-15 14:07:45 -07002849/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002850 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002851 * @adapter: board private structure
2852 *
2853 * Configure the Tx unit of the MAC after a reset.
2854 **/
2855static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2856{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002857 struct ixgbe_hw *hw = &adapter->hw;
2858 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002859 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002860
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002861 ixgbe_setup_mtqc(adapter);
2862
2863 if (hw->mac.type != ixgbe_mac_82598EB) {
2864 /* DMATXCTL.EN must be before Tx queues are enabled */
2865 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2866 dmatxctl |= IXGBE_DMATXCTL_TE;
2867 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2868 }
2869
Auke Kok9a799d72007-09-15 14:07:45 -07002870 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002871 for (i = 0; i < adapter->num_tx_queues; i++)
2872 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002873}
2874
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002875#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002876
Yi Zoua6616b42009-08-06 13:05:23 +00002877static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002878 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002879{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002880 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002881 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002882
Alexander Duyckbd508172010-11-16 19:27:03 -08002883 switch (adapter->hw.mac.type) {
2884 case ixgbe_mac_82598EB: {
2885 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2886 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002887 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002888 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002889 break;
2890 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002891 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002892 default:
2893 break;
2894 }
2895
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002896 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002897
2898 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2899 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002900 if (adapter->num_vfs)
2901 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002902
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002903 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2904 IXGBE_SRRCTL_BSIZEHDR_MASK;
2905
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002906 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002907#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2908 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2909#else
2910 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2911#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002912 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002913 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002914 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2915 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002916 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002917 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002918
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002919 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002920}
2921
Alexander Duyck05abb122010-08-19 13:35:41 +00002922static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002923{
Alexander Duyck05abb122010-08-19 13:35:41 +00002924 struct ixgbe_hw *hw = &adapter->hw;
2925 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002926 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2927 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002928 u32 mrqc = 0, reta = 0;
2929 u32 rxcsum;
2930 int i, j;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002931 int mask;
2932
Alexander Duyck05abb122010-08-19 13:35:41 +00002933 /* Fill out hash function seeds */
2934 for (i = 0; i < 10; i++)
2935 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002936
Alexander Duyck05abb122010-08-19 13:35:41 +00002937 /* Fill out redirection table */
2938 for (i = 0, j = 0; i < 128; i++, j++) {
2939 if (j == adapter->ring_feature[RING_F_RSS].indices)
2940 j = 0;
2941 /* reta = 4-byte sliding window of
2942 * 0x00..(indices-1)(indices-1)00..etc. */
2943 reta = (reta << 8) | (j * 0x11);
2944 if ((i & 3) == 3)
2945 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2946 }
2947
2948 /* Disable indicating checksum in descriptor, enables RSS hash */
2949 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2950 rxcsum |= IXGBE_RXCSUM_PCSD;
2951 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2952
2953 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2954 mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
2955 else
2956 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002957#ifdef CONFIG_IXGBE_DCB
Alexander Duyck05abb122010-08-19 13:35:41 +00002958 | IXGBE_FLAG_DCB_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002959#endif
Alexander Duyck05abb122010-08-19 13:35:41 +00002960 | IXGBE_FLAG_SRIOV_ENABLED
2961 );
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002962
2963 switch (mask) {
John Fastabend8187cd42011-02-23 05:58:08 +00002964#ifdef CONFIG_IXGBE_DCB
2965 case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED):
2966 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2967 break;
2968 case (IXGBE_FLAG_DCB_ENABLED):
2969 mrqc = IXGBE_MRQC_RT8TCEN;
2970 break;
2971#endif /* CONFIG_IXGBE_DCB */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002972 case (IXGBE_FLAG_RSS_ENABLED):
2973 mrqc = IXGBE_MRQC_RSSEN;
2974 break;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002975 case (IXGBE_FLAG_SRIOV_ENABLED):
2976 mrqc = IXGBE_MRQC_VMDQEN;
2977 break;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002978 default:
2979 break;
2980 }
2981
Alexander Duyck05abb122010-08-19 13:35:41 +00002982 /* Perform hash on these packet types */
2983 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2984 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2985 | IXGBE_MRQC_RSS_FIELD_IPV6
2986 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2987
2988 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002989}
2990
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002991/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002992 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2993 * @adapter: address of board private structure
2994 * @ring: structure containing ring specific data
2995 **/
2996void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2997 struct ixgbe_ring *ring)
2998{
2999 struct ixgbe_hw *hw = &adapter->hw;
3000 u32 rscctrl;
3001 u8 reg_idx = ring->reg_idx;
3002
3003 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
3004 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
3005 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
3006}
3007
3008/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003009 * ixgbe_configure_rscctl - enable RSC for the indicated ring
3010 * @adapter: address of board private structure
3011 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003012 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08003013void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00003014 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003015{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003016 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003017 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08003018 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003019 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003020
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003021 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00003022 return;
3023
3024 rx_buf_len = ring->rx_buf_len;
3025 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003026 rscctrl |= IXGBE_RSCCTL_RSCEN;
3027 /*
3028 * we must limit the number of descriptors so that the
3029 * total size of max desc * buf_len is not greater
3030 * than 65535
3031 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003032 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003033#if (MAX_SKB_FRAGS > 16)
3034 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3035#elif (MAX_SKB_FRAGS > 8)
3036 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3037#elif (MAX_SKB_FRAGS > 4)
3038 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3039#else
3040 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3041#endif
3042 } else {
3043 if (rx_buf_len < IXGBE_RXBUFFER_4096)
3044 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3045 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
3046 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3047 else
3048 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3049 }
Alexander Duyck73670962010-08-19 13:38:34 +00003050 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003051}
3052
Alexander Duyck9e10e042010-08-19 13:40:06 +00003053/**
3054 * ixgbe_set_uta - Set unicast filter table address
3055 * @adapter: board private structure
3056 *
3057 * The unicast table address is a register array of 32-bit registers.
3058 * The table is meant to be used in a way similar to how the MTA is used
3059 * however due to certain limitations in the hardware it is necessary to
3060 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3061 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3062 **/
3063static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3064{
3065 struct ixgbe_hw *hw = &adapter->hw;
3066 int i;
3067
3068 /* The UTA table only exists on 82599 hardware and newer */
3069 if (hw->mac.type < ixgbe_mac_82599EB)
3070 return;
3071
3072 /* we only need to do this if VMDq is enabled */
3073 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3074 return;
3075
3076 for (i = 0; i < 128; i++)
3077 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3078}
3079
3080#define IXGBE_MAX_RX_DESC_POLL 10
3081static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3082 struct ixgbe_ring *ring)
3083{
3084 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003085 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3086 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003087 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003088
3089 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3090 if (hw->mac.type == ixgbe_mac_82598EB &&
3091 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3092 return;
3093
3094 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003095 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003096 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3097 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3098
3099 if (!wait_loop) {
3100 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3101 "the polling period\n", reg_idx);
3102 }
3103}
3104
Yi Zou2d39d572011-01-06 14:29:56 +00003105void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3106 struct ixgbe_ring *ring)
3107{
3108 struct ixgbe_hw *hw = &adapter->hw;
3109 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3110 u32 rxdctl;
3111 u8 reg_idx = ring->reg_idx;
3112
3113 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3114 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3115
3116 /* write value back with RXDCTL.ENABLE bit cleared */
3117 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3118
3119 if (hw->mac.type == ixgbe_mac_82598EB &&
3120 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3121 return;
3122
3123 /* the hardware may take up to 100us to really disable the rx queue */
3124 do {
3125 udelay(10);
3126 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3127 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3128
3129 if (!wait_loop) {
3130 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3131 "the polling period\n", reg_idx);
3132 }
3133}
3134
Alexander Duyck84418e32010-08-19 13:40:54 +00003135void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3136 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003137{
3138 struct ixgbe_hw *hw = &adapter->hw;
3139 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003140 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003141 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003142
Alexander Duyck9e10e042010-08-19 13:40:06 +00003143 /* disable queue to avoid issues while updating state */
3144 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003145 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003146
Alexander Duyckacd37172010-08-19 13:36:05 +00003147 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3148 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3149 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3150 ring->count * sizeof(union ixgbe_adv_rx_desc));
3151 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3152 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003153 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003154
3155 ixgbe_configure_srrctl(adapter, ring);
3156 ixgbe_configure_rscctl(adapter, ring);
3157
Greg Rosee9f98072011-01-26 01:06:07 +00003158 /* If operating in IOV mode set RLPML for X540 */
3159 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3160 hw->mac.type == ixgbe_mac_X540) {
3161 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3162 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3163 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3164 }
3165
Alexander Duyck9e10e042010-08-19 13:40:06 +00003166 if (hw->mac.type == ixgbe_mac_82598EB) {
3167 /*
3168 * enable cache line friendly hardware writes:
3169 * PTHRESH=32 descriptors (half the internal cache),
3170 * this also removes ugly rx_no_buffer_count increment
3171 * HTHRESH=4 descriptors (to minimize latency on fetch)
3172 * WTHRESH=8 burst writeback up to two cache lines
3173 */
3174 rxdctl &= ~0x3FFFFF;
3175 rxdctl |= 0x080420;
3176 }
3177
3178 /* enable receive descriptor ring */
3179 rxdctl |= IXGBE_RXDCTL_ENABLE;
3180 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3181
3182 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08003183 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003184}
3185
Alexander Duyck48654522010-08-19 13:36:27 +00003186static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3187{
3188 struct ixgbe_hw *hw = &adapter->hw;
3189 int p;
3190
3191 /* PSRTYPE must be initialized in non 82598 adapters */
3192 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003193 IXGBE_PSRTYPE_UDPHDR |
3194 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003195 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003196 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003197
3198 if (hw->mac.type == ixgbe_mac_82598EB)
3199 return;
3200
3201 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3202 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3203
3204 for (p = 0; p < adapter->num_rx_pools; p++)
3205 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3206 psrtype);
3207}
3208
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003209static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3210{
3211 struct ixgbe_hw *hw = &adapter->hw;
3212 u32 gcr_ext;
3213 u32 vt_reg_bits;
3214 u32 reg_offset, vf_shift;
3215 u32 vmdctl;
3216
3217 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3218 return;
3219
3220 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3221 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3222 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3223 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3224
3225 vf_shift = adapter->num_vfs % 32;
3226 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3227
3228 /* Enable only the PF's pool for Tx/Rx */
3229 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3230 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3231 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3232 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3233 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3234
3235 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3236 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3237
3238 /*
3239 * Set up VF register offsets for selected VT Mode,
3240 * i.e. 32 or 64 VFs for SR-IOV
3241 */
3242 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3243 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3244 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3245 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3246
3247 /* enable Tx loopback for VF/PF communication */
3248 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003249 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003250 hw->mac.ops.set_mac_anti_spoofing(hw,
3251 (adapter->antispoofing_enabled =
3252 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003253 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003254}
3255
Alexander Duyck477de6e2010-08-19 13:38:11 +00003256static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003257{
Auke Kok9a799d72007-09-15 14:07:45 -07003258 struct ixgbe_hw *hw = &adapter->hw;
3259 struct net_device *netdev = adapter->netdev;
3260 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003261 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003262 struct ixgbe_ring *rx_ring;
3263 int i;
3264 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003265
Auke Kok9a799d72007-09-15 14:07:45 -07003266 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003267 /* On by default */
3268 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3269
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003270 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003271 if (adapter->num_vfs)
3272 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3273
3274 /* Disable packet split due to 82599 erratum #45 */
3275 if (hw->mac.type == ixgbe_mac_82599EB)
3276 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003277
3278 /* Set the RX buffer length according to the mode */
3279 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003280 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003281 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003282 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003283 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003284 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003285 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003286 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3287 }
3288
3289#ifdef IXGBE_FCOE
3290 /* adjust max frame to be able to do baby jumbo for FCoE */
3291 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3292 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3293 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3294
3295#endif /* IXGBE_FCOE */
3296 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3297 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3298 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3299 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3300
3301 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003302 }
3303
Auke Kok9a799d72007-09-15 14:07:45 -07003304 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003305 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3306 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003307 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3308
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003309 /*
3310 * Setup the HW Rx Head and Tail Descriptor Pointers and
3311 * the Base and Length of the Rx Descriptor Ring
3312 */
Auke Kok9a799d72007-09-15 14:07:45 -07003313 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003314 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003315 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003316
Yi Zou6e455b892009-08-06 13:05:44 +00003317 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003318 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003319 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003320 clear_ring_ps_enabled(rx_ring);
3321
3322 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3323 set_ring_rsc_enabled(rx_ring);
3324 else
3325 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003326
Yi Zou63f39bd2009-05-17 12:34:35 +00003327#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003328 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003329 struct ixgbe_ring_feature *f;
3330 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003331 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003332 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003333 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3334 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003335 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003336 } else if (!ring_is_rsc_enabled(rx_ring) &&
3337 !ring_is_ps_enabled(rx_ring)) {
3338 rx_ring->rx_buf_len =
3339 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003340 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003341 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003342#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003343 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003344}
3345
Alexander Duyck73670962010-08-19 13:38:34 +00003346static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3347{
3348 struct ixgbe_hw *hw = &adapter->hw;
3349 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3350
3351 switch (hw->mac.type) {
3352 case ixgbe_mac_82598EB:
3353 /*
3354 * For VMDq support of different descriptor types or
3355 * buffer sizes through the use of multiple SRRCTL
3356 * registers, RDRXCTL.MVMEN must be set to 1
3357 *
3358 * also, the manual doesn't mention it clearly but DCA hints
3359 * will only use queue 0's tags unless this bit is set. Side
3360 * effects of setting this bit are only that SRRCTL must be
3361 * fully programmed [0..15]
3362 */
3363 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3364 break;
3365 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003366 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003367 /* Disable RSC for ACK packets */
3368 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3369 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3370 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3371 /* hardware requires some bits to be set by default */
3372 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3373 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3374 break;
3375 default:
3376 /* We should do nothing since we don't know this hardware */
3377 return;
3378 }
3379
3380 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3381}
3382
Alexander Duyck477de6e2010-08-19 13:38:11 +00003383/**
3384 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3385 * @adapter: board private structure
3386 *
3387 * Configure the Rx unit of the MAC after a reset.
3388 **/
3389static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3390{
3391 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003392 int i;
3393 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003394
3395 /* disable receives while setting up the descriptors */
3396 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3397 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3398
3399 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003400 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003401
Alexander Duyck9e10e042010-08-19 13:40:06 +00003402 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003403 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003404
Alexander Duyck9e10e042010-08-19 13:40:06 +00003405 ixgbe_set_uta(adapter);
3406
Alexander Duyck477de6e2010-08-19 13:38:11 +00003407 /* set_rx_buffer_len must be called before ring initialization */
3408 ixgbe_set_rx_buffer_len(adapter);
3409
3410 /*
3411 * Setup the HW Rx Head and Tail Descriptor Pointers and
3412 * the Base and Length of the Rx Descriptor Ring
3413 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003414 for (i = 0; i < adapter->num_rx_queues; i++)
3415 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003416
Alexander Duyck9e10e042010-08-19 13:40:06 +00003417 /* disable drop enable for 82598 parts */
3418 if (hw->mac.type == ixgbe_mac_82598EB)
3419 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3420
3421 /* enable all receives */
3422 rxctrl |= IXGBE_RXCTRL_RXEN;
3423 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003424}
3425
Auke Kok9a799d72007-09-15 14:07:45 -07003426static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3427{
3428 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003429 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003430 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003431
3432 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003433 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003434 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003435}
3436
3437static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3438{
3439 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003440 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003441 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003442
Auke Kok9a799d72007-09-15 14:07:45 -07003443 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003444 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003445 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003446}
3447
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003448/**
3449 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3450 * @adapter: driver data
3451 */
3452static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3453{
3454 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003455 u32 vlnctrl;
3456
3457 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3458 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3459 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3460}
3461
3462/**
3463 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3464 * @adapter: driver data
3465 */
3466static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3467{
3468 struct ixgbe_hw *hw = &adapter->hw;
3469 u32 vlnctrl;
3470
3471 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3472 vlnctrl |= IXGBE_VLNCTRL_VFE;
3473 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3474 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3475}
3476
3477/**
3478 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3479 * @adapter: driver data
3480 */
3481static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3482{
3483 struct ixgbe_hw *hw = &adapter->hw;
3484 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003485 int i, j;
3486
3487 switch (hw->mac.type) {
3488 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003489 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3490 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003491 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3492 break;
3493 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003494 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003495 for (i = 0; i < adapter->num_rx_queues; i++) {
3496 j = adapter->rx_ring[i]->reg_idx;
3497 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3498 vlnctrl &= ~IXGBE_RXDCTL_VME;
3499 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3500 }
3501 break;
3502 default:
3503 break;
3504 }
3505}
3506
3507/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003508 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003509 * @adapter: driver data
3510 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003511static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003512{
3513 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003514 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003515 int i, j;
3516
3517 switch (hw->mac.type) {
3518 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003519 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3520 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003521 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3522 break;
3523 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003524 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003525 for (i = 0; i < adapter->num_rx_queues; i++) {
3526 j = adapter->rx_ring[i]->reg_idx;
3527 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3528 vlnctrl |= IXGBE_RXDCTL_VME;
3529 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3530 }
3531 break;
3532 default:
3533 break;
3534 }
3535}
3536
Auke Kok9a799d72007-09-15 14:07:45 -07003537static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3538{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003539 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003540
Jesse Grossf62bbb52010-10-20 13:56:10 +00003541 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3542
3543 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3544 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003545}
3546
3547/**
Alexander Duyck28500622010-06-15 09:25:48 +00003548 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3549 * @netdev: network interface device structure
3550 *
3551 * Writes unicast address list to the RAR table.
3552 * Returns: -ENOMEM on failure/insufficient address space
3553 * 0 on no addresses written
3554 * X on writing X addresses to the RAR table
3555 **/
3556static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3557{
3558 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3559 struct ixgbe_hw *hw = &adapter->hw;
3560 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003561 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003562 int count = 0;
3563
3564 /* return ENOMEM indicating insufficient memory for addresses */
3565 if (netdev_uc_count(netdev) > rar_entries)
3566 return -ENOMEM;
3567
3568 if (!netdev_uc_empty(netdev) && rar_entries) {
3569 struct netdev_hw_addr *ha;
3570 /* return error if we do not support writing to RAR table */
3571 if (!hw->mac.ops.set_rar)
3572 return -ENOMEM;
3573
3574 netdev_for_each_uc_addr(ha, netdev) {
3575 if (!rar_entries)
3576 break;
3577 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3578 vfn, IXGBE_RAH_AV);
3579 count++;
3580 }
3581 }
3582 /* write the addresses in reverse order to avoid write combining */
3583 for (; rar_entries > 0 ; rar_entries--)
3584 hw->mac.ops.clear_rar(hw, rar_entries);
3585
3586 return count;
3587}
3588
3589/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003590 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003591 * @netdev: network interface device structure
3592 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003593 * The set_rx_method entry point is called whenever the unicast/multicast
3594 * address list or the network interface flags are updated. This routine is
3595 * responsible for configuring the hardware for proper unicast, multicast and
3596 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003597 **/
Greg Rose7f870472010-01-09 02:25:29 +00003598void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003599{
3600 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3601 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003602 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3603 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003604
3605 /* Check for Promiscuous and All Multicast modes */
3606
3607 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3608
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003609 /* set all bits that we expect to always be set */
3610 fctrl |= IXGBE_FCTRL_BAM;
3611 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3612 fctrl |= IXGBE_FCTRL_PMCF;
3613
Alexander Duyck28500622010-06-15 09:25:48 +00003614 /* clear the bits we are changing the status of */
3615 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3616
Auke Kok9a799d72007-09-15 14:07:45 -07003617 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003618 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003619 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003620 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003621 /* don't hardware filter vlans in promisc mode */
3622 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003623 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003624 if (netdev->flags & IFF_ALLMULTI) {
3625 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003626 vmolr |= IXGBE_VMOLR_MPE;
3627 } else {
3628 /*
3629 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003630 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003631 * that we can at least receive multicast traffic
3632 */
3633 hw->mac.ops.update_mc_addr_list(hw, netdev);
3634 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003635 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003636 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003637 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003638 /*
3639 * Write addresses to available RAR registers, if there is not
3640 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003641 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003642 */
3643 count = ixgbe_write_uc_addr_list(netdev);
3644 if (count < 0) {
3645 fctrl |= IXGBE_FCTRL_UPE;
3646 vmolr |= IXGBE_VMOLR_ROPE;
3647 }
3648 }
3649
3650 if (adapter->num_vfs) {
3651 ixgbe_restore_vf_multicasts(adapter);
3652 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3653 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3654 IXGBE_VMOLR_ROPE);
3655 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003656 }
3657
3658 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003659
3660 if (netdev->features & NETIF_F_HW_VLAN_RX)
3661 ixgbe_vlan_strip_enable(adapter);
3662 else
3663 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003664}
3665
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003666static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3667{
3668 int q_idx;
3669 struct ixgbe_q_vector *q_vector;
3670 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3671
3672 /* legacy and MSI only use one vector */
3673 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3674 q_vectors = 1;
3675
3676 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003677 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003678 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003679 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003680 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3681 if (!q_vector->rxr_count || !q_vector->txr_count) {
3682 if (q_vector->txr_count == 1)
3683 napi->poll = &ixgbe_clean_txonly;
3684 else if (q_vector->rxr_count == 1)
3685 napi->poll = &ixgbe_clean_rxonly;
3686 }
3687 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003688
3689 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003690 }
3691}
3692
3693static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3694{
3695 int q_idx;
3696 struct ixgbe_q_vector *q_vector;
3697 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3698
3699 /* legacy and MSI only use one vector */
3700 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3701 q_vectors = 1;
3702
3703 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003704 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003705 napi_disable(&q_vector->napi);
3706 }
3707}
3708
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003709#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003710/*
3711 * ixgbe_configure_dcb - Configure DCB hardware
3712 * @adapter: ixgbe adapter struct
3713 *
3714 * This is called by the driver on open to configure the DCB hardware.
3715 * This is also called by the gennetlink interface when reconfiguring
3716 * the DCB state.
3717 */
3718static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3719{
3720 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003721 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003722
Alexander Duyck67ebd792010-08-19 13:34:04 +00003723 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3724 if (hw->mac.type == ixgbe_mac_82598EB)
3725 netif_set_gso_max_size(adapter->netdev, 65536);
3726 return;
3727 }
3728
3729 if (hw->mac.type == ixgbe_mac_82598EB)
3730 netif_set_gso_max_size(adapter->netdev, 32768);
3731
Alexander Duyck2f90b862008-11-20 20:52:10 -08003732
Alexander Duyck2f90b862008-11-20 20:52:10 -08003733 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003734 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003735
Alexander Duyck2f90b862008-11-20 20:52:10 -08003736 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003737
3738 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003739 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3740#ifdef CONFIG_FCOE
3741 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3742 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3743#endif
3744 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3745 DCB_TX_CONFIG);
3746 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3747 DCB_RX_CONFIG);
3748 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3749 } else {
3750 struct net_device *dev = adapter->netdev;
3751
3752 if (adapter->ixgbe_ieee_ets)
3753 dev->dcbnl_ops->ieee_setets(dev,
3754 adapter->ixgbe_ieee_ets);
3755 if (adapter->ixgbe_ieee_pfc)
3756 dev->dcbnl_ops->ieee_setpfc(dev,
3757 adapter->ixgbe_ieee_pfc);
3758 }
John Fastabend8187cd42011-02-23 05:58:08 +00003759
3760 /* Enable RSS Hash per TC */
3761 if (hw->mac.type != ixgbe_mac_82598EB) {
3762 int i;
3763 u32 reg = 0;
3764
3765 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3766 u8 msb = 0;
3767 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3768
3769 while (cnt >>= 1)
3770 msb++;
3771
3772 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3773 }
3774 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3775 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003776}
3777
3778#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003779static void ixgbe_configure(struct ixgbe_adapter *adapter)
3780{
3781 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003782 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003783 int i;
3784
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003785#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003786 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003787#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003788
Jesse Grossf62bbb52010-10-20 13:56:10 +00003789 ixgbe_set_rx_mode(netdev);
3790 ixgbe_restore_vlan(adapter);
3791
Yi Zoueacd73f2009-05-13 13:11:06 +00003792#ifdef IXGBE_FCOE
3793 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3794 ixgbe_configure_fcoe(adapter);
3795
3796#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003797 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3798 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003799 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003800 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003801 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3802 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3803 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3804 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003805 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003806
Auke Kok9a799d72007-09-15 14:07:45 -07003807 ixgbe_configure_tx(adapter);
3808 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003809}
3810
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003811static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3812{
3813 switch (hw->phy.type) {
3814 case ixgbe_phy_sfp_avago:
3815 case ixgbe_phy_sfp_ftl:
3816 case ixgbe_phy_sfp_intel:
3817 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003818 case ixgbe_phy_sfp_passive_tyco:
3819 case ixgbe_phy_sfp_passive_unknown:
3820 case ixgbe_phy_sfp_active_unknown:
3821 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003822 return true;
3823 default:
3824 return false;
3825 }
3826}
3827
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003828/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003829 * ixgbe_sfp_link_config - set up SFP+ link
3830 * @adapter: pointer to private adapter struct
3831 **/
3832static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3833{
Alexander Duyck70864002011-04-27 09:13:56 +00003834 /*
3835 * We are assuming the worst case scenerio here, and that
3836 * is that an SFP was inserted/removed after the reset
3837 * but before SFP detection was enabled. As such the best
3838 * solution is to just start searching as soon as we start
3839 */
3840 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3841 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003842
Alexander Duyck70864002011-04-27 09:13:56 +00003843 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003844}
3845
3846/**
3847 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003848 * @hw: pointer to private hardware struct
3849 *
3850 * Returns 0 on success, negative on failure
3851 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003852static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003853{
3854 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003855 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003856 u32 ret = IXGBE_ERR_LINK_SETUP;
3857
3858 if (hw->mac.ops.check_link)
3859 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3860
3861 if (ret)
3862 goto link_cfg_out;
3863
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003864 autoneg = hw->phy.autoneg_advertised;
3865 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003866 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3867 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003868 if (ret)
3869 goto link_cfg_out;
3870
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003871 if (hw->mac.ops.setup_link)
3872 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003873link_cfg_out:
3874 return ret;
3875}
3876
Alexander Duycka34bcff2010-08-19 13:39:20 +00003877static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003878{
Auke Kok9a799d72007-09-15 14:07:45 -07003879 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003880 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003881
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003882 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003883 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3884 IXGBE_GPIE_OCD;
3885 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003886 /*
3887 * use EIAM to auto-mask when MSI-X interrupt is asserted
3888 * this saves a register write for every interrupt
3889 */
3890 switch (hw->mac.type) {
3891 case ixgbe_mac_82598EB:
3892 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3893 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003894 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003895 case ixgbe_mac_X540:
3896 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003897 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3898 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3899 break;
3900 }
3901 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003902 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3903 * specifically only auto mask tx and rx interrupts */
3904 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003905 }
3906
Alexander Duycka34bcff2010-08-19 13:39:20 +00003907 /* XXX: to interrupt immediately for EICS writes, enable this */
3908 /* gpie |= IXGBE_GPIE_EIMEN; */
3909
3910 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3911 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3912 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003913 }
3914
Alexander Duycka34bcff2010-08-19 13:39:20 +00003915 /* Enable fan failure interrupt */
3916 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003917 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003918
Don Skidmore2698b202011-04-13 07:01:52 +00003919 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003920 gpie |= IXGBE_SDP1_GPIEN;
3921 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003922 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003923
3924 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3925}
3926
3927static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3928{
3929 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003930 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003931 u32 ctrl_ext;
3932
3933 ixgbe_get_hw_control(adapter);
3934 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003935
Auke Kok9a799d72007-09-15 14:07:45 -07003936 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3937 ixgbe_configure_msix(adapter);
3938 else
3939 ixgbe_configure_msi_and_legacy(adapter);
3940
Don Skidmorec6ecf392010-12-03 03:31:51 +00003941 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3942 if (hw->mac.ops.enable_tx_laser &&
3943 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003944 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003945 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003946 hw->mac.ops.enable_tx_laser(hw);
3947
Auke Kok9a799d72007-09-15 14:07:45 -07003948 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003949 ixgbe_napi_enable_all(adapter);
3950
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003951 if (ixgbe_is_sfp(hw)) {
3952 ixgbe_sfp_link_config(adapter);
3953 } else {
3954 err = ixgbe_non_sfp_link_config(hw);
3955 if (err)
3956 e_err(probe, "link_config FAILED %d\n", err);
3957 }
3958
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003959 /* clear any pending interrupts, may auto mask */
3960 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003961 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003962
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003963 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003964 * If this adapter has a fan, check to see if we had a failure
3965 * before we enabled the interrupt.
3966 */
3967 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3968 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3969 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003970 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003971 }
3972
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003973 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003974 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003975
Auke Kok9a799d72007-09-15 14:07:45 -07003976 /* bring the link up in the watchdog, this could race with our first
3977 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003978 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3979 adapter->link_check_timeout = jiffies;
Alexander Duyck70864002011-04-27 09:13:56 +00003980 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003981
3982 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3983 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3984 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3985 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3986
Auke Kok9a799d72007-09-15 14:07:45 -07003987 return 0;
3988}
3989
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003990void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3991{
3992 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003993 /* put off any impending NetWatchDogTimeout */
3994 adapter->netdev->trans_start = jiffies;
3995
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003996 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003997 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003998 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003999 /*
4000 * If SR-IOV enabled then wait a bit before bringing the adapter
4001 * back up to give the VFs time to respond to the reset. The
4002 * two second wait is based upon the watchdog timer cycle in
4003 * the VF driver.
4004 */
4005 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4006 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004007 ixgbe_up(adapter);
4008 clear_bit(__IXGBE_RESETTING, &adapter->state);
4009}
4010
Auke Kok9a799d72007-09-15 14:07:45 -07004011int ixgbe_up(struct ixgbe_adapter *adapter)
4012{
4013 /* hardware has been reset, we need to reload some things */
4014 ixgbe_configure(adapter);
4015
4016 return ixgbe_up_complete(adapter);
4017}
4018
4019void ixgbe_reset(struct ixgbe_adapter *adapter)
4020{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07004021 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07004022 int err;
4023
Alexander Duyck70864002011-04-27 09:13:56 +00004024 /* lock SFP init bit to prevent race conditions with the watchdog */
4025 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
4026 usleep_range(1000, 2000);
4027
4028 /* clear all SFP and link config related flags while holding SFP_INIT */
4029 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
4030 IXGBE_FLAG2_SFP_NEEDS_RESET);
4031 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
4032
Don Skidmore8ca783a2009-05-26 20:40:47 -07004033 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004034 switch (err) {
4035 case 0:
4036 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004037 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004038 break;
4039 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004040 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004041 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004042 case IXGBE_ERR_EEPROM_VERSION:
4043 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004044 e_dev_warn("This device is a pre-production adapter/LOM. "
4045 "Please be aware there may be issuesassociated with "
4046 "your hardware. If you are experiencing problems "
4047 "please contact your Intel or hardware "
4048 "representative who provided you with this "
4049 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004050 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004051 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004052 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004053 }
Auke Kok9a799d72007-09-15 14:07:45 -07004054
Alexander Duyck70864002011-04-27 09:13:56 +00004055 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4056
Auke Kok9a799d72007-09-15 14:07:45 -07004057 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004058 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4059 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004060}
4061
Auke Kok9a799d72007-09-15 14:07:45 -07004062/**
4063 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004064 * @rx_ring: ring to free buffers from
4065 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004066static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004067{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004068 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004069 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004070 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004071
Alexander Duyck84418e32010-08-19 13:40:54 +00004072 /* ring already cleared, nothing to do */
4073 if (!rx_ring->rx_buffer_info)
4074 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004075
Alexander Duyck84418e32010-08-19 13:40:54 +00004076 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004077 for (i = 0; i < rx_ring->count; i++) {
4078 struct ixgbe_rx_buffer *rx_buffer_info;
4079
4080 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4081 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004082 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004083 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004084 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004085 rx_buffer_info->dma = 0;
4086 }
4087 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004088 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004089 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004090 do {
4091 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004092 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004093 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004094 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004095 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004096 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004097 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004098 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004099 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004100 skb = skb->prev;
4101 dev_kfree_skb(this);
4102 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004103 }
4104 if (!rx_buffer_info->page)
4105 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004106 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004107 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004108 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004109 rx_buffer_info->page_dma = 0;
4110 }
Auke Kok9a799d72007-09-15 14:07:45 -07004111 put_page(rx_buffer_info->page);
4112 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004113 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004114 }
4115
4116 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4117 memset(rx_ring->rx_buffer_info, 0, size);
4118
4119 /* Zero out the descriptor ring */
4120 memset(rx_ring->desc, 0, rx_ring->size);
4121
4122 rx_ring->next_to_clean = 0;
4123 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004124}
4125
4126/**
4127 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004128 * @tx_ring: ring to be cleaned
4129 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004130static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004131{
4132 struct ixgbe_tx_buffer *tx_buffer_info;
4133 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004134 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004135
Alexander Duyck84418e32010-08-19 13:40:54 +00004136 /* ring already cleared, nothing to do */
4137 if (!tx_ring->tx_buffer_info)
4138 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004139
Alexander Duyck84418e32010-08-19 13:40:54 +00004140 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004141 for (i = 0; i < tx_ring->count; i++) {
4142 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004143 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004144 }
4145
4146 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4147 memset(tx_ring->tx_buffer_info, 0, size);
4148
4149 /* Zero out the descriptor ring */
4150 memset(tx_ring->desc, 0, tx_ring->size);
4151
4152 tx_ring->next_to_use = 0;
4153 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004154}
4155
4156/**
Auke Kok9a799d72007-09-15 14:07:45 -07004157 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4158 * @adapter: board private structure
4159 **/
4160static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4161{
4162 int i;
4163
4164 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004165 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004166}
4167
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004168/**
4169 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4170 * @adapter: board private structure
4171 **/
4172static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4173{
4174 int i;
4175
4176 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004177 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004178}
4179
Auke Kok9a799d72007-09-15 14:07:45 -07004180void ixgbe_down(struct ixgbe_adapter *adapter)
4181{
4182 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004183 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004184 u32 rxctrl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004185 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004186 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004187
4188 /* signal that we are down to the interrupt handler */
4189 set_bit(__IXGBE_DOWN, &adapter->state);
4190
4191 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004192 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4193 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004194
Yi Zou2d39d572011-01-06 14:29:56 +00004195 /* disable all enabled rx queues */
4196 for (i = 0; i < adapter->num_rx_queues; i++)
4197 /* this call also flushes the previous write */
4198 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4199
Don Skidmore032b4322011-03-18 09:32:53 +00004200 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004201
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004202 netif_tx_stop_all_queues(netdev);
4203
Alexander Duyck70864002011-04-27 09:13:56 +00004204 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004205 netif_carrier_off(netdev);
4206 netif_tx_disable(netdev);
4207
4208 ixgbe_irq_disable(adapter);
4209
4210 ixgbe_napi_disable_all(adapter);
4211
Alexander Duyckd034acf2011-04-27 09:25:34 +00004212 adapter->flags2 &= ~(IXGBE_FLAG2_FDIR_REQUIRES_REINIT |
4213 IXGBE_FLAG2_RESET_REQUESTED);
Alexander Duyck70864002011-04-27 09:13:56 +00004214 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4215
4216 del_timer_sync(&adapter->service_timer);
4217
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004218 /* disable receive for all VFs and wait one second */
4219 if (adapter->num_vfs) {
4220 /* ping all the active vfs to let them know we are going down */
4221 ixgbe_ping_all_vfs(adapter);
4222
4223 /* Disable all VFTE/VFRE TX/RX */
4224 ixgbe_disable_tx_rx(adapter);
4225
4226 /* Mark all the VFs as inactive */
4227 for (i = 0 ; i < adapter->num_vfs; i++)
4228 adapter->vfinfo[i].clear_to_send = 0;
4229 }
4230
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004231 /* Cleanup the affinity_hint CPU mask memory and callback */
4232 for (i = 0; i < num_q_vectors; i++) {
4233 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4234 /* clear the affinity_mask in the IRQ descriptor */
4235 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4236 /* release the CPU mask memory */
4237 free_cpumask_var(q_vector->affinity_mask);
4238 }
4239
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004240 /* disable transmits in the hardware now that interrupts are off */
4241 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004242 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004243 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), IXGBE_TXDCTL_SWFLSH);
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004244 }
Alexander Duyck34cecbb2011-04-22 04:08:14 +00004245
4246 /* Disable the Tx DMA engine on 82599 and X540 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004247 switch (hw->mac.type) {
4248 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004249 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004250 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004251 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4252 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004253 break;
4254 default:
4255 break;
4256 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004257
Paul Larson6f4a0e42008-06-24 17:00:56 -07004258 if (!pci_channel_offline(adapter->pdev))
4259 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004260
4261 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4262 if (hw->mac.ops.disable_tx_laser &&
4263 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004264 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004265 (hw->mac.type == ixgbe_mac_82599EB))))
4266 hw->mac.ops.disable_tx_laser(hw);
4267
Auke Kok9a799d72007-09-15 14:07:45 -07004268 ixgbe_clean_all_tx_rings(adapter);
4269 ixgbe_clean_all_rx_rings(adapter);
4270
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004271#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004272 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004273 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004274#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004275}
4276
Auke Kok9a799d72007-09-15 14:07:45 -07004277/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004278 * ixgbe_poll - NAPI Rx polling callback
4279 * @napi: structure for representing this polling device
4280 * @budget: how many packets driver is allowed to clean
4281 *
4282 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004283 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004284static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004285{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004286 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004287 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004288 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004289 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004290
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004291#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004292 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4293 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004294#endif
4295
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004296 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4297 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004298
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004299 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004300 work_done = budget;
4301
David S. Miller53e52c72008-01-07 21:06:12 -08004302 /* If budget not fully consumed, exit the polling mode */
4303 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004304 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004305 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004306 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004307 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004308 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004309 }
Auke Kok9a799d72007-09-15 14:07:45 -07004310 return work_done;
4311}
4312
4313/**
4314 * ixgbe_tx_timeout - Respond to a Tx Hang
4315 * @netdev: network interface device structure
4316 **/
4317static void ixgbe_tx_timeout(struct net_device *netdev)
4318{
4319 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4320
4321 /* Do the reset outside of interrupt context */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00004322 ixgbe_tx_timeout_reset(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004323}
4324
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004325/**
4326 * ixgbe_set_rss_queues: Allocate queues for RSS
4327 * @adapter: board private structure to initialize
4328 *
4329 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4330 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4331 *
4332 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004333static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4334{
4335 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004336 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004337
4338 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004339 f->mask = 0xF;
4340 adapter->num_rx_queues = f->indices;
4341 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004342 ret = true;
4343 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004344 ret = false;
4345 }
4346
4347 return ret;
4348}
4349
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004350/**
4351 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4352 * @adapter: board private structure to initialize
4353 *
4354 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4355 * to the original CPU that initiated the Tx session. This runs in addition
4356 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4357 * Rx load across CPUs using RSS.
4358 *
4359 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004360static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004361{
4362 bool ret = false;
4363 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4364
4365 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4366 f_fdir->mask = 0;
4367
4368 /* Flow Director must have RSS enabled */
4369 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4370 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4371 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4372 adapter->num_tx_queues = f_fdir->indices;
4373 adapter->num_rx_queues = f_fdir->indices;
4374 ret = true;
4375 } else {
4376 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4377 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4378 }
4379 return ret;
4380}
4381
Yi Zou0331a832009-05-17 12:33:52 +00004382#ifdef IXGBE_FCOE
4383/**
4384 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4385 * @adapter: board private structure to initialize
4386 *
4387 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4388 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4389 * rx queues out of the max number of rx queues, instead, it is used as the
4390 * index of the first rx queue used by FCoE.
4391 *
4392 **/
4393static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4394{
Yi Zou0331a832009-05-17 12:33:52 +00004395 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4396
John Fastabende5b64632011-03-08 03:44:52 +00004397 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4398 return false;
4399
4400 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4401#ifdef CONFIG_IXGBE_DCB
4402 int tc;
4403 struct net_device *dev = adapter->netdev;
4404
4405 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4406 f->indices = dev->tc_to_txq[tc].count;
4407 f->mask = dev->tc_to_txq[tc].offset;
4408#endif
4409 } else {
4410 f->indices = min((int)num_online_cpus(), f->indices);
4411
Yi Zou8de8b2e2009-09-03 14:55:50 +00004412 adapter->num_rx_queues = 1;
4413 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004414
Yi Zou0331a832009-05-17 12:33:52 +00004415 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004416 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004417 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4418 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4419 ixgbe_set_fdir_queues(adapter);
4420 else
4421 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004422 }
4423 /* adding FCoE rx rings to the end */
4424 f->mask = adapter->num_rx_queues;
4425 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004426 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004427 }
4428
John Fastabende5b64632011-03-08 03:44:52 +00004429 return true;
4430}
4431#endif /* IXGBE_FCOE */
4432
4433#ifdef CONFIG_IXGBE_DCB
4434static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4435{
4436 bool ret = false;
4437 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4438 int i, q;
4439
4440 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4441 return ret;
4442
4443 f->indices = 0;
4444 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4445 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4446 f->indices += q;
4447 }
4448
4449 f->mask = 0x7 << 3;
4450 adapter->num_rx_queues = f->indices;
4451 adapter->num_tx_queues = f->indices;
4452 ret = true;
4453
4454#ifdef IXGBE_FCOE
4455 /* FCoE enabled queues require special configuration done through
4456 * configure_fcoe() and others. Here we map FCoE indices onto the
4457 * DCB queue pairs allowing FCoE to own configuration later.
4458 */
4459 ixgbe_set_fcoe_queues(adapter);
4460#endif
4461
Yi Zou0331a832009-05-17 12:33:52 +00004462 return ret;
4463}
John Fastabende5b64632011-03-08 03:44:52 +00004464#endif
Yi Zou0331a832009-05-17 12:33:52 +00004465
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004466/**
4467 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4468 * @adapter: board private structure to initialize
4469 *
4470 * IOV doesn't actually use anything, so just NAK the
4471 * request for now and let the other queue routines
4472 * figure out what to do.
4473 */
4474static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4475{
4476 return false;
4477}
4478
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004479/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004480 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004481 * @adapter: board private structure to initialize
4482 *
4483 * This is the top level queue allocation routine. The order here is very
4484 * important, starting with the "most" number of features turned on at once,
4485 * and ending with the smallest set of features. This way large combinations
4486 * can be allocated if they're turned on, and smaller combinations are the
4487 * fallthrough conditions.
4488 *
4489 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004490static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004491{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004492 /* Start with base case */
4493 adapter->num_rx_queues = 1;
4494 adapter->num_tx_queues = 1;
4495 adapter->num_rx_pools = adapter->num_rx_queues;
4496 adapter->num_rx_queues_per_pool = 1;
4497
4498 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004499 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004500
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004501#ifdef CONFIG_IXGBE_DCB
4502 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004503 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004504
4505#endif
John Fastabende5b64632011-03-08 03:44:52 +00004506#ifdef IXGBE_FCOE
4507 if (ixgbe_set_fcoe_queues(adapter))
4508 goto done;
4509
4510#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004511 if (ixgbe_set_fdir_queues(adapter))
4512 goto done;
4513
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004514 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004515 goto done;
4516
4517 /* fallback to base case */
4518 adapter->num_rx_queues = 1;
4519 adapter->num_tx_queues = 1;
4520
4521done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004522 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004523 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004524 return netif_set_real_num_rx_queues(adapter->netdev,
4525 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004526}
4527
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004528static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004529 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004530{
4531 int err, vector_threshold;
4532
4533 /* We'll want at least 3 (vector_threshold):
4534 * 1) TxQ[0] Cleanup
4535 * 2) RxQ[0] Cleanup
4536 * 3) Other (Link Status Change, etc.)
4537 * 4) TCP Timer (optional)
4538 */
4539 vector_threshold = MIN_MSIX_COUNT;
4540
4541 /* The more we get, the more we will assign to Tx/Rx Cleanup
4542 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4543 * Right now, we simply care about how many we'll get; we'll
4544 * set them up later while requesting irq's.
4545 */
4546 while (vectors >= vector_threshold) {
4547 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004548 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004549 if (!err) /* Success in acquiring all requested vectors. */
4550 break;
4551 else if (err < 0)
4552 vectors = 0; /* Nasty failure, quit now */
4553 else /* err == number of vectors we should try again with */
4554 vectors = err;
4555 }
4556
4557 if (vectors < vector_threshold) {
4558 /* Can't allocate enough MSI-X interrupts? Oh well.
4559 * This just means we'll go with either a single MSI
4560 * vector or fall back to legacy interrupts.
4561 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004562 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4563 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004564 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4565 kfree(adapter->msix_entries);
4566 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004567 } else {
4568 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004569 /*
4570 * Adjust for only the vectors we'll use, which is minimum
4571 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4572 * vectors we were allocated.
4573 */
4574 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004575 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004576 }
4577}
4578
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004579/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004580 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004581 * @adapter: board private structure to initialize
4582 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004583 * Cache the descriptor ring offsets for RSS to the assigned rings.
4584 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004585 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004586static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004587{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004588 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004589
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004590 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4591 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004592
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004593 for (i = 0; i < adapter->num_rx_queues; i++)
4594 adapter->rx_ring[i]->reg_idx = i;
4595 for (i = 0; i < adapter->num_tx_queues; i++)
4596 adapter->tx_ring[i]->reg_idx = i;
4597
4598 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004599}
4600
4601#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004602
4603/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004604static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4605 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004606{
4607 struct net_device *dev = adapter->netdev;
4608 struct ixgbe_hw *hw = &adapter->hw;
4609 u8 num_tcs = netdev_get_num_tc(dev);
4610
4611 *tx = 0;
4612 *rx = 0;
4613
4614 switch (hw->mac.type) {
4615 case ixgbe_mac_82598EB:
4616 *tx = tc << 3;
4617 *rx = tc << 2;
4618 break;
4619 case ixgbe_mac_82599EB:
4620 case ixgbe_mac_X540:
4621 if (num_tcs == 8) {
4622 if (tc < 3) {
4623 *tx = tc << 5;
4624 *rx = tc << 4;
4625 } else if (tc < 5) {
4626 *tx = ((tc + 2) << 4);
4627 *rx = tc << 4;
4628 } else if (tc < num_tcs) {
4629 *tx = ((tc + 8) << 3);
4630 *rx = tc << 4;
4631 }
4632 } else if (num_tcs == 4) {
4633 *rx = tc << 5;
4634 switch (tc) {
4635 case 0:
4636 *tx = 0;
4637 break;
4638 case 1:
4639 *tx = 64;
4640 break;
4641 case 2:
4642 *tx = 96;
4643 break;
4644 case 3:
4645 *tx = 112;
4646 break;
4647 default:
4648 break;
4649 }
4650 }
4651 break;
4652 default:
4653 break;
4654 }
4655}
4656
4657#define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4658
4659/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4660 * classes.
4661 *
4662 * @netdev: net device to configure
4663 * @tc: number of traffic classes to enable
4664 */
4665int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4666{
4667 int i;
4668 unsigned int q, offset = 0;
4669
4670 if (!tc) {
4671 netdev_reset_tc(dev);
4672 } else {
John Fastabend24095aa2011-02-23 05:58:03 +00004673 struct ixgbe_adapter *adapter = netdev_priv(dev);
4674
4675 /* Hardware supports up to 8 traffic classes */
4676 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
John Fastabende5b64632011-03-08 03:44:52 +00004677 return -EINVAL;
4678
4679 /* Partition Tx queues evenly amongst traffic classes */
4680 for (i = 0; i < tc; i++) {
4681 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4682 netdev_set_prio_tc_map(dev, i, i);
4683 netdev_set_tc_queue(dev, i, q, offset);
4684 offset += q;
4685 }
John Fastabend24095aa2011-02-23 05:58:03 +00004686
4687 /* This enables multiple traffic class support in the hardware
4688 * which defaults to strict priority transmission by default.
4689 * If traffic classes are already enabled perhaps through DCB
4690 * code path then existing configuration will be used.
4691 */
4692 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4693 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4694 struct ieee_ets ets = {
4695 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4696 };
4697 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4698
4699 dev->dcbnl_ops->setdcbx(dev, mode);
4700 dev->dcbnl_ops->ieee_setets(dev, &ets);
4701 }
John Fastabende5b64632011-03-08 03:44:52 +00004702 }
4703 return 0;
4704}
4705
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004706/**
4707 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4708 * @adapter: board private structure to initialize
4709 *
4710 * Cache the descriptor ring offsets for DCB to the assigned rings.
4711 *
4712 **/
4713static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4714{
John Fastabende5b64632011-03-08 03:44:52 +00004715 struct net_device *dev = adapter->netdev;
4716 int i, j, k;
4717 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004718
Alexander Duyckbd508172010-11-16 19:27:03 -08004719 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4720 return false;
4721
John Fastabende5b64632011-03-08 03:44:52 +00004722 for (i = 0, k = 0; i < num_tcs; i++) {
4723 unsigned int tx_s, rx_s;
4724 u16 count = dev->tc_to_txq[i].count;
4725
4726 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4727 for (j = 0; j < count; j++, k++) {
4728 adapter->tx_ring[k]->reg_idx = tx_s + j;
4729 adapter->rx_ring[k]->reg_idx = rx_s + j;
4730 adapter->tx_ring[k]->dcb_tc = i;
4731 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004732 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004733 }
John Fastabende5b64632011-03-08 03:44:52 +00004734
4735 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004736}
4737#endif
4738
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004739/**
4740 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4741 * @adapter: board private structure to initialize
4742 *
4743 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4744 *
4745 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004746static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004747{
4748 int i;
4749 bool ret = false;
4750
4751 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4752 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4753 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4754 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004755 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004756 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004757 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004758 ret = true;
4759 }
4760
4761 return ret;
4762}
4763
Yi Zou0331a832009-05-17 12:33:52 +00004764#ifdef IXGBE_FCOE
4765/**
4766 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4767 * @adapter: board private structure to initialize
4768 *
4769 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4770 *
4771 */
4772static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4773{
Yi Zou0331a832009-05-17 12:33:52 +00004774 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004775 int i;
4776 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004777
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004778 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4779 return false;
4780
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004781 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4782 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4783 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4784 ixgbe_cache_ring_fdir(adapter);
4785 else
4786 ixgbe_cache_ring_rss(adapter);
4787
4788 fcoe_rx_i = f->mask;
4789 fcoe_tx_i = f->mask;
4790 }
4791 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4792 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4793 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4794 }
4795 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004796}
4797
4798#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004799/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004800 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4801 * @adapter: board private structure to initialize
4802 *
4803 * SR-IOV doesn't use any descriptor rings but changes the default if
4804 * no other mapping is used.
4805 *
4806 */
4807static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4808{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004809 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4810 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004811 if (adapter->num_vfs)
4812 return true;
4813 else
4814 return false;
4815}
4816
4817/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004818 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4819 * @adapter: board private structure to initialize
4820 *
4821 * Once we know the feature-set enabled for the device, we'll cache
4822 * the register offset the descriptor ring is assigned to.
4823 *
4824 * Note, the order the various feature calls is important. It must start with
4825 * the "most" features enabled at the same time, then trickle down to the
4826 * least amount of features turned on at once.
4827 **/
4828static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4829{
4830 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004831 adapter->rx_ring[0]->reg_idx = 0;
4832 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004833
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004834 if (ixgbe_cache_ring_sriov(adapter))
4835 return;
4836
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004837#ifdef CONFIG_IXGBE_DCB
4838 if (ixgbe_cache_ring_dcb(adapter))
4839 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004840#endif
John Fastabende5b64632011-03-08 03:44:52 +00004841
4842#ifdef IXGBE_FCOE
4843 if (ixgbe_cache_ring_fcoe(adapter))
4844 return;
4845#endif /* IXGBE_FCOE */
4846
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004847 if (ixgbe_cache_ring_fdir(adapter))
4848 return;
4849
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004850 if (ixgbe_cache_ring_rss(adapter))
4851 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004852}
4853
Auke Kok9a799d72007-09-15 14:07:45 -07004854/**
4855 * ixgbe_alloc_queues - Allocate memory for all rings
4856 * @adapter: board private structure to initialize
4857 *
4858 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004859 * number of queues at compile-time. The polling_netdev array is
4860 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004861 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004862static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004863{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004864 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004865
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004866 if (nid < 0 || !node_online(nid))
4867 nid = first_online_node;
4868
4869 for (; tx < adapter->num_tx_queues; tx++) {
4870 struct ixgbe_ring *ring;
4871
4872 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004873 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004874 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004875 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004876 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004877 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004878 ring->queue_index = tx;
4879 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004880 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004881 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004882
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004883 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004884 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004885
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004886 for (; rx < adapter->num_rx_queues; rx++) {
4887 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004888
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004889 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004890 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004891 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004892 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004893 goto err_allocation;
4894 ring->count = adapter->rx_ring_count;
4895 ring->queue_index = rx;
4896 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004897 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004898 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004899
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004900 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004901 }
4902
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004903 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004904
4905 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004906
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004907err_allocation:
4908 while (tx)
4909 kfree(adapter->tx_ring[--tx]);
4910
4911 while (rx)
4912 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004913 return -ENOMEM;
4914}
4915
4916/**
4917 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4918 * @adapter: board private structure to initialize
4919 *
4920 * Attempt to configure the interrupts using the best available
4921 * capabilities of the hardware and the kernel.
4922 **/
Al Virofeea6a52008-11-27 15:34:07 -08004923static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004924{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004925 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004926 int err = 0;
4927 int vector, v_budget;
4928
4929 /*
4930 * It's easy to be greedy for MSI-X vectors, but it really
4931 * doesn't do us much good if we have a lot more vectors
4932 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004933 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004934 */
4935 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004936 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004937
4938 /*
4939 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004940 * hw.mac->max_msix_vectors vectors. With features
4941 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4942 * descriptor queues supported by our device. Thus, we cap it off in
4943 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004944 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004945 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004946
4947 /* A failure in MSI-X entry allocation isn't fatal, but it does
4948 * mean we disable MSI-X capabilities of the adapter. */
4949 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004950 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004951 if (adapter->msix_entries) {
4952 for (vector = 0; vector < v_budget; vector++)
4953 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004954
Alexander Duyck7a921c92009-05-06 10:43:28 +00004955 ixgbe_acquire_msix_vectors(adapter, v_budget);
4956
4957 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4958 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004959 }
David S. Miller26d27842010-05-03 15:18:22 -07004960
Alexander Duyck7a921c92009-05-06 10:43:28 +00004961 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4962 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004963 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4964 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4965 e_err(probe,
4966 "Flow Director is not supported while multiple "
4967 "queues are disabled. Disabling Flow Director\n");
4968 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004969 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4970 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4971 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004972 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4973 ixgbe_disable_sriov(adapter);
4974
Ben Hutchings847f53f2010-09-27 08:28:56 +00004975 err = ixgbe_set_num_queues(adapter);
4976 if (err)
4977 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004978
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004979 err = pci_enable_msi(adapter->pdev);
4980 if (!err) {
4981 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4982 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004983 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4984 "Unable to allocate MSI interrupt, "
4985 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004986 /* reset err */
4987 err = 0;
4988 }
4989
4990out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004991 return err;
4992}
4993
Alexander Duyck7a921c92009-05-06 10:43:28 +00004994/**
4995 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4996 * @adapter: board private structure to initialize
4997 *
4998 * We allocate one q_vector per queue interrupt. If allocation fails we
4999 * return -ENOMEM.
5000 **/
5001static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
5002{
5003 int q_idx, num_q_vectors;
5004 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005005 int (*poll)(struct napi_struct *, int);
5006
5007 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5008 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005009 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005010 } else {
5011 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005012 poll = &ixgbe_poll;
5013 }
5014
5015 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005016 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005017 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005018 if (!q_vector)
5019 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005020 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005021 if (!q_vector)
5022 goto err_out;
5023 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005024 if (q_vector->txr_count && !q_vector->rxr_count)
5025 q_vector->eitr = adapter->tx_eitr_param;
5026 else
5027 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005028 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005029 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005030 adapter->q_vector[q_idx] = q_vector;
5031 }
5032
5033 return 0;
5034
5035err_out:
5036 while (q_idx) {
5037 q_idx--;
5038 q_vector = adapter->q_vector[q_idx];
5039 netif_napi_del(&q_vector->napi);
5040 kfree(q_vector);
5041 adapter->q_vector[q_idx] = NULL;
5042 }
5043 return -ENOMEM;
5044}
5045
5046/**
5047 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5048 * @adapter: board private structure to initialize
5049 *
5050 * This function frees the memory allocated to the q_vectors. In addition if
5051 * NAPI is enabled it will delete any references to the NAPI struct prior
5052 * to freeing the q_vector.
5053 **/
5054static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5055{
5056 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057
Alexander Duyck91281fd2009-06-04 16:00:27 +00005058 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005059 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005060 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005061 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005062
5063 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5064 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005065 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005066 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005067 kfree(q_vector);
5068 }
5069}
5070
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005071static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005072{
5073 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5074 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5075 pci_disable_msix(adapter->pdev);
5076 kfree(adapter->msix_entries);
5077 adapter->msix_entries = NULL;
5078 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5079 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5080 pci_disable_msi(adapter->pdev);
5081 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005082}
5083
5084/**
5085 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5086 * @adapter: board private structure to initialize
5087 *
5088 * We determine which interrupt scheme to use based on...
5089 * - Kernel support (MSI, MSI-X)
5090 * - which can be user-defined (via MODULE_PARAM)
5091 * - Hardware queue count (num_*_queues)
5092 * - defined by miscellaneous hardware support/features (RSS, etc.)
5093 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005094int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005095{
5096 int err;
5097
5098 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005099 err = ixgbe_set_num_queues(adapter);
5100 if (err)
5101 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005102
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005103 err = ixgbe_set_interrupt_capability(adapter);
5104 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005105 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005106 goto err_set_interrupt;
5107 }
5108
Alexander Duyck7a921c92009-05-06 10:43:28 +00005109 err = ixgbe_alloc_q_vectors(adapter);
5110 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005111 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005112 goto err_alloc_q_vectors;
5113 }
5114
5115 err = ixgbe_alloc_queues(adapter);
5116 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005117 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005118 goto err_alloc_queues;
5119 }
5120
Emil Tantilov849c4542010-06-03 16:53:41 +00005121 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005122 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5123 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005124
5125 set_bit(__IXGBE_DOWN, &adapter->state);
5126
5127 return 0;
5128
Alexander Duyck7a921c92009-05-06 10:43:28 +00005129err_alloc_queues:
5130 ixgbe_free_q_vectors(adapter);
5131err_alloc_q_vectors:
5132 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005133err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005134 return err;
5135}
5136
Eric Dumazet1a515022010-11-16 19:26:42 -08005137static void ring_free_rcu(struct rcu_head *head)
5138{
5139 kfree(container_of(head, struct ixgbe_ring, rcu));
5140}
5141
Alexander Duyck7a921c92009-05-06 10:43:28 +00005142/**
5143 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5144 * @adapter: board private structure to clear interrupt scheme on
5145 *
5146 * We go through and clear interrupt specific resources and reset the structure
5147 * to pre-load conditions
5148 **/
5149void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5150{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005151 int i;
5152
5153 for (i = 0; i < adapter->num_tx_queues; i++) {
5154 kfree(adapter->tx_ring[i]);
5155 adapter->tx_ring[i] = NULL;
5156 }
5157 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005158 struct ixgbe_ring *ring = adapter->rx_ring[i];
5159
5160 /* ixgbe_get_stats64() might access this ring, we must wait
5161 * a grace period before freeing it.
5162 */
5163 call_rcu(&ring->rcu, ring_free_rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005164 adapter->rx_ring[i] = NULL;
5165 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005166
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005167 adapter->num_tx_queues = 0;
5168 adapter->num_rx_queues = 0;
5169
Alexander Duyck7a921c92009-05-06 10:43:28 +00005170 ixgbe_free_q_vectors(adapter);
5171 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005172}
5173
5174/**
5175 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5176 * @adapter: board private structure to initialize
5177 *
5178 * ixgbe_sw_init initializes the Adapter private data structure.
5179 * Fields are initialized based on PCI device information and
5180 * OS network device settings (MTU size).
5181 **/
5182static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5183{
5184 struct ixgbe_hw *hw = &adapter->hw;
5185 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005186 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005187 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005188#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005189 int j;
5190 struct tc_configuration *tc;
5191#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005192 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005193
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005194 /* PCI config space info */
5195
5196 hw->vendor_id = pdev->vendor;
5197 hw->device_id = pdev->device;
5198 hw->revision_id = pdev->revision;
5199 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5200 hw->subsystem_device_id = pdev->subsystem_device;
5201
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005202 /* Set capability flags */
5203 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5204 adapter->ring_feature[RING_F_RSS].indices = rss;
5205 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005206 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005207 switch (hw->mac.type) {
5208 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005209 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5210 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005211 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005212 break;
5213 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005214 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005215 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005216 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5217 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005218 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5219 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005220 /* n-tuple support exists, always init our spinlock */
5221 spin_lock_init(&adapter->fdir_perfect_lock);
5222 /* Flow Director hash filters enabled */
5223 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5224 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005225 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005226 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005227 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005228#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005229 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5230 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5231 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005232#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005233 /* Default traffic class to use for FCoE */
5234 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005235 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005236#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005237#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005238 break;
5239 default:
5240 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005241 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005242
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005243#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005244 /* Configure DCB traffic classes */
5245 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5246 tc = &adapter->dcb_cfg.tc_config[j];
5247 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5248 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5249 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5250 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5251 tc->dcb_pfc = pfc_disabled;
5252 }
5253 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5254 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5255 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005256 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005257 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005258 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005259 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005260 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005261
5262#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005263
5264 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005265 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005266 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005267#ifdef CONFIG_DCB
5268 adapter->last_lfc_mode = hw->fc.current_mode;
5269#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005270 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5271 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005272 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5273 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005274 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005275
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005276 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005277 adapter->rx_itr_setting = 1;
5278 adapter->rx_eitr_param = 20000;
5279 adapter->tx_itr_setting = 1;
5280 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005281
5282 /* set defaults for eitr in MegaBytes */
5283 adapter->eitr_low = 10;
5284 adapter->eitr_high = 20;
5285
5286 /* set default ring sizes */
5287 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5288 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5289
Auke Kok9a799d72007-09-15 14:07:45 -07005290 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005291 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005292 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005293 return -EIO;
5294 }
5295
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005296 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005297 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5298
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005299 /* get assigned NUMA node */
5300 adapter->node = dev_to_node(&pdev->dev);
5301
Auke Kok9a799d72007-09-15 14:07:45 -07005302 set_bit(__IXGBE_DOWN, &adapter->state);
5303
5304 return 0;
5305}
5306
5307/**
5308 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005309 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005310 *
5311 * Return 0 on success, negative on failure
5312 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005313int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005314{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005315 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005316 int size;
5317
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005318 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005319 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005320 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005321 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005322 if (!tx_ring->tx_buffer_info)
5323 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005324
5325 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005326 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005327 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005328
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005329 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005330 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005331 if (!tx_ring->desc)
5332 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005333
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005334 tx_ring->next_to_use = 0;
5335 tx_ring->next_to_clean = 0;
5336 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005337 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005338
5339err:
5340 vfree(tx_ring->tx_buffer_info);
5341 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005342 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005343 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005344}
5345
5346/**
Alexander Duyck69888672008-09-11 20:05:39 -07005347 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5348 * @adapter: board private structure
5349 *
5350 * If this function returns with an error, then it's possible one or
5351 * more of the rings is populated (while the rest are not). It is the
5352 * callers duty to clean those orphaned rings.
5353 *
5354 * Return 0 on success, negative on failure
5355 **/
5356static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5357{
5358 int i, err = 0;
5359
5360 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005361 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005362 if (!err)
5363 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005364 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005365 break;
5366 }
5367
5368 return err;
5369}
5370
5371/**
Auke Kok9a799d72007-09-15 14:07:45 -07005372 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005373 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005374 *
5375 * Returns 0 on success, negative on failure
5376 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005377int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005378{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005379 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005380 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005381
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005382 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005383 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005384 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005385 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 if (!rx_ring->rx_buffer_info)
5387 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005388
Auke Kok9a799d72007-09-15 14:07:45 -07005389 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005390 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5391 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005392
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005394 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005395
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005396 if (!rx_ring->desc)
5397 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005398
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005399 rx_ring->next_to_clean = 0;
5400 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005401
5402 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005403err:
5404 vfree(rx_ring->rx_buffer_info);
5405 rx_ring->rx_buffer_info = NULL;
5406 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005407 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005408}
5409
5410/**
Alexander Duyck69888672008-09-11 20:05:39 -07005411 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5412 * @adapter: board private structure
5413 *
5414 * If this function returns with an error, then it's possible one or
5415 * more of the rings is populated (while the rest are not). It is the
5416 * callers duty to clean those orphaned rings.
5417 *
5418 * Return 0 on success, negative on failure
5419 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005420static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5421{
5422 int i, err = 0;
5423
5424 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005425 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005426 if (!err)
5427 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005428 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005429 break;
5430 }
5431
5432 return err;
5433}
5434
5435/**
Auke Kok9a799d72007-09-15 14:07:45 -07005436 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005437 * @tx_ring: Tx descriptor ring for a specific queue
5438 *
5439 * Free all transmit software resources
5440 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005441void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005442{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005443 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005444
5445 vfree(tx_ring->tx_buffer_info);
5446 tx_ring->tx_buffer_info = NULL;
5447
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005448 /* if not set, then don't free */
5449 if (!tx_ring->desc)
5450 return;
5451
5452 dma_free_coherent(tx_ring->dev, tx_ring->size,
5453 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005454
5455 tx_ring->desc = NULL;
5456}
5457
5458/**
5459 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5460 * @adapter: board private structure
5461 *
5462 * Free all transmit software resources
5463 **/
5464static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5465{
5466 int i;
5467
5468 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005469 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005470 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005471}
5472
5473/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005474 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005475 * @rx_ring: ring to clean the resources from
5476 *
5477 * Free all receive software resources
5478 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005479void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005480{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005481 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005482
5483 vfree(rx_ring->rx_buffer_info);
5484 rx_ring->rx_buffer_info = NULL;
5485
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005486 /* if not set, then don't free */
5487 if (!rx_ring->desc)
5488 return;
5489
5490 dma_free_coherent(rx_ring->dev, rx_ring->size,
5491 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005492
5493 rx_ring->desc = NULL;
5494}
5495
5496/**
5497 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5498 * @adapter: board private structure
5499 *
5500 * Free all receive software resources
5501 **/
5502static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5503{
5504 int i;
5505
5506 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005507 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005508 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005509}
5510
5511/**
Auke Kok9a799d72007-09-15 14:07:45 -07005512 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5513 * @netdev: network interface device structure
5514 * @new_mtu: new value for maximum frame size
5515 *
5516 * Returns 0 on success, negative on failure
5517 **/
5518static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5519{
5520 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005521 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005522 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5523
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005524 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005525 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5526 hw->mac.type != ixgbe_mac_X540) {
5527 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5528 return -EINVAL;
5529 } else {
5530 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5531 return -EINVAL;
5532 }
Auke Kok9a799d72007-09-15 14:07:45 -07005533
Emil Tantilov396e7992010-07-01 20:05:12 +00005534 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005535 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005536 netdev->mtu = new_mtu;
5537
John Fastabend16b61be2010-11-16 19:26:44 -08005538 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5539 hw->fc.low_water = FC_LOW_WATER(max_frame);
5540
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005541 if (netif_running(netdev))
5542 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005543
5544 return 0;
5545}
5546
5547/**
5548 * ixgbe_open - Called when a network interface is made active
5549 * @netdev: network interface device structure
5550 *
5551 * Returns 0 on success, negative value on failure
5552 *
5553 * The open entry point is called when a network interface is made
5554 * active by the system (IFF_UP). At this point all resources needed
5555 * for transmit and receive operations are allocated, the interrupt
5556 * handler is registered with the OS, the watchdog timer is started,
5557 * and the stack is notified that the interface is ready.
5558 **/
5559static int ixgbe_open(struct net_device *netdev)
5560{
5561 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5562 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005563
Auke Kok4bebfaa2008-02-11 09:26:01 -08005564 /* disallow open during test */
5565 if (test_bit(__IXGBE_TESTING, &adapter->state))
5566 return -EBUSY;
5567
Jesse Brandeburg54386462009-04-17 20:44:27 +00005568 netif_carrier_off(netdev);
5569
Auke Kok9a799d72007-09-15 14:07:45 -07005570 /* allocate transmit descriptors */
5571 err = ixgbe_setup_all_tx_resources(adapter);
5572 if (err)
5573 goto err_setup_tx;
5574
Auke Kok9a799d72007-09-15 14:07:45 -07005575 /* allocate receive descriptors */
5576 err = ixgbe_setup_all_rx_resources(adapter);
5577 if (err)
5578 goto err_setup_rx;
5579
5580 ixgbe_configure(adapter);
5581
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005582 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005583 if (err)
5584 goto err_req_irq;
5585
Auke Kok9a799d72007-09-15 14:07:45 -07005586 err = ixgbe_up_complete(adapter);
5587 if (err)
5588 goto err_up;
5589
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005590 netif_tx_start_all_queues(netdev);
5591
Auke Kok9a799d72007-09-15 14:07:45 -07005592 return 0;
5593
5594err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005595 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005596 ixgbe_free_irq(adapter);
5597err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005598err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005599 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005600err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005601 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005602 ixgbe_reset(adapter);
5603
5604 return err;
5605}
5606
5607/**
5608 * ixgbe_close - Disables a network interface
5609 * @netdev: network interface device structure
5610 *
5611 * Returns 0, this is not allowed to fail
5612 *
5613 * The close entry point is called when an interface is de-activated
5614 * by the OS. The hardware is still under the drivers control, but
5615 * needs to be disabled. A global MAC reset is issued to stop the
5616 * hardware, and all transmit and receive resources are freed.
5617 **/
5618static int ixgbe_close(struct net_device *netdev)
5619{
5620 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005621
5622 ixgbe_down(adapter);
5623 ixgbe_free_irq(adapter);
5624
5625 ixgbe_free_all_tx_resources(adapter);
5626 ixgbe_free_all_rx_resources(adapter);
5627
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005628 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005629
5630 return 0;
5631}
5632
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005633#ifdef CONFIG_PM
5634static int ixgbe_resume(struct pci_dev *pdev)
5635{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005636 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5637 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005638 u32 err;
5639
5640 pci_set_power_state(pdev, PCI_D0);
5641 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005642 /*
5643 * pci_restore_state clears dev->state_saved so call
5644 * pci_save_state to restore it.
5645 */
5646 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005647
5648 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005649 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005650 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005651 return err;
5652 }
5653 pci_set_master(pdev);
5654
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005655 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005656
5657 err = ixgbe_init_interrupt_scheme(adapter);
5658 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005659 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005660 return err;
5661 }
5662
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005663 ixgbe_reset(adapter);
5664
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005665 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5666
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005667 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005668 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005669 if (err)
5670 return err;
5671 }
5672
5673 netif_device_attach(netdev);
5674
5675 return 0;
5676}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005677#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005678
5679static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005680{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005681 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5682 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005683 struct ixgbe_hw *hw = &adapter->hw;
5684 u32 ctrl, fctrl;
5685 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005686#ifdef CONFIG_PM
5687 int retval = 0;
5688#endif
5689
5690 netif_device_detach(netdev);
5691
5692 if (netif_running(netdev)) {
5693 ixgbe_down(adapter);
5694 ixgbe_free_irq(adapter);
5695 ixgbe_free_all_tx_resources(adapter);
5696 ixgbe_free_all_rx_resources(adapter);
5697 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005698
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005699 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005700#ifdef CONFIG_DCB
5701 kfree(adapter->ixgbe_ieee_pfc);
5702 kfree(adapter->ixgbe_ieee_ets);
5703#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005704
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005705#ifdef CONFIG_PM
5706 retval = pci_save_state(pdev);
5707 if (retval)
5708 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005709
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005710#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005711 if (wufc) {
5712 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005713
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005714 /* turn on all-multi mode if wake on multicast is enabled */
5715 if (wufc & IXGBE_WUFC_MC) {
5716 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5717 fctrl |= IXGBE_FCTRL_MPE;
5718 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5719 }
5720
5721 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5722 ctrl |= IXGBE_CTRL_GIO_DIS;
5723 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5724
5725 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5726 } else {
5727 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5728 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5729 }
5730
Alexander Duyckbd508172010-11-16 19:27:03 -08005731 switch (hw->mac.type) {
5732 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005733 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005734 break;
5735 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005736 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005737 pci_wake_from_d3(pdev, !!wufc);
5738 break;
5739 default:
5740 break;
5741 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005742
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005743 *enable_wake = !!wufc;
5744
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005745 ixgbe_release_hw_control(adapter);
5746
5747 pci_disable_device(pdev);
5748
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005749 return 0;
5750}
5751
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005752#ifdef CONFIG_PM
5753static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5754{
5755 int retval;
5756 bool wake;
5757
5758 retval = __ixgbe_shutdown(pdev, &wake);
5759 if (retval)
5760 return retval;
5761
5762 if (wake) {
5763 pci_prepare_to_sleep(pdev);
5764 } else {
5765 pci_wake_from_d3(pdev, false);
5766 pci_set_power_state(pdev, PCI_D3hot);
5767 }
5768
5769 return 0;
5770}
5771#endif /* CONFIG_PM */
5772
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005773static void ixgbe_shutdown(struct pci_dev *pdev)
5774{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005775 bool wake;
5776
5777 __ixgbe_shutdown(pdev, &wake);
5778
5779 if (system_state == SYSTEM_POWER_OFF) {
5780 pci_wake_from_d3(pdev, wake);
5781 pci_set_power_state(pdev, PCI_D3hot);
5782 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005783}
5784
5785/**
Auke Kok9a799d72007-09-15 14:07:45 -07005786 * ixgbe_update_stats - Update the board statistics counters.
5787 * @adapter: board private structure
5788 **/
5789void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5790{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005791 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005792 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005793 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005794 u64 total_mpc = 0;
5795 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005796 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5797 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5798 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005799
Don Skidmored08935c2010-06-11 13:20:29 +00005800 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5801 test_bit(__IXGBE_RESETTING, &adapter->state))
5802 return;
5803
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005804 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005805 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005806 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005807 for (i = 0; i < 16; i++)
5808 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005809 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005810 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005811 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5812 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005813 }
5814 adapter->rsc_total_count = rsc_count;
5815 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005816 }
5817
Alexander Duyck5b7da512010-11-16 19:26:50 -08005818 for (i = 0; i < adapter->num_rx_queues; i++) {
5819 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5820 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5821 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5822 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5823 bytes += rx_ring->stats.bytes;
5824 packets += rx_ring->stats.packets;
5825 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005826 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005827 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5828 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5829 netdev->stats.rx_bytes = bytes;
5830 netdev->stats.rx_packets = packets;
5831
5832 bytes = 0;
5833 packets = 0;
5834 /* gather some stats to the adapter struct that are per queue */
5835 for (i = 0; i < adapter->num_tx_queues; i++) {
5836 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5837 restart_queue += tx_ring->tx_stats.restart_queue;
5838 tx_busy += tx_ring->tx_stats.tx_busy;
5839 bytes += tx_ring->stats.bytes;
5840 packets += tx_ring->stats.packets;
5841 }
5842 adapter->restart_queue = restart_queue;
5843 adapter->tx_busy = tx_busy;
5844 netdev->stats.tx_bytes = bytes;
5845 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005846
Joe Perches7ca647b2010-09-07 21:35:40 +00005847 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005848 for (i = 0; i < 8; i++) {
5849 /* for packet buffers not used, the register should read 0 */
5850 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5851 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005852 hwstats->mpc[i] += mpc;
5853 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005854 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005855 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5856 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5857 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5858 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5859 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005860 switch (hw->mac.type) {
5861 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005862 hwstats->pxonrxc[i] +=
5863 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005864 break;
5865 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005866 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005867 hwstats->pxonrxc[i] +=
5868 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005869 break;
5870 default:
5871 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005872 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005873 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5874 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005875 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005876 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005877 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005878 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005879
John Fastabendc84d3242010-11-16 19:27:12 -08005880 ixgbe_update_xoff_received(adapter);
5881
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005882 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005883 switch (hw->mac.type) {
5884 case ixgbe_mac_82598EB:
5885 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005886 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5887 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5888 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5889 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005890 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005891 /* OS2BMC stats are X540 only*/
5892 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5893 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5894 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5895 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5896 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005897 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005898 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005899 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005900 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005902 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005904 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5905 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005906#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005907 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5908 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5909 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5910 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5911 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5912 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005913#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005914 break;
5915 default:
5916 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005917 }
Auke Kok9a799d72007-09-15 14:07:45 -07005918 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005919 hwstats->bprc += bprc;
5920 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005921 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005922 hwstats->mprc -= bprc;
5923 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5924 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5925 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5926 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5927 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5928 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5929 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5930 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005931 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005932 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005933 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005934 hwstats->lxofftxc += lxoff;
5935 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5936 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5937 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005938 /*
5939 * 82598 errata - tx of flow control packets is included in tx counters
5940 */
5941 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005942 hwstats->gptc -= xon_off_tot;
5943 hwstats->mptc -= xon_off_tot;
5944 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5945 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5946 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5947 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5948 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5949 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5950 hwstats->ptc64 -= xon_off_tot;
5951 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5952 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5953 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5954 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5955 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5956 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005957
5958 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005959 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005960
5961 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005962 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005963 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005964 netdev->stats.rx_length_errors = hwstats->rlec;
5965 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005966 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005967}
5968
5969/**
Alexander Duyckd034acf2011-04-27 09:25:34 +00005970 * ixgbe_fdir_reinit_subtask - worker thread to reinit FDIR filter table
5971 * @adapter - pointer to the device adapter structure
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005972 **/
Alexander Duyckd034acf2011-04-27 09:25:34 +00005973static void ixgbe_fdir_reinit_subtask(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005974{
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005975 struct ixgbe_hw *hw = &adapter->hw;
5976 int i;
5977
Alexander Duyckd034acf2011-04-27 09:25:34 +00005978 if (!(adapter->flags2 & IXGBE_FLAG2_FDIR_REQUIRES_REINIT))
5979 return;
5980
5981 adapter->flags2 &= ~IXGBE_FLAG2_FDIR_REQUIRES_REINIT;
5982
5983 /* if interface is down do nothing */
5984 if (test_bit(__IXGBE_DOWN, &adapter->state))
5985 return;
5986
5987 /* do nothing if we are not using signature filters */
5988 if (!(adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE))
5989 return;
5990
5991 adapter->fdir_overflow++;
5992
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005993 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
5994 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08005995 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
Alexander Duyckf0f97782011-04-22 04:08:09 +00005996 &(adapter->tx_ring[i]->state));
Alexander Duyckd034acf2011-04-27 09:25:34 +00005997 /* re-enable flow director interrupts */
5998 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_FLOW_DIR);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005999 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006000 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006001 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006002 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006003}
6004
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006005/**
6006 * ixgbe_check_hang_subtask - check for hung queues and dropped interrupts
6007 * @adapter - pointer to the device adapter structure
6008 *
6009 * This function serves two purposes. First it strobes the interrupt lines
6010 * in order to make certain interrupts are occuring. Secondly it sets the
6011 * bits needed to check for TX hangs. As a result we should immediately
6012 * determine if a hang has occured.
6013 */
6014static void ixgbe_check_hang_subtask(struct ixgbe_adapter *adapter)
6015{
6016 struct ixgbe_hw *hw = &adapter->hw;
6017 u64 eics = 0;
6018 int i;
6019
6020 /* If we're down or resetting, just bail */
6021 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6022 test_bit(__IXGBE_RESETTING, &adapter->state))
6023 return;
6024
6025 /* Force detection of hung controller */
6026 if (netif_carrier_ok(adapter->netdev)) {
6027 for (i = 0; i < adapter->num_tx_queues; i++)
6028 set_check_for_tx_hang(adapter->tx_ring[i]);
6029 }
6030
6031 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6032 /*
6033 * for legacy and MSI interrupts don't set any bits
6034 * that are enabled for EIAM, because this operation
6035 * would set *both* EIMS and EICS for any bit in EIAM
6036 */
6037 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6038 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6039 } else {
6040 /* get one bit for every active tx/rx interrupt vector */
6041 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6042 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6043 if (qv->rxr_count || qv->txr_count)
6044 eics |= ((u64)1 << i);
6045 }
6046 }
6047
6048 /* Cause software interrupt to ensure rings are cleaned */
6049 ixgbe_irq_rearm_queues(adapter, eics);
6050
6051}
6052
6053/**
6054 * ixgbe_watchdog_update_link - update the link status
6055 * @adapter - pointer to the device adapter structure
6056 * @link_speed - pointer to a u32 to store the link_speed
6057 **/
6058static void ixgbe_watchdog_update_link(struct ixgbe_adapter *adapter)
6059{
6060 struct ixgbe_hw *hw = &adapter->hw;
6061 u32 link_speed = adapter->link_speed;
6062 bool link_up = adapter->link_up;
6063 int i;
6064
6065 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE))
6066 return;
6067
6068 if (hw->mac.ops.check_link) {
6069 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
6070 } else {
6071 /* always assume link is up, if no check link function */
6072 link_speed = IXGBE_LINK_SPEED_10GB_FULL;
6073 link_up = true;
6074 }
6075 if (link_up) {
6076 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6077 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
6078 hw->mac.ops.fc_enable(hw, i);
6079 } else {
6080 hw->mac.ops.fc_enable(hw, 0);
6081 }
6082 }
6083
6084 if (link_up ||
6085 time_after(jiffies, (adapter->link_check_timeout +
6086 IXGBE_TRY_LINK_TIMEOUT))) {
6087 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
6088 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
6089 IXGBE_WRITE_FLUSH(hw);
6090 }
6091
6092 adapter->link_up = link_up;
6093 adapter->link_speed = link_speed;
6094}
6095
6096/**
6097 * ixgbe_watchdog_link_is_up - update netif_carrier status and
6098 * print link up message
6099 * @adapter - pointer to the device adapter structure
6100 **/
6101static void ixgbe_watchdog_link_is_up(struct ixgbe_adapter *adapter)
6102{
6103 struct net_device *netdev = adapter->netdev;
6104 struct ixgbe_hw *hw = &adapter->hw;
6105 u32 link_speed = adapter->link_speed;
6106 bool flow_rx, flow_tx;
6107
6108 /* only continue if link was previously down */
6109 if (netif_carrier_ok(netdev))
6110 return;
6111
6112 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
6113
6114 switch (hw->mac.type) {
6115 case ixgbe_mac_82598EB: {
6116 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6117 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
6118 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6119 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
6120 }
6121 break;
6122 case ixgbe_mac_X540:
6123 case ixgbe_mac_82599EB: {
6124 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6125 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6126 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6127 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6128 }
6129 break;
6130 default:
6131 flow_tx = false;
6132 flow_rx = false;
6133 break;
6134 }
6135 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
6136 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
6137 "10 Gbps" :
6138 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
6139 "1 Gbps" :
6140 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6141 "100 Mbps" :
6142 "unknown speed"))),
6143 ((flow_rx && flow_tx) ? "RX/TX" :
6144 (flow_rx ? "RX" :
6145 (flow_tx ? "TX" : "None"))));
6146
6147 netif_carrier_on(netdev);
6148#ifdef HAVE_IPLINK_VF_CONFIG
6149 ixgbe_check_vf_rate_limit(adapter);
6150#endif /* HAVE_IPLINK_VF_CONFIG */
6151}
6152
6153/**
6154 * ixgbe_watchdog_link_is_down - update netif_carrier status and
6155 * print link down message
6156 * @adapter - pointer to the adapter structure
6157 **/
6158static void ixgbe_watchdog_link_is_down(struct ixgbe_adapter* adapter)
6159{
6160 struct net_device *netdev = adapter->netdev;
6161 struct ixgbe_hw *hw = &adapter->hw;
6162
6163 adapter->link_up = false;
6164 adapter->link_speed = 0;
6165
6166 /* only continue if link was up previously */
6167 if (!netif_carrier_ok(netdev))
6168 return;
6169
6170 /* poll for SFP+ cable when link is down */
6171 if (ixgbe_is_sfp(hw) && hw->mac.type == ixgbe_mac_82598EB)
6172 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
6173
6174 e_info(drv, "NIC Link is Down\n");
6175 netif_carrier_off(netdev);
6176}
6177
6178/**
6179 * ixgbe_watchdog_flush_tx - flush queues on link down
6180 * @adapter - pointer to the device adapter structure
6181 **/
6182static void ixgbe_watchdog_flush_tx(struct ixgbe_adapter *adapter)
6183{
6184 int i;
6185 int some_tx_pending = 0;
6186
6187 if (!netif_carrier_ok(adapter->netdev)) {
6188 for (i = 0; i < adapter->num_tx_queues; i++) {
6189 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
6190 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6191 some_tx_pending = 1;
6192 break;
6193 }
6194 }
6195
6196 if (some_tx_pending) {
6197 /* We've lost link, so the controller stops DMA,
6198 * but we've got queued Tx work that's never going
6199 * to get done, so reset controller to flush Tx.
6200 * (Do the reset outside of interrupt context).
6201 */
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006202 adapter->flags2 |= IXGBE_FLAG2_RESET_REQUESTED;
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006203 }
6204 }
6205}
6206
Greg Rosea985b6c32010-11-18 03:02:52 +00006207static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6208{
6209 u32 ssvpc;
6210
6211 /* Do not perform spoof check for 82598 */
6212 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6213 return;
6214
6215 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6216
6217 /*
6218 * ssvpc register is cleared on read, if zero then no
6219 * spoofed packets in the last interval.
6220 */
6221 if (!ssvpc)
6222 return;
6223
6224 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6225}
6226
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006227/**
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006228 * ixgbe_watchdog_subtask - check and bring link up
6229 * @adapter - pointer to the device adapter structure
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006230 **/
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006231static void ixgbe_watchdog_subtask(struct ixgbe_adapter *adapter)
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006232{
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006233 /* if interface is down do nothing */
6234 if (test_bit(__IXGBE_DOWN, &adapter->state))
6235 return;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006236
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006237 ixgbe_watchdog_update_link(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006238
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006239 if (adapter->link_up)
6240 ixgbe_watchdog_link_is_up(adapter);
6241 else
6242 ixgbe_watchdog_link_is_down(adapter);
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006243
Greg Rosea985b6c32010-11-18 03:02:52 +00006244 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006245 ixgbe_update_stats(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006246
6247 ixgbe_watchdog_flush_tx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006248}
6249
Alexander Duyck70864002011-04-27 09:13:56 +00006250/**
6251 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6252 * @adapter - the ixgbe adapter structure
6253 **/
6254static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6255{
6256 struct ixgbe_hw *hw = &adapter->hw;
6257 s32 err;
6258
6259 /* not searching for SFP so there is nothing to do here */
6260 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6261 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6262 return;
6263
6264 /* someone else is in init, wait until next service event */
6265 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6266 return;
6267
6268 err = hw->phy.ops.identify_sfp(hw);
6269 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6270 goto sfp_out;
6271
6272 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6273 /* If no cable is present, then we need to reset
6274 * the next time we find a good cable. */
6275 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6276 }
6277
6278 /* exit on error */
6279 if (err)
6280 goto sfp_out;
6281
6282 /* exit if reset not needed */
6283 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6284 goto sfp_out;
6285
6286 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6287
6288 /*
6289 * A module may be identified correctly, but the EEPROM may not have
6290 * support for that module. setup_sfp() will fail in that case, so
6291 * we should not allow that module to load.
6292 */
6293 if (hw->mac.type == ixgbe_mac_82598EB)
6294 err = hw->phy.ops.reset(hw);
6295 else
6296 err = hw->mac.ops.setup_sfp(hw);
6297
6298 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6299 goto sfp_out;
6300
6301 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6302 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6303
6304sfp_out:
6305 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6306
6307 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6308 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6309 e_dev_err("failed to initialize because an unsupported "
6310 "SFP+ module type was detected.\n");
6311 e_dev_err("Reload the driver after installing a "
6312 "supported module.\n");
6313 unregister_netdev(adapter->netdev);
6314 }
6315}
6316
6317/**
6318 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6319 * @adapter - the ixgbe adapter structure
6320 **/
6321static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6322{
6323 struct ixgbe_hw *hw = &adapter->hw;
6324 u32 autoneg;
6325 bool negotiation;
6326
6327 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6328 return;
6329
6330 /* someone else is in init, wait until next service event */
6331 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6332 return;
6333
6334 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6335
6336 autoneg = hw->phy.autoneg_advertised;
6337 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6338 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6339 hw->mac.autotry_restart = false;
6340 if (hw->mac.ops.setup_link)
6341 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6342
6343 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6344 adapter->link_check_timeout = jiffies;
6345 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6346}
6347
6348/**
6349 * ixgbe_service_timer - Timer Call-back
6350 * @data: pointer to adapter cast into an unsigned long
6351 **/
6352static void ixgbe_service_timer(unsigned long data)
6353{
6354 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6355 unsigned long next_event_offset;
6356
6357 /* poll faster when waiting for link */
6358 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6359 next_event_offset = HZ / 10;
6360 else
6361 next_event_offset = HZ * 2;
6362
6363 /* Reset the timer */
6364 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6365
6366 ixgbe_service_event_schedule(adapter);
6367}
6368
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006369static void ixgbe_reset_subtask(struct ixgbe_adapter *adapter)
6370{
6371 if (!(adapter->flags2 & IXGBE_FLAG2_RESET_REQUESTED))
6372 return;
6373
6374 adapter->flags2 &= ~IXGBE_FLAG2_RESET_REQUESTED;
6375
6376 /* If we're already down or resetting, just bail */
6377 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
6378 test_bit(__IXGBE_RESETTING, &adapter->state))
6379 return;
6380
6381 ixgbe_dump(adapter);
6382 netdev_err(adapter->netdev, "Reset adapter\n");
6383 adapter->tx_timeout_count++;
6384
6385 ixgbe_reinit_locked(adapter);
6386}
6387
Alexander Duyck70864002011-04-27 09:13:56 +00006388/**
6389 * ixgbe_service_task - manages and runs subtasks
6390 * @work: pointer to work_struct containing our data
6391 **/
6392static void ixgbe_service_task(struct work_struct *work)
6393{
6394 struct ixgbe_adapter *adapter = container_of(work,
6395 struct ixgbe_adapter,
6396 service_task);
6397
Alexander Duyckc83c6cb2011-04-27 09:21:16 +00006398 ixgbe_reset_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006399 ixgbe_sfp_detection_subtask(adapter);
6400 ixgbe_sfp_link_config_subtask(adapter);
Alexander Duyckf0f97782011-04-22 04:08:09 +00006401 ixgbe_check_overtemp_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006402 ixgbe_watchdog_subtask(adapter);
Alexander Duyckd034acf2011-04-27 09:25:34 +00006403 ixgbe_fdir_reinit_subtask(adapter);
Alexander Duyck93c52dd2011-04-22 04:07:54 +00006404 ixgbe_check_hang_subtask(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00006405
6406 ixgbe_service_event_complete(adapter);
6407}
6408
Auke Kok9a799d72007-09-15 14:07:45 -07006409static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006410 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006411 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006412{
6413 struct ixgbe_adv_tx_context_desc *context_desc;
6414 unsigned int i;
6415 int err;
6416 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006417 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6418 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006419
6420 if (skb_is_gso(skb)) {
6421 if (skb_header_cloned(skb)) {
6422 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6423 if (err)
6424 return err;
6425 }
6426 l4len = tcp_hdrlen(skb);
6427 *hdr_len += l4len;
6428
Hao Zheng5e09a102010-11-11 13:47:59 +00006429 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006430 struct iphdr *iph = ip_hdr(skb);
6431 iph->tot_len = 0;
6432 iph->check = 0;
6433 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006434 iph->daddr, 0,
6435 IPPROTO_TCP,
6436 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006437 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006438 ipv6_hdr(skb)->payload_len = 0;
6439 tcp_hdr(skb)->check =
6440 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006441 &ipv6_hdr(skb)->daddr,
6442 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006443 }
6444
6445 i = tx_ring->next_to_use;
6446
6447 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006448 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006449
6450 /* VLAN MACLEN IPLEN */
6451 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6452 vlan_macip_lens |=
6453 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6454 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006455 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006456 *hdr_len += skb_network_offset(skb);
6457 vlan_macip_lens |=
6458 (skb_transport_header(skb) - skb_network_header(skb));
6459 *hdr_len +=
6460 (skb_transport_header(skb) - skb_network_header(skb));
6461 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6462 context_desc->seqnum_seed = 0;
6463
6464 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006465 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006466 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006467
Hao Zheng5e09a102010-11-11 13:47:59 +00006468 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006469 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6470 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6471 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6472
6473 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006474 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006475 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6476 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006477 /* use index 1 for TSO */
6478 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006479 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6480
6481 tx_buffer_info->time_stamp = jiffies;
6482 tx_buffer_info->next_to_watch = i;
6483
6484 i++;
6485 if (i == tx_ring->count)
6486 i = 0;
6487 tx_ring->next_to_use = i;
6488
6489 return true;
6490 }
6491 return false;
6492}
6493
Hao Zheng5e09a102010-11-11 13:47:59 +00006494static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6495 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006496{
6497 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006498
6499 switch (protocol) {
6500 case cpu_to_be16(ETH_P_IP):
6501 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6502 switch (ip_hdr(skb)->protocol) {
6503 case IPPROTO_TCP:
6504 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6505 break;
6506 case IPPROTO_SCTP:
6507 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6508 break;
6509 }
6510 break;
6511 case cpu_to_be16(ETH_P_IPV6):
6512 /* XXX what about other V6 headers?? */
6513 switch (ipv6_hdr(skb)->nexthdr) {
6514 case IPPROTO_TCP:
6515 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6516 break;
6517 case IPPROTO_SCTP:
6518 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6519 break;
6520 }
6521 break;
6522 default:
6523 if (unlikely(net_ratelimit()))
6524 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006525 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006526 break;
6527 }
6528
6529 return rtn;
6530}
6531
Auke Kok9a799d72007-09-15 14:07:45 -07006532static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006533 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006534 struct sk_buff *skb, u32 tx_flags,
6535 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006536{
6537 struct ixgbe_adv_tx_context_desc *context_desc;
6538 unsigned int i;
6539 struct ixgbe_tx_buffer *tx_buffer_info;
6540 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6541
6542 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6543 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6544 i = tx_ring->next_to_use;
6545 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006546 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006547
6548 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6549 vlan_macip_lens |=
6550 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6551 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006552 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006553 if (skb->ip_summed == CHECKSUM_PARTIAL)
6554 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006555 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006556
6557 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6558 context_desc->seqnum_seed = 0;
6559
6560 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006561 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006562
Joe Perches7ca647b2010-09-07 21:35:40 +00006563 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006564 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006565
6566 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006567 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006568 context_desc->mss_l4len_idx = 0;
6569
6570 tx_buffer_info->time_stamp = jiffies;
6571 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006572
Auke Kok9a799d72007-09-15 14:07:45 -07006573 i++;
6574 if (i == tx_ring->count)
6575 i = 0;
6576 tx_ring->next_to_use = i;
6577
6578 return true;
6579 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006580
Auke Kok9a799d72007-09-15 14:07:45 -07006581 return false;
6582}
6583
6584static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006585 struct ixgbe_ring *tx_ring,
6586 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006587 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006588{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006589 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006590 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006591 unsigned int len;
6592 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006593 unsigned int offset = 0, size, count = 0, i;
6594 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6595 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006596 unsigned int bytecount = skb->len;
6597 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006598
6599 i = tx_ring->next_to_use;
6600
Yi Zoueacd73f2009-05-13 13:11:06 +00006601 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6602 /* excluding fcoe_crc_eof for FCoE */
6603 total -= sizeof(struct fcoe_crc_eof);
6604
6605 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006606 while (len) {
6607 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6608 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6609
6610 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006611 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006612 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006613 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006614 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006615 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006616 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006617 tx_buffer_info->time_stamp = jiffies;
6618 tx_buffer_info->next_to_watch = i;
6619
6620 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006621 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006622 offset += size;
6623 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006624
6625 if (len) {
6626 i++;
6627 if (i == tx_ring->count)
6628 i = 0;
6629 }
Auke Kok9a799d72007-09-15 14:07:45 -07006630 }
6631
6632 for (f = 0; f < nr_frags; f++) {
6633 struct skb_frag_struct *frag;
6634
6635 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006636 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006637 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006638
6639 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006640 i++;
6641 if (i == tx_ring->count)
6642 i = 0;
6643
Auke Kok9a799d72007-09-15 14:07:45 -07006644 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6645 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6646
6647 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006648 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006649 frag->page,
6650 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006651 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006652 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006653 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006654 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006655 tx_buffer_info->time_stamp = jiffies;
6656 tx_buffer_info->next_to_watch = i;
6657
6658 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006659 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006660 offset += size;
6661 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006662 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006663 if (total == 0)
6664 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006665 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006666
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006667 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6668 gso_segs = skb_shinfo(skb)->gso_segs;
6669#ifdef IXGBE_FCOE
6670 /* adjust for FCoE Sequence Offload */
6671 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6672 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6673 skb_shinfo(skb)->gso_size);
6674#endif /* IXGBE_FCOE */
6675 bytecount += (gso_segs - 1) * hdr_len;
6676
6677 /* multiply data chunks by size of headers */
6678 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6679 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006680 tx_ring->tx_buffer_info[i].skb = skb;
6681 tx_ring->tx_buffer_info[first].next_to_watch = i;
6682
6683 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006684
6685dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006686 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006687
6688 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6689 tx_buffer_info->dma = 0;
6690 tx_buffer_info->time_stamp = 0;
6691 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006692 if (count)
6693 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006694
6695 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006696 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006697 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006698 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006699 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006700 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006701 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006702 }
6703
Anton Blancharde44d38e2010-02-03 13:12:51 +00006704 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006705}
6706
Alexander Duyck84ea2592010-11-16 19:26:49 -08006707static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006708 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006709{
6710 union ixgbe_adv_tx_desc *tx_desc = NULL;
6711 struct ixgbe_tx_buffer *tx_buffer_info;
6712 u32 olinfo_status = 0, cmd_type_len = 0;
6713 unsigned int i;
6714 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6715
6716 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6717
6718 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6719
6720 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6721 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6722
6723 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6724 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6725
6726 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006727 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006728
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006729 /* use index 1 context for tso */
6730 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006731 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6732 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006733 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006734
6735 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6736 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006737 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006738
Yi Zoueacd73f2009-05-13 13:11:06 +00006739 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6740 olinfo_status |= IXGBE_ADVTXD_CC;
6741 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6742 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6743 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6744 }
6745
Auke Kok9a799d72007-09-15 14:07:45 -07006746 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6747
6748 i = tx_ring->next_to_use;
6749 while (count--) {
6750 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006751 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006752 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6753 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006754 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006755 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006756 i++;
6757 if (i == tx_ring->count)
6758 i = 0;
6759 }
6760
6761 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6762
6763 /*
6764 * Force memory writes to complete before letting h/w
6765 * know there are new descriptors to fetch. (Only
6766 * applicable for weak-ordered memory model archs,
6767 * such as IA-64).
6768 */
6769 wmb();
6770
6771 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006772 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006773}
6774
Alexander Duyck69830522011-01-06 14:29:58 +00006775static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6776 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006777{
Alexander Duyck69830522011-01-06 14:29:58 +00006778 struct ixgbe_q_vector *q_vector = ring->q_vector;
6779 union ixgbe_atr_hash_dword input = { .dword = 0 };
6780 union ixgbe_atr_hash_dword common = { .dword = 0 };
6781 union {
6782 unsigned char *network;
6783 struct iphdr *ipv4;
6784 struct ipv6hdr *ipv6;
6785 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006786 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006787 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006788
Alexander Duyck69830522011-01-06 14:29:58 +00006789 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6790 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006791 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006792
Alexander Duyck69830522011-01-06 14:29:58 +00006793 /* do nothing if sampling is disabled */
6794 if (!ring->atr_sample_rate)
6795 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006796
Alexander Duyck69830522011-01-06 14:29:58 +00006797 ring->atr_count++;
6798
6799 /* snag network header to get L4 type and address */
6800 hdr.network = skb_network_header(skb);
6801
6802 /* Currently only IPv4/IPv6 with TCP is supported */
6803 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6804 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6805 (protocol != __constant_htons(ETH_P_IP) ||
6806 hdr.ipv4->protocol != IPPROTO_TCP))
6807 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006808
6809 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006810
Alexander Duyck69830522011-01-06 14:29:58 +00006811 /* skip this packet since the socket is closing */
6812 if (th->fin)
6813 return;
6814
6815 /* sample on all syn packets or once every atr sample count */
6816 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6817 return;
6818
6819 /* reset sample count */
6820 ring->atr_count = 0;
6821
6822 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6823
6824 /*
6825 * src and dst are inverted, think how the receiver sees them
6826 *
6827 * The input is broken into two sections, a non-compressed section
6828 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6829 * is XORed together and stored in the compressed dword.
6830 */
6831 input.formatted.vlan_id = vlan_id;
6832
6833 /*
6834 * since src port and flex bytes occupy the same word XOR them together
6835 * and write the value to source port portion of compressed dword
6836 */
6837 if (vlan_id)
6838 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6839 else
6840 common.port.src ^= th->dest ^ protocol;
6841 common.port.dst ^= th->source;
6842
6843 if (protocol == __constant_htons(ETH_P_IP)) {
6844 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6845 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6846 } else {
6847 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6848 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6849 hdr.ipv6->saddr.s6_addr32[1] ^
6850 hdr.ipv6->saddr.s6_addr32[2] ^
6851 hdr.ipv6->saddr.s6_addr32[3] ^
6852 hdr.ipv6->daddr.s6_addr32[0] ^
6853 hdr.ipv6->daddr.s6_addr32[1] ^
6854 hdr.ipv6->daddr.s6_addr32[2] ^
6855 hdr.ipv6->daddr.s6_addr32[3];
6856 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006857
6858 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006859 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6860 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006861}
6862
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006863static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006864{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006865 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006866 /* Herbert's original patch had:
6867 * smp_mb__after_netif_stop_queue();
6868 * but since that doesn't exist yet, just open code it. */
6869 smp_mb();
6870
6871 /* We need to check again in a case another CPU has just
6872 * made room available. */
6873 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6874 return -EBUSY;
6875
6876 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006877 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006878 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006879 return 0;
6880}
6881
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006882static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006883{
6884 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6885 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006886 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006887}
6888
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006889static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6890{
6891 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006892 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006893#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006894 __be16 protocol;
6895
6896 protocol = vlan_get_protocol(skb);
6897
John Fastabende5b64632011-03-08 03:44:52 +00006898 if (((protocol == htons(ETH_P_FCOE)) ||
6899 (protocol == htons(ETH_P_FIP))) &&
6900 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6901 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6902 txq += adapter->ring_feature[RING_F_FCOE].mask;
6903 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006904 }
6905#endif
6906
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006907 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6908 while (unlikely(txq >= dev->real_num_tx_queues))
6909 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006910 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006911 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006912
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006913 return skb_tx_hash(dev, skb);
6914}
6915
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006916netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006917 struct ixgbe_adapter *adapter,
6918 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006919{
Auke Kok9a799d72007-09-15 14:07:45 -07006920 unsigned int first;
6921 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006922 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006923 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006924 int count = 0;
6925 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006926 __be16 protocol;
6927
6928 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006929
Jesse Grosseab6d182010-10-20 13:56:03 +00006930 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006931 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006932 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6933 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006934 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006935 }
6936 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6937 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006938 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6939 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006940 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006941 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6942 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006943 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006944
Yi Zou09ad1cc2009-09-03 14:56:10 +00006945#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006946 /* for FCoE with DCB, we force the priority to what
6947 * was specified by the switch */
6948 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006949 (protocol == htons(ETH_P_FCOE)))
6950 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006951#endif
6952
Yi Zoueacd73f2009-05-13 13:11:06 +00006953 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006954 if (skb_is_gso(skb) ||
6955 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006956 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6957 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006958 count++;
6959
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006960 count += TXD_USE_COUNT(skb_headlen(skb));
6961 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006962 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6963
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006964 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006965 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006966 return NETDEV_TX_BUSY;
6967 }
Auke Kok9a799d72007-09-15 14:07:45 -07006968
Auke Kok9a799d72007-09-15 14:07:45 -07006969 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006970 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6971#ifdef IXGBE_FCOE
6972 /* setup tx offload for FCoE */
6973 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6974 if (tso < 0) {
6975 dev_kfree_skb_any(skb);
6976 return NETDEV_TX_OK;
6977 }
6978 if (tso)
6979 tx_flags |= IXGBE_TX_FLAGS_FSO;
6980#endif /* IXGBE_FCOE */
6981 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006982 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006983 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006984 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6985 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006986 if (tso < 0) {
6987 dev_kfree_skb_any(skb);
6988 return NETDEV_TX_OK;
6989 }
6990
6991 if (tso)
6992 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006993 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6994 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006995 (skb->ip_summed == CHECKSUM_PARTIAL))
6996 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006997 }
6998
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006999 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00007000 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007001 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00007002 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
7003 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08007004 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007005 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07007006
Alexander Duyck44df32c2009-03-31 21:34:23 +00007007 } else {
7008 dev_kfree_skb_any(skb);
7009 tx_ring->tx_buffer_info[first].time_stamp = 0;
7010 tx_ring->next_to_use = first;
7011 }
Auke Kok9a799d72007-09-15 14:07:45 -07007012
7013 return NETDEV_TX_OK;
7014}
7015
Alexander Duyck84418e32010-08-19 13:40:54 +00007016static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
7017{
7018 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7019 struct ixgbe_ring *tx_ring;
7020
7021 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08007022 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00007023}
7024
Auke Kok9a799d72007-09-15 14:07:45 -07007025/**
Auke Kok9a799d72007-09-15 14:07:45 -07007026 * ixgbe_set_mac - Change the Ethernet Address of the NIC
7027 * @netdev: network interface device structure
7028 * @p: pointer to an address structure
7029 *
7030 * Returns 0 on success, negative on failure
7031 **/
7032static int ixgbe_set_mac(struct net_device *netdev, void *p)
7033{
7034 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007035 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07007036 struct sockaddr *addr = p;
7037
7038 if (!is_valid_ether_addr(addr->sa_data))
7039 return -EADDRNOTAVAIL;
7040
7041 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007042 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07007043
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007044 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
7045 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07007046
7047 return 0;
7048}
7049
Ben Hutchings6b73e102009-04-29 08:08:58 +00007050static int
7051ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
7052{
7053 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7054 struct ixgbe_hw *hw = &adapter->hw;
7055 u16 value;
7056 int rc;
7057
7058 if (prtad != hw->phy.mdio.prtad)
7059 return -EINVAL;
7060 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
7061 if (!rc)
7062 rc = value;
7063 return rc;
7064}
7065
7066static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
7067 u16 addr, u16 value)
7068{
7069 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7070 struct ixgbe_hw *hw = &adapter->hw;
7071
7072 if (prtad != hw->phy.mdio.prtad)
7073 return -EINVAL;
7074 return hw->phy.ops.write_reg(hw, addr, devad, value);
7075}
7076
7077static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
7078{
7079 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7080
7081 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
7082}
7083
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007084/**
7085 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007086 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007087 * @netdev: network interface device structure
7088 *
7089 * Returns non-zero on failure
7090 **/
7091static int ixgbe_add_sanmac_netdev(struct net_device *dev)
7092{
7093 int err = 0;
7094 struct ixgbe_adapter *adapter = netdev_priv(dev);
7095 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7096
7097 if (is_valid_ether_addr(mac->san_addr)) {
7098 rtnl_lock();
7099 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7100 rtnl_unlock();
7101 }
7102 return err;
7103}
7104
7105/**
7106 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007107 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007108 * @netdev: network interface device structure
7109 *
7110 * Returns non-zero on failure
7111 **/
7112static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7113{
7114 int err = 0;
7115 struct ixgbe_adapter *adapter = netdev_priv(dev);
7116 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7117
7118 if (is_valid_ether_addr(mac->san_addr)) {
7119 rtnl_lock();
7120 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7121 rtnl_unlock();
7122 }
7123 return err;
7124}
7125
Auke Kok9a799d72007-09-15 14:07:45 -07007126#ifdef CONFIG_NET_POLL_CONTROLLER
7127/*
7128 * Polling 'interrupt' - used by things like netconsole to send skbs
7129 * without having to re-enable interrupts. It's not called while
7130 * the interrupt routine is executing.
7131 */
7132static void ixgbe_netpoll(struct net_device *netdev)
7133{
7134 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007135 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007136
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007137 /* if interface is down do nothing */
7138 if (test_bit(__IXGBE_DOWN, &adapter->state))
7139 return;
7140
Auke Kok9a799d72007-09-15 14:07:45 -07007141 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007142 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7143 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7144 for (i = 0; i < num_q_vectors; i++) {
7145 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7146 ixgbe_msix_clean_many(0, q_vector);
7147 }
7148 } else {
7149 ixgbe_intr(adapter->pdev->irq, netdev);
7150 }
Auke Kok9a799d72007-09-15 14:07:45 -07007151 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007152}
7153#endif
7154
Eric Dumazetde1036b2010-10-20 23:00:04 +00007155static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7156 struct rtnl_link_stats64 *stats)
7157{
7158 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7159 int i;
7160
Eric Dumazet1a515022010-11-16 19:26:42 -08007161 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007162 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007163 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007164 u64 bytes, packets;
7165 unsigned int start;
7166
Eric Dumazet1a515022010-11-16 19:26:42 -08007167 if (ring) {
7168 do {
7169 start = u64_stats_fetch_begin_bh(&ring->syncp);
7170 packets = ring->stats.packets;
7171 bytes = ring->stats.bytes;
7172 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7173 stats->rx_packets += packets;
7174 stats->rx_bytes += bytes;
7175 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007176 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007177
7178 for (i = 0; i < adapter->num_tx_queues; i++) {
7179 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7180 u64 bytes, packets;
7181 unsigned int start;
7182
7183 if (ring) {
7184 do {
7185 start = u64_stats_fetch_begin_bh(&ring->syncp);
7186 packets = ring->stats.packets;
7187 bytes = ring->stats.bytes;
7188 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7189 stats->tx_packets += packets;
7190 stats->tx_bytes += bytes;
7191 }
7192 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007193 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007194 /* following stats updated by ixgbe_watchdog_task() */
7195 stats->multicast = netdev->stats.multicast;
7196 stats->rx_errors = netdev->stats.rx_errors;
7197 stats->rx_length_errors = netdev->stats.rx_length_errors;
7198 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7199 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7200 return stats;
7201}
7202
7203
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007204static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007205 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007206 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007207 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007208 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007209 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007210 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7211 .ndo_validate_addr = eth_validate_addr,
7212 .ndo_set_mac_address = ixgbe_set_mac,
7213 .ndo_change_mtu = ixgbe_change_mtu,
7214 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007215 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7216 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007217 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007218 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7219 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7220 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7221 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007222 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007223#ifdef CONFIG_IXGBE_DCB
7224 .ndo_setup_tc = ixgbe_setup_tc,
7225#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007226#ifdef CONFIG_NET_POLL_CONTROLLER
7227 .ndo_poll_controller = ixgbe_netpoll,
7228#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007229#ifdef IXGBE_FCOE
7230 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007231 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007232 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007233 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7234 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007235 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007236#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007237};
7238
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007239static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7240 const struct ixgbe_info *ii)
7241{
7242#ifdef CONFIG_PCI_IOV
7243 struct ixgbe_hw *hw = &adapter->hw;
7244 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007245 int num_vf_macvlans, i;
7246 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007247
Greg Rose3377eba792010-12-07 08:16:45 +00007248 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007249 return;
7250
7251 /* The 82599 supports up to 64 VFs per physical function
7252 * but this implementation limits allocation to 63 so that
7253 * basic networking resources are still available to the
7254 * physical function
7255 */
7256 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7257 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7258 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7259 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007260 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007261 goto err_novfs;
7262 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007263
7264 num_vf_macvlans = hw->mac.num_rar_entries -
7265 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7266
7267 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7268 sizeof(struct vf_macvlans),
7269 GFP_KERNEL);
7270 if (mv_list) {
7271 /* Initialize list of VF macvlans */
7272 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7273 for (i = 0; i < num_vf_macvlans; i++) {
7274 mv_list->vf = -1;
7275 mv_list->free = true;
7276 mv_list->rar_entry = hw->mac.num_rar_entries -
7277 (i + adapter->num_vfs + 1);
7278 list_add(&mv_list->l, &adapter->vf_mvs.l);
7279 mv_list++;
7280 }
7281 }
7282
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007283 /* If call to enable VFs succeeded then allocate memory
7284 * for per VF control structures.
7285 */
7286 adapter->vfinfo =
7287 kcalloc(adapter->num_vfs,
7288 sizeof(struct vf_data_storage), GFP_KERNEL);
7289 if (adapter->vfinfo) {
7290 /* Now that we're sure SR-IOV is enabled
7291 * and memory allocated set up the mailbox parameters
7292 */
7293 ixgbe_init_mbx_params_pf(hw);
7294 memcpy(&hw->mbx.ops, ii->mbx_ops,
7295 sizeof(hw->mbx.ops));
7296
7297 /* Disable RSC when in SR-IOV mode */
7298 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7299 IXGBE_FLAG2_RSC_ENABLED);
7300 return;
7301 }
7302
7303 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007304 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7305 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007306 pci_disable_sriov(adapter->pdev);
7307
7308err_novfs:
7309 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7310 adapter->num_vfs = 0;
7311#endif /* CONFIG_PCI_IOV */
7312}
7313
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007314/**
Auke Kok9a799d72007-09-15 14:07:45 -07007315 * ixgbe_probe - Device Initialization Routine
7316 * @pdev: PCI device information struct
7317 * @ent: entry in ixgbe_pci_tbl
7318 *
7319 * Returns 0 on success, negative on failure
7320 *
7321 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7322 * The OS initialization, configuring of the adapter private structure,
7323 * and a hardware reset occur.
7324 **/
7325static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007326 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007327{
7328 struct net_device *netdev;
7329 struct ixgbe_adapter *adapter = NULL;
7330 struct ixgbe_hw *hw;
7331 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007332 static int cards_found;
7333 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007334 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007335 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007336#ifdef IXGBE_FCOE
7337 u16 device_caps;
7338#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007339 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007340
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007341 /* Catch broken hardware that put the wrong VF device ID in
7342 * the PCIe SR-IOV capability.
7343 */
7344 if (pdev->is_virtfn) {
7345 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7346 pci_name(pdev), pdev->vendor, pdev->device);
7347 return -EINVAL;
7348 }
7349
gouji-new9ce77662009-05-06 10:44:45 +00007350 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007351 if (err)
7352 return err;
7353
Nick Nunley1b507732010-04-27 13:10:27 +00007354 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7355 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007356 pci_using_dac = 1;
7357 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007358 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007359 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007360 err = dma_set_coherent_mask(&pdev->dev,
7361 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007362 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007363 dev_err(&pdev->dev,
7364 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007365 goto err_dma;
7366 }
7367 }
7368 pci_using_dac = 0;
7369 }
7370
gouji-new9ce77662009-05-06 10:44:45 +00007371 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007372 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007373 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007374 dev_err(&pdev->dev,
7375 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007376 goto err_pci_reg;
7377 }
7378
Frans Pop19d5afd2009-10-02 10:04:12 -07007379 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007380
Auke Kok9a799d72007-09-15 14:07:45 -07007381 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007382 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007383
John Fastabendc85a2612010-02-25 23:15:21 +00007384 if (ii->mac == ixgbe_mac_82598EB)
7385 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7386 else
7387 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7388
John Fastabende5b64632011-03-08 03:44:52 +00007389#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007390 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007391#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007392 indices += min_t(unsigned int, num_possible_cpus(),
7393 IXGBE_MAX_FCOE_INDICES);
7394#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007395 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007396 if (!netdev) {
7397 err = -ENOMEM;
7398 goto err_alloc_etherdev;
7399 }
7400
Auke Kok9a799d72007-09-15 14:07:45 -07007401 SET_NETDEV_DEV(netdev, &pdev->dev);
7402
Auke Kok9a799d72007-09-15 14:07:45 -07007403 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007404 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007405
7406 adapter->netdev = netdev;
7407 adapter->pdev = pdev;
7408 hw = &adapter->hw;
7409 hw->back = adapter;
7410 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7411
Jeff Kirsher05857982008-09-11 19:57:00 -07007412 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007413 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007414 if (!hw->hw_addr) {
7415 err = -EIO;
7416 goto err_ioremap;
7417 }
7418
7419 for (i = 1; i <= 5; i++) {
7420 if (pci_resource_len(pdev, i) == 0)
7421 continue;
7422 }
7423
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007424 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007425 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007426 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007427 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007428
Auke Kok9a799d72007-09-15 14:07:45 -07007429 adapter->bd_number = cards_found;
7430
Auke Kok9a799d72007-09-15 14:07:45 -07007431 /* Setup hw api */
7432 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007433 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007434
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007435 /* EEPROM */
7436 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7437 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7438 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7439 if (!(eec & (1 << 8)))
7440 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7441
7442 /* PHY */
7443 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007444 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007445 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7446 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7447 hw->phy.mdio.mmds = 0;
7448 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7449 hw->phy.mdio.dev = netdev;
7450 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7451 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007452
Don Skidmore8ca783a2009-05-26 20:40:47 -07007453 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007454
7455 /* setup the private structure */
7456 err = ixgbe_sw_init(adapter);
7457 if (err)
7458 goto err_sw_init;
7459
Don Skidmoree86bff02010-02-11 04:14:08 +00007460 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007461 switch (adapter->hw.mac.type) {
7462 case ixgbe_mac_82599EB:
7463 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007464 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007465 break;
7466 default:
7467 break;
7468 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007469
Don Skidmorebf069c92009-05-07 10:39:54 +00007470 /*
7471 * If there is a fan on this device and it has failed log the
7472 * failure.
7473 */
7474 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7475 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7476 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007477 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007478 }
7479
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007480 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007481 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007482 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007483 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007484 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7485 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007486 err = 0;
7487 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007488 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007489 "module type was detected.\n");
7490 e_dev_err("Reload the driver after installing a supported "
7491 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007492 goto err_sw_init;
7493 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007494 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007495 goto err_sw_init;
7496 }
7497
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007498 ixgbe_probe_vf(adapter, ii);
7499
Emil Tantilov396e7992010-07-01 20:05:12 +00007500 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007501 NETIF_F_IP_CSUM |
7502 NETIF_F_HW_VLAN_TX |
7503 NETIF_F_HW_VLAN_RX |
7504 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007505
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007506 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007507 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007508 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007509 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007510 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007511
Don Skidmore58be7662011-04-12 09:42:11 +00007512 switch (adapter->hw.mac.type) {
7513 case ixgbe_mac_82599EB:
7514 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007515 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007516 break;
7517 default:
7518 break;
7519 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007520
Jeff Kirsherad31c402008-06-05 04:05:30 -07007521 netdev->vlan_features |= NETIF_F_TSO;
7522 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007523 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007524 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007525 netdev->vlan_features |= NETIF_F_SG;
7526
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007527 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7528 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7529 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007530
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007531#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007532 netdev->dcbnl_ops = &dcbnl_ops;
7533#endif
7534
Yi Zoueacd73f2009-05-13 13:11:06 +00007535#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007536 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007537 if (hw->mac.ops.get_device_caps) {
7538 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007539 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7540 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007541 }
7542 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007543 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7544 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7545 netdev->vlan_features |= NETIF_F_FSO;
7546 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7547 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007548#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007549 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007550 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007551 netdev->vlan_features |= NETIF_F_HIGHDMA;
7552 }
Auke Kok9a799d72007-09-15 14:07:45 -07007553
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007554 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007555 netdev->features |= NETIF_F_LRO;
7556
Auke Kok9a799d72007-09-15 14:07:45 -07007557 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007558 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007559 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007560 err = -EIO;
7561 goto err_eeprom;
7562 }
7563
7564 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7565 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7566
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007567 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007568 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007569 err = -EIO;
7570 goto err_eeprom;
7571 }
7572
Don Skidmorec6ecf392010-12-03 03:31:51 +00007573 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7574 if (hw->mac.ops.disable_tx_laser &&
7575 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007576 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007577 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007578 hw->mac.ops.disable_tx_laser(hw);
7579
Alexander Duyck70864002011-04-27 09:13:56 +00007580 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7581 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007582
Alexander Duyck70864002011-04-27 09:13:56 +00007583 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7584 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7585
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007586 err = ixgbe_init_interrupt_scheme(adapter);
7587 if (err)
7588 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007589
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007590 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7591 netdev->features &= ~NETIF_F_RXHASH;
7592
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007593 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007594 case IXGBE_DEV_ID_82599_SFP:
7595 /* Only this subdevice supports WOL */
7596 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7597 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7598 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7599 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007600 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7601 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007602 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7603 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7604 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7605 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007606 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007607 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007608 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007609 break;
7610 default:
7611 adapter->wol = 0;
7612 break;
7613 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007614 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7615
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007616 /* pick up the PCI bus settings for reporting later */
7617 hw->mac.ops.get_bus_info(hw);
7618
Auke Kok9a799d72007-09-15 14:07:45 -07007619 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007620 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007621 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7622 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007623 "Unknown"),
7624 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7625 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7626 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7627 "Unknown"),
7628 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007629
7630 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7631 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007632 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007633 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007634 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007635 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007636 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007637 else
Don Skidmore289700db2010-12-03 03:32:58 +00007638 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7639 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007640
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007641 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007642 e_dev_warn("PCI-Express bandwidth available for this card is "
7643 "not sufficient for optimal performance.\n");
7644 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7645 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007646 }
7647
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007648 /* save off EEPROM version number */
7649 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7650
Auke Kok9a799d72007-09-15 14:07:45 -07007651 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007652 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007653
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007654 if (err == IXGBE_ERR_EEPROM_VERSION) {
7655 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007656 e_dev_warn("This device is a pre-production adapter/LOM. "
7657 "Please be aware there may be issues associated "
7658 "with your hardware. If you are experiencing "
7659 "problems please contact your Intel or hardware "
7660 "representative who provided you with this "
7661 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007662 }
Auke Kok9a799d72007-09-15 14:07:45 -07007663 strcpy(netdev->name, "eth%d");
7664 err = register_netdev(netdev);
7665 if (err)
7666 goto err_register;
7667
Jesse Brandeburg54386462009-04-17 20:44:27 +00007668 /* carrier off reporting is important to ethtool even BEFORE open */
7669 netif_carrier_off(netdev);
7670
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007671#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007672 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007673 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007674 ixgbe_setup_dca(adapter);
7675 }
7676#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007677 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007678 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007679 for (i = 0; i < adapter->num_vfs; i++)
7680 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7681 }
7682
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007683 /* add san mac addr to netdev */
7684 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007685
Emil Tantilov849c4542010-06-03 16:53:41 +00007686 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007687 cards_found++;
7688 return 0;
7689
7690err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007691 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007692 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007693err_sw_init:
7694err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007695 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7696 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007697 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007698 iounmap(hw->hw_addr);
7699err_ioremap:
7700 free_netdev(netdev);
7701err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007702 pci_release_selected_regions(pdev,
7703 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007704err_pci_reg:
7705err_dma:
7706 pci_disable_device(pdev);
7707 return err;
7708}
7709
7710/**
7711 * ixgbe_remove - Device Removal Routine
7712 * @pdev: PCI device information struct
7713 *
7714 * ixgbe_remove is called by the PCI subsystem to alert the driver
7715 * that it should release a PCI device. The could be caused by a
7716 * Hot-Plug event, or because the driver is going to be removed from
7717 * memory.
7718 **/
7719static void __devexit ixgbe_remove(struct pci_dev *pdev)
7720{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007721 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7722 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007723
7724 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007725 cancel_work_sync(&adapter->service_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007726
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007727#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007728 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7729 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7730 dca_remove_requester(&pdev->dev);
7731 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7732 }
7733
7734#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007735#ifdef IXGBE_FCOE
7736 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7737 ixgbe_cleanup_fcoe(adapter);
7738
7739#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007740
7741 /* remove the added san mac */
7742 ixgbe_del_sanmac_netdev(netdev);
7743
Donald Skidmorec4900be2008-11-20 21:11:42 -08007744 if (netdev->reg_state == NETREG_REGISTERED)
7745 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007746
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007747 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7748 ixgbe_disable_sriov(adapter);
7749
Alexander Duyck7a921c92009-05-06 10:43:28 +00007750 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007751
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007752 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007753
7754 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007755 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007756 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007757
Emil Tantilov849c4542010-06-03 16:53:41 +00007758 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007759
Auke Kok9a799d72007-09-15 14:07:45 -07007760 free_netdev(netdev);
7761
Frans Pop19d5afd2009-10-02 10:04:12 -07007762 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007763
Auke Kok9a799d72007-09-15 14:07:45 -07007764 pci_disable_device(pdev);
7765}
7766
7767/**
7768 * ixgbe_io_error_detected - called when PCI error is detected
7769 * @pdev: Pointer to PCI device
7770 * @state: The current pci connection state
7771 *
7772 * This function is called after a PCI bus error affecting
7773 * this device has been detected.
7774 */
7775static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007776 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007777{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007778 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7779 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007780
7781 netif_device_detach(netdev);
7782
Breno Leitao3044b8d2009-05-06 10:44:26 +00007783 if (state == pci_channel_io_perm_failure)
7784 return PCI_ERS_RESULT_DISCONNECT;
7785
Auke Kok9a799d72007-09-15 14:07:45 -07007786 if (netif_running(netdev))
7787 ixgbe_down(adapter);
7788 pci_disable_device(pdev);
7789
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007790 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007791 return PCI_ERS_RESULT_NEED_RESET;
7792}
7793
7794/**
7795 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7796 * @pdev: Pointer to PCI device
7797 *
7798 * Restart the card from scratch, as if from a cold-boot.
7799 */
7800static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7801{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007802 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007803 pci_ers_result_t result;
7804 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007805
gouji-new9ce77662009-05-06 10:44:45 +00007806 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007807 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007808 result = PCI_ERS_RESULT_DISCONNECT;
7809 } else {
7810 pci_set_master(pdev);
7811 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007812 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007813
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007814 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007815
7816 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007817 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007818 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007819 }
Auke Kok9a799d72007-09-15 14:07:45 -07007820
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007821 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7822 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007823 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7824 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007825 /* non-fatal, continue */
7826 }
Auke Kok9a799d72007-09-15 14:07:45 -07007827
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007828 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007829}
7830
7831/**
7832 * ixgbe_io_resume - called when traffic can start flowing again.
7833 * @pdev: Pointer to PCI device
7834 *
7835 * This callback is called when the error recovery driver tells us that
7836 * its OK to resume normal operation.
7837 */
7838static void ixgbe_io_resume(struct pci_dev *pdev)
7839{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007840 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7841 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007842
7843 if (netif_running(netdev)) {
7844 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007845 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007846 return;
7847 }
7848 }
7849
7850 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007851}
7852
7853static struct pci_error_handlers ixgbe_err_handler = {
7854 .error_detected = ixgbe_io_error_detected,
7855 .slot_reset = ixgbe_io_slot_reset,
7856 .resume = ixgbe_io_resume,
7857};
7858
7859static struct pci_driver ixgbe_driver = {
7860 .name = ixgbe_driver_name,
7861 .id_table = ixgbe_pci_tbl,
7862 .probe = ixgbe_probe,
7863 .remove = __devexit_p(ixgbe_remove),
7864#ifdef CONFIG_PM
7865 .suspend = ixgbe_suspend,
7866 .resume = ixgbe_resume,
7867#endif
7868 .shutdown = ixgbe_shutdown,
7869 .err_handler = &ixgbe_err_handler
7870};
7871
7872/**
7873 * ixgbe_init_module - Driver Registration Routine
7874 *
7875 * ixgbe_init_module is the first routine called when the driver is
7876 * loaded. All it does is register with the PCI subsystem.
7877 **/
7878static int __init ixgbe_init_module(void)
7879{
7880 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007881 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007882 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007883
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007884#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007885 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007886#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007887
Auke Kok9a799d72007-09-15 14:07:45 -07007888 ret = pci_register_driver(&ixgbe_driver);
7889 return ret;
7890}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007891
Auke Kok9a799d72007-09-15 14:07:45 -07007892module_init(ixgbe_init_module);
7893
7894/**
7895 * ixgbe_exit_module - Driver Exit Cleanup Routine
7896 *
7897 * ixgbe_exit_module is called just before the driver is removed
7898 * from memory.
7899 **/
7900static void __exit ixgbe_exit_module(void)
7901{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007902#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007903 dca_unregister_notify(&dca_notifier);
7904#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007905 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007906 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007907}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007908
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007909#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007910static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007911 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007912{
7913 int ret_val;
7914
7915 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007916 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007917
7918 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7919}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007920
Alexander Duyckb4533682009-03-31 21:32:42 +00007921#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007922
Auke Kok9a799d72007-09-15 14:07:45 -07007923module_exit(ixgbe_exit_module);
7924
7925/* ixgbe_main.c */