blob: a5d4226eee0c43be7ba39fbf6a8d246a20eb07a5 [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 Jr8911184f2009-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
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700836static void ixgbe_tx_timeout(struct net_device *netdev);
837
Auke Kok9a799d72007-09-15 14:07:45 -0700838/**
839 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000840 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700841 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700842 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000843static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000844 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700845{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000846 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800847 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
848 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700849 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800850 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700851
852 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800853 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000854 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800855
856 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000857 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800858 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000859 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800860 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000861 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700862 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700863
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800864 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800865 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800866
Auke Kok9a799d72007-09-15 14:07:45 -0700867 i++;
868 if (i == tx_ring->count)
869 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800870
871 if (cleaned && tx_buffer_info->skb) {
872 total_bytes += tx_buffer_info->bytecount;
873 total_packets += tx_buffer_info->gso_segs;
874 }
875
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800876 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800877 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700878 }
879
John Fastabendc84d3242010-11-16 19:27:12 -0800880 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800881 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000882 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800883 }
884
Auke Kok9a799d72007-09-15 14:07:45 -0700885 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800886 tx_ring->total_bytes += total_bytes;
887 tx_ring->total_packets += total_packets;
888 u64_stats_update_begin(&tx_ring->syncp);
889 tx_ring->stats.packets += total_packets;
890 tx_ring->stats.bytes += total_bytes;
891 u64_stats_update_end(&tx_ring->syncp);
892
John Fastabendc84d3242010-11-16 19:27:12 -0800893 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800894 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800895 struct ixgbe_hw *hw = &adapter->hw;
896 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
897 e_err(drv, "Detected Tx Unit Hang\n"
898 " Tx Queue <%d>\n"
899 " TDH, TDT <%x>, <%x>\n"
900 " next_to_use <%x>\n"
901 " next_to_clean <%x>\n"
902 "tx_buffer_info[next_to_clean]\n"
903 " time_stamp <%lx>\n"
904 " jiffies <%lx>\n",
905 tx_ring->queue_index,
906 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
907 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
908 tx_ring->next_to_use, eop,
909 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
910
911 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
912
913 e_info(probe,
914 "tx hang %d detected on queue %d, resetting adapter\n",
915 adapter->tx_timeout_count + 1, tx_ring->queue_index);
916
917 /* schedule immediate reset if we believe we hung */
Alexander Duyckb9537992010-11-16 19:26:58 -0800918 ixgbe_tx_timeout(adapter->netdev);
919
920 /* the adapter is about to reset, no point in enabling stuff */
921 return true;
922 }
Auke Kok9a799d72007-09-15 14:07:45 -0700923
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800924#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800925 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Joe Perchese8e9f692010-09-07 21:34:53 +0000926 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800927 /* Make sure that anybody stopping the queue after this
928 * sees the new next_to_clean.
929 */
930 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800931 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800932 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800933 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800934 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800935 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800936 }
Auke Kok9a799d72007-09-15 14:07:45 -0700937
Eric Dumazet807540b2010-09-23 05:40:09 +0000938 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700939}
940
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400941#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800942static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800943 struct ixgbe_ring *rx_ring,
944 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800945{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800946 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800947 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800948 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800949
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800950 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
951 switch (hw->mac.type) {
952 case ixgbe_mac_82598EB:
953 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
954 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
955 break;
956 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800957 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800958 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
959 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
960 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
961 break;
962 default:
963 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800964 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800965 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
966 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
967 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800968 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800969}
970
971static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800972 struct ixgbe_ring *tx_ring,
973 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800974{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000975 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800976 u32 txctrl;
977 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800978
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800979 switch (hw->mac.type) {
980 case ixgbe_mac_82598EB:
981 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
982 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
983 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
984 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800985 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
986 break;
987 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800988 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800989 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
990 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
991 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
992 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
993 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800994 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
995 break;
996 default:
997 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800998 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800999}
1000
1001static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
1002{
1003 struct ixgbe_adapter *adapter = q_vector->adapter;
1004 int cpu = get_cpu();
1005 long r_idx;
1006 int i;
1007
1008 if (q_vector->cpu == cpu)
1009 goto out_no_update;
1010
1011 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1012 for (i = 0; i < q_vector->txr_count; i++) {
1013 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
1014 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
1015 r_idx + 1);
1016 }
1017
1018 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1019 for (i = 0; i < q_vector->rxr_count; i++) {
1020 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1021 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1022 r_idx + 1);
1023 }
1024
1025 q_vector->cpu = cpu;
1026out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001027 put_cpu();
1028}
1029
1030static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1031{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001032 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001033 int i;
1034
1035 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1036 return;
1037
Alexander Duycke35ec122009-05-21 13:07:12 +00001038 /* always use CB2 mode, difference is masked in the CB driver */
1039 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1040
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001041 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1042 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1043 else
1044 num_q_vectors = 1;
1045
1046 for (i = 0; i < num_q_vectors; i++) {
1047 adapter->q_vector[i]->cpu = -1;
1048 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001049 }
1050}
1051
1052static int __ixgbe_notify_dca(struct device *dev, void *data)
1053{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001054 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001055 unsigned long event = *(unsigned long *)data;
1056
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001057 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1058 return 0;
1059
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001060 switch (event) {
1061 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001062 /* if we're already enabled, don't do it again */
1063 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1064 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001065 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001066 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001067 ixgbe_setup_dca(adapter);
1068 break;
1069 }
1070 /* Fall Through since DCA is disabled. */
1071 case DCA_PROVIDER_REMOVE:
1072 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1073 dca_remove_requester(dev);
1074 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1075 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1076 }
1077 break;
1078 }
1079
Denis V. Lunev652f0932008-03-27 14:39:17 +03001080 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001081}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001082#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001083
1084static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1085 struct sk_buff *skb)
1086{
1087 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1088}
1089
Auke Kok9a799d72007-09-15 14:07:45 -07001090/**
1091 * ixgbe_receive_skb - Send a completed packet up the stack
1092 * @adapter: board private structure
1093 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001094 * @status: hardware indication of status of receive
1095 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1096 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001097 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001098static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001099 struct sk_buff *skb, u8 status,
1100 struct ixgbe_ring *ring,
1101 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001102{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001103 struct ixgbe_adapter *adapter = q_vector->adapter;
1104 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001105 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1106 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001107
Jesse Grossf62bbb52010-10-20 13:56:10 +00001108 if (is_vlan && (tag & VLAN_VID_MASK))
1109 __vlan_hwaccel_put_tag(skb, tag);
1110
1111 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1112 napi_gro_receive(napi, skb);
1113 else
1114 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001115}
1116
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001117/**
1118 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1119 * @adapter: address of board private structure
1120 * @status_err: hardware indication of status of receive
1121 * @skb: skb currently being received and modified
1122 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001123static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001124 union ixgbe_adv_rx_desc *rx_desc,
1125 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001126{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001127 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1128
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001129 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001130
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001131 /* Rx csum disabled */
1132 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001133 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001134
1135 /* if IP and error */
1136 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1137 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001138 adapter->hw_csum_rx_error++;
1139 return;
1140 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001141
1142 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1143 return;
1144
1145 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001146 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1147
1148 /*
1149 * 82599 errata, UDP frames with a 0 checksum can be marked as
1150 * checksum errors.
1151 */
1152 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1153 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1154 return;
1155
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001156 adapter->hw_csum_rx_error++;
1157 return;
1158 }
1159
Auke Kok9a799d72007-09-15 14:07:45 -07001160 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001161 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001162}
1163
Alexander Duyck84ea2592010-11-16 19:26:49 -08001164static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001165{
1166 /*
1167 * Force memory writes to complete before letting h/w
1168 * know there are new descriptors to fetch. (Only
1169 * applicable for weak-ordered memory model archs,
1170 * such as IA-64).
1171 */
1172 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001173 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001174}
1175
Auke Kok9a799d72007-09-15 14:07:45 -07001176/**
1177 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001178 * @rx_ring: ring to place buffers on
1179 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001180 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001181void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001182{
Auke Kok9a799d72007-09-15 14:07:45 -07001183 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001184 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001185 struct sk_buff *skb;
1186 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001187
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001188 /* do nothing if no valid netdev defined */
1189 if (!rx_ring->netdev)
1190 return;
1191
Auke Kok9a799d72007-09-15 14:07:45 -07001192 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001193 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001194 bi = &rx_ring->rx_buffer_info[i];
1195 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001196
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001197 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001198 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001199 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001200 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001201 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001202 goto no_buffers;
1203 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001204 /* initialize queue mapping */
1205 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001206 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001207 }
Auke Kok9a799d72007-09-15 14:07:45 -07001208
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001209 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001210 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001211 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001212 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001213 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001214 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001215 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001216 bi->dma = 0;
1217 goto no_buffers;
1218 }
Auke Kok9a799d72007-09-15 14:07:45 -07001219 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001220
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001221 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001222 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001223 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001224 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001225 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001226 goto no_buffers;
1227 }
1228 }
1229
1230 if (!bi->page_dma) {
1231 /* use a half page if we're re-using */
1232 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001233 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001234 bi->page,
1235 bi->page_offset,
1236 PAGE_SIZE / 2,
1237 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001238 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001239 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001240 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001241 bi->page_dma = 0;
1242 goto no_buffers;
1243 }
1244 }
1245
1246 /* Refresh the desc even if buffer_addrs didn't change
1247 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001248 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1249 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001250 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001251 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001252 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001253 }
1254
1255 i++;
1256 if (i == rx_ring->count)
1257 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001258 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001259
Auke Kok9a799d72007-09-15 14:07:45 -07001260no_buffers:
1261 if (rx_ring->next_to_use != i) {
1262 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001263 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001264 }
1265}
1266
Alexander Duyckc267fc12010-11-16 19:27:00 -08001267static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001268{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001269 /* HW will not DMA in data larger than the given buffer, even if it
1270 * parses the (NFS, of course) header to be larger. In that case, it
1271 * fills the header buffer and spills the rest into the page.
1272 */
1273 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1274 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1275 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1276 if (hlen > IXGBE_RX_HDR_SIZE)
1277 hlen = IXGBE_RX_HDR_SIZE;
1278 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001279}
1280
Alexander Duyckf8212f92009-04-27 22:42:37 +00001281/**
1282 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1283 * @skb: pointer to the last skb in the rsc queue
1284 *
1285 * This function changes a queue full of hw rsc buffers into a completed
1286 * packet. It uses the ->prev pointers to find the first packet and then
1287 * turns it into the frag list owner.
1288 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001289static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001290{
1291 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001292 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001293
1294 while (skb->prev) {
1295 struct sk_buff *prev = skb->prev;
1296 frag_list_size += skb->len;
1297 skb->prev = NULL;
1298 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001299 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001300 }
1301
1302 skb_shinfo(skb)->frag_list = skb->next;
1303 skb->next = NULL;
1304 skb->len += frag_list_size;
1305 skb->data_len += frag_list_size;
1306 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001307 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1308
Alexander Duyckf8212f92009-04-27 22:42:37 +00001309 return skb;
1310}
1311
Alexander Duyckaa801752010-11-16 19:27:02 -08001312static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1313{
1314 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1315 IXGBE_RXDADV_RSCCNT_MASK);
1316}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001317
Alexander Duyckc267fc12010-11-16 19:27:00 -08001318static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001319 struct ixgbe_ring *rx_ring,
1320 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001321{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001322 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001323 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1324 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1325 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001326 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001327 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001328#ifdef IXGBE_FCOE
1329 int ddp_bytes = 0;
1330#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001331 u32 staterr;
1332 u16 i;
1333 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001334 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001335
1336 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001337 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001338 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001339
1340 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001341 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001342
Milton Miller3c945e52010-02-19 17:44:42 +00001343 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001344
Alexander Duyckc267fc12010-11-16 19:27:00 -08001345 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1346
Auke Kok9a799d72007-09-15 14:07:45 -07001347 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001348 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001349 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001350
Alexander Duyckc267fc12010-11-16 19:27:00 -08001351 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001352 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001353
1354 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001355 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001356 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001357 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001358 !(staterr & IXGBE_RXD_STAT_EOP) &&
1359 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001360 /*
1361 * When HWRSC is enabled, delay unmapping
1362 * of the first packet. It carries the
1363 * header information, HW may still
1364 * access the header after the writeback.
1365 * Only unmap it when EOP is reached
1366 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001367 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001368 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001369 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001370 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001371 rx_buffer_info->dma,
1372 rx_ring->rx_buf_len,
1373 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001374 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001375 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001376
1377 if (ring_is_ps_enabled(rx_ring)) {
1378 hlen = ixgbe_get_hlen(rx_desc);
1379 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1380 } else {
1381 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1382 }
1383
1384 skb_put(skb, hlen);
1385 } else {
1386 /* assume packet split since header is unmapped */
1387 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001388 }
1389
1390 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001391 dma_unmap_page(rx_ring->dev,
1392 rx_buffer_info->page_dma,
1393 PAGE_SIZE / 2,
1394 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001395 rx_buffer_info->page_dma = 0;
1396 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001397 rx_buffer_info->page,
1398 rx_buffer_info->page_offset,
1399 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001400
Alexander Duyckc267fc12010-11-16 19:27:00 -08001401 if ((page_count(rx_buffer_info->page) == 1) &&
1402 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001403 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001404 else
1405 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001406
1407 skb->len += upper_len;
1408 skb->data_len += upper_len;
1409 skb->truesize += upper_len;
1410 }
1411
1412 i++;
1413 if (i == rx_ring->count)
1414 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001415
Alexander Duyck31f05a22010-08-19 13:40:31 +00001416 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001417 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001418 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001419
Alexander Duyckaa801752010-11-16 19:27:02 -08001420 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001421 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1422 IXGBE_RXDADV_NEXTP_SHIFT;
1423 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001424 } else {
1425 next_buffer = &rx_ring->rx_buffer_info[i];
1426 }
1427
Alexander Duyckc267fc12010-11-16 19:27:00 -08001428 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001429 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001430 rx_buffer_info->skb = next_buffer->skb;
1431 rx_buffer_info->dma = next_buffer->dma;
1432 next_buffer->skb = skb;
1433 next_buffer->dma = 0;
1434 } else {
1435 skb->next = next_buffer->skb;
1436 skb->next->prev = skb;
1437 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001438 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001439 goto next_desc;
1440 }
1441
Alexander Duyckaa801752010-11-16 19:27:02 -08001442 if (skb->prev) {
1443 skb = ixgbe_transform_rsc_queue(skb);
1444 /* if we got here without RSC the packet is invalid */
1445 if (!pkt_is_rsc) {
1446 __pskb_trim(skb, 0);
1447 rx_buffer_info->skb = skb;
1448 goto next_desc;
1449 }
1450 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001451
1452 if (ring_is_rsc_enabled(rx_ring)) {
1453 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1454 dma_unmap_single(rx_ring->dev,
1455 IXGBE_RSC_CB(skb)->dma,
1456 rx_ring->rx_buf_len,
1457 DMA_FROM_DEVICE);
1458 IXGBE_RSC_CB(skb)->dma = 0;
1459 IXGBE_RSC_CB(skb)->delay_unmap = false;
1460 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001461 }
1462 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001463 if (ring_is_ps_enabled(rx_ring))
1464 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001465 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001466 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001467 rx_ring->rx_stats.rsc_count +=
1468 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001469 rx_ring->rx_stats.rsc_flush++;
1470 }
1471
1472 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001473 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001474 /* trim packet back to size 0 and recycle it */
1475 __pskb_trim(skb, 0);
1476 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001477 goto next_desc;
1478 }
1479
Don Skidmore8bae1b22009-07-23 18:00:39 +00001480 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001481 if (adapter->netdev->features & NETIF_F_RXHASH)
1482 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001483
1484 /* probably a little skewed due to removing CRC */
1485 total_rx_bytes += skb->len;
1486 total_rx_packets++;
1487
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001488 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001489#ifdef IXGBE_FCOE
1490 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001491 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1492 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1493 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001494 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001495 }
Yi Zou332d4a72009-05-13 13:11:53 +00001496#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001497 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001498
1499next_desc:
1500 rx_desc->wb.upper.status_error = 0;
1501
Alexander Duyckc267fc12010-11-16 19:27:00 -08001502 (*work_done)++;
1503 if (*work_done >= work_to_do)
1504 break;
1505
Auke Kok9a799d72007-09-15 14:07:45 -07001506 /* return some buffers to hardware, one at a time is too slow */
1507 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001508 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001509 cleaned_count = 0;
1510 }
1511
1512 /* use prefetched values */
1513 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001514 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001515 }
1516
Auke Kok9a799d72007-09-15 14:07:45 -07001517 rx_ring->next_to_clean = i;
1518 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1519
1520 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001521 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001522
Yi Zou3d8fd382009-06-08 14:38:44 +00001523#ifdef IXGBE_FCOE
1524 /* include DDPed FCoE data */
1525 if (ddp_bytes > 0) {
1526 unsigned int mss;
1527
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001528 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001529 sizeof(struct fc_frame_header) -
1530 sizeof(struct fcoe_crc_eof);
1531 if (mss > 512)
1532 mss &= ~511;
1533 total_rx_bytes += ddp_bytes;
1534 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1535 }
1536#endif /* IXGBE_FCOE */
1537
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001538 rx_ring->total_packets += total_rx_packets;
1539 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001540 u64_stats_update_begin(&rx_ring->syncp);
1541 rx_ring->stats.packets += total_rx_packets;
1542 rx_ring->stats.bytes += total_rx_bytes;
1543 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001544}
1545
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001546static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001547/**
1548 * ixgbe_configure_msix - Configure MSI-X hardware
1549 * @adapter: board private structure
1550 *
1551 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1552 * interrupts.
1553 **/
1554static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1555{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001556 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001557 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001558 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001559
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001560 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1561
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001562 /*
1563 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001564 * corresponding register.
1565 */
1566 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001567 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001568 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001569 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001570 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001571
1572 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001573 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1574 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001575 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001576 adapter->num_rx_queues,
1577 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001578 }
1579 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001580 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001581
1582 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001583 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1584 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001585 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001586 adapter->num_tx_queues,
1587 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001588 }
1589
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001590 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001591 /* tx only */
1592 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001593 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001594 /* rx or mixed */
1595 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001596
Alexander Duyckfe49f042009-06-04 16:00:09 +00001597 ixgbe_write_eitr(q_vector);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001598 /* If Flow Director is enabled, set interrupt affinity */
1599 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1600 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1601 /*
1602 * Allocate the affinity_hint cpumask, assign the mask
1603 * for this vector, and set our affinity_hint for
1604 * this irq.
1605 */
1606 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1607 GFP_KERNEL))
1608 return;
1609 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1610 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1611 q_vector->affinity_mask);
1612 }
Auke Kok9a799d72007-09-15 14:07:45 -07001613 }
1614
Alexander Duyckbd508172010-11-16 19:27:03 -08001615 switch (adapter->hw.mac.type) {
1616 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001617 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001618 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001619 break;
1620 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001621 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001622 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001623 break;
1624
1625 default:
1626 break;
1627 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001628 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001629
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001630 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001631 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001632 if (adapter->num_vfs)
1633 mask &= ~(IXGBE_EIMS_OTHER |
1634 IXGBE_EIMS_MAILBOX |
1635 IXGBE_EIMS_LSC);
1636 else
1637 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001638 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001639}
1640
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001641enum latency_range {
1642 lowest_latency = 0,
1643 low_latency = 1,
1644 bulk_latency = 2,
1645 latency_invalid = 255
1646};
1647
1648/**
1649 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1650 * @adapter: pointer to adapter
1651 * @eitr: eitr setting (ints per sec) to give last timeslice
1652 * @itr_setting: current throttle rate in ints/second
1653 * @packets: the number of packets during this measurement interval
1654 * @bytes: the number of bytes during this measurement interval
1655 *
1656 * Stores a new ITR value based on packets and byte
1657 * counts during the last interrupt. The advantage of per interrupt
1658 * computation is faster updates and more accurate ITR for the current
1659 * traffic pattern. Constants in this function were computed
1660 * based on theoretical maximum wire speed and thresholds were set based
1661 * on testing data as well as attempting to minimize response time
1662 * while increasing bulk throughput.
1663 * this functionality is controlled by the InterruptThrottleRate module
1664 * parameter (see ixgbe_param.c)
1665 **/
1666static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001667 u32 eitr, u8 itr_setting,
1668 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001669{
1670 unsigned int retval = itr_setting;
1671 u32 timepassed_us;
1672 u64 bytes_perint;
1673
1674 if (packets == 0)
1675 goto update_itr_done;
1676
1677
1678 /* simple throttlerate management
1679 * 0-20MB/s lowest (100000 ints/s)
1680 * 20-100MB/s low (20000 ints/s)
1681 * 100-1249MB/s bulk (8000 ints/s)
1682 */
1683 /* what was last interrupt timeslice? */
1684 timepassed_us = 1000000/eitr;
1685 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1686
1687 switch (itr_setting) {
1688 case lowest_latency:
1689 if (bytes_perint > adapter->eitr_low)
1690 retval = low_latency;
1691 break;
1692 case low_latency:
1693 if (bytes_perint > adapter->eitr_high)
1694 retval = bulk_latency;
1695 else if (bytes_perint <= adapter->eitr_low)
1696 retval = lowest_latency;
1697 break;
1698 case bulk_latency:
1699 if (bytes_perint <= adapter->eitr_high)
1700 retval = low_latency;
1701 break;
1702 }
1703
1704update_itr_done:
1705 return retval;
1706}
1707
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001708/**
1709 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001710 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001711 *
1712 * This function is made to be called by ethtool and by the driver
1713 * when it needs to update EITR registers at runtime. Hardware
1714 * specific quirks/differences are taken care of here.
1715 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001716void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001717{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001718 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001719 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001720 int v_idx = q_vector->v_idx;
1721 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1722
Alexander Duyckbd508172010-11-16 19:27:03 -08001723 switch (adapter->hw.mac.type) {
1724 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001725 /* must write high and low 16 bits to reset counter */
1726 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001727 break;
1728 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001729 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001730 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001731 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001732 * max interrupt rate, but there is an errata where it can
1733 * not be zero with RSC
1734 */
1735 if (itr_reg == 8 &&
1736 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1737 itr_reg = 0;
1738
1739 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001740 * set the WDIS bit to not clear the timer bits and cause an
1741 * immediate assertion of the interrupt
1742 */
1743 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001744 break;
1745 default:
1746 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001747 }
1748 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1749}
1750
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001751static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1752{
1753 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001754 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001755 u32 new_itr;
1756 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001757
1758 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1759 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001760 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001761 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001762 q_vector->tx_itr,
1763 tx_ring->total_packets,
1764 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001765 /* if the result for this queue would decrease interrupt
1766 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001767 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001768 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001769 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001770 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001771 }
1772
1773 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1774 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001775 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001776 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001777 q_vector->rx_itr,
1778 rx_ring->total_packets,
1779 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001780 /* if the result for this queue would decrease interrupt
1781 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001782 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001783 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001784 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001785 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001786 }
1787
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001788 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001789
1790 switch (current_itr) {
1791 /* counts and packets in update_itr are dependent on these numbers */
1792 case lowest_latency:
1793 new_itr = 100000;
1794 break;
1795 case low_latency:
1796 new_itr = 20000; /* aka hwitr = ~200 */
1797 break;
1798 case bulk_latency:
1799 default:
1800 new_itr = 8000;
1801 break;
1802 }
1803
1804 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001805 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001806 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001807
1808 /* save the algorithm value here, not the smoothed one */
1809 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001810
1811 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001812 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001813}
1814
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001815/**
1816 * ixgbe_check_overtemp_task - worker thread to check over tempurature
1817 * @work: pointer to work_struct containing our data
1818 **/
1819static void ixgbe_check_overtemp_task(struct work_struct *work)
1820{
1821 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00001822 struct ixgbe_adapter,
1823 check_overtemp_task);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001824 struct ixgbe_hw *hw = &adapter->hw;
1825 u32 eicr = adapter->interrupt_event;
1826
Joe Perches7ca647b2010-09-07 21:35:40 +00001827 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1828 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001829
Joe Perches7ca647b2010-09-07 21:35:40 +00001830 switch (hw->device_id) {
1831 case IXGBE_DEV_ID_82599_T3_LOM: {
1832 u32 autoneg;
1833 bool link_up = false;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001834
Joe Perches7ca647b2010-09-07 21:35:40 +00001835 if (hw->mac.ops.check_link)
1836 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1837
1838 if (((eicr & IXGBE_EICR_GPI_SDP0) && (!link_up)) ||
1839 (eicr & IXGBE_EICR_LSC))
1840 /* Check if this is due to overtemp */
1841 if (hw->phy.ops.check_overtemp(hw) == IXGBE_ERR_OVERTEMP)
1842 break;
1843 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001844 }
Joe Perches7ca647b2010-09-07 21:35:40 +00001845 default:
1846 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1847 return;
1848 break;
1849 }
1850 e_crit(drv,
1851 "Network adapter has been stopped because it has over heated. "
1852 "Restart the computer. If the problem persists, "
1853 "power off the system and replace the adapter\n");
1854 /* write to clear the interrupt */
1855 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001856}
1857
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001858static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1859{
1860 struct ixgbe_hw *hw = &adapter->hw;
1861
1862 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1863 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001864 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001865 /* write to clear the interrupt */
1866 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1867 }
1868}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001869
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001870static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1871{
1872 struct ixgbe_hw *hw = &adapter->hw;
1873
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001874 if (eicr & IXGBE_EICR_GPI_SDP2) {
1875 /* Clear the interrupt */
1876 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
Alexander Duyck70864002011-04-27 09:13:56 +00001877 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1878 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
1879 ixgbe_service_event_schedule(adapter);
1880 }
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001881 }
1882
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001883 if (eicr & IXGBE_EICR_GPI_SDP1) {
1884 /* Clear the interrupt */
1885 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck70864002011-04-27 09:13:56 +00001886 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1887 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
1888 ixgbe_service_event_schedule(adapter);
1889 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001890 }
1891}
1892
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001893static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1894{
1895 struct ixgbe_hw *hw = &adapter->hw;
1896
1897 adapter->lsc_int++;
1898 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1899 adapter->link_check_timeout = jiffies;
1900 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1901 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001902 IXGBE_WRITE_FLUSH(hw);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001903 schedule_work(&adapter->watchdog_task);
1904 }
1905}
1906
Auke Kok9a799d72007-09-15 14:07:45 -07001907static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1908{
1909 struct net_device *netdev = data;
1910 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1911 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001912 u32 eicr;
1913
1914 /*
1915 * Workaround for Silicon errata. Use clear-by-write instead
1916 * of clear-by-read. Reading with EICS will return the
1917 * interrupt causes without clearing, which later be done
1918 * with the write to EICR.
1919 */
1920 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1921 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001922
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001923 if (eicr & IXGBE_EICR_LSC)
1924 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001925
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001926 if (eicr & IXGBE_EICR_MAILBOX)
1927 ixgbe_msg_task(adapter);
1928
Alexander Duyckbd508172010-11-16 19:27:03 -08001929 switch (hw->mac.type) {
1930 case ixgbe_mac_82599EB:
Don Skidmored9946532010-12-09 06:55:19 +00001931 ixgbe_check_sfp_event(adapter, eicr);
1932 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1933 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1934 adapter->interrupt_event = eicr;
1935 schedule_work(&adapter->check_overtemp_task);
1936 }
1937 /* now fallthrough to handle Flow Director */
Don Skidmoreb93a2222010-11-16 19:27:17 -08001938 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001939 /* Handle Flow Director Full threshold interrupt */
1940 if (eicr & IXGBE_EICR_FLOW_DIR) {
1941 int i;
1942 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1943 /* Disable transmits before FDIR Re-initialization */
1944 netif_tx_stop_all_queues(netdev);
1945 for (i = 0; i < adapter->num_tx_queues; i++) {
1946 struct ixgbe_ring *tx_ring =
Joe Perchese8e9f692010-09-07 21:34:53 +00001947 adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001948 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1949 &tx_ring->state))
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001950 schedule_work(&adapter->fdir_reinit_task);
1951 }
1952 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001953 break;
1954 default:
1955 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001956 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001957
1958 ixgbe_check_fan_failure(adapter, eicr);
1959
Alexander Duyck70864002011-04-27 09:13:56 +00001960 /* re-enable the original interrupt state, no lsc, no queues */
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001961 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyck70864002011-04-27 09:13:56 +00001962 IXGBE_WRITE_REG(hw, IXGBE_EIMS, eicr &
1963 ~(IXGBE_EIMS_LSC | IXGBE_EIMS_RTX_QUEUE));
Auke Kok9a799d72007-09-15 14:07:45 -07001964
1965 return IRQ_HANDLED;
1966}
1967
Alexander Duyckfe49f042009-06-04 16:00:09 +00001968static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1969 u64 qmask)
1970{
1971 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001972 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001973
Alexander Duyckbd508172010-11-16 19:27:03 -08001974 switch (hw->mac.type) {
1975 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001976 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001977 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1978 break;
1979 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001980 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001981 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001982 if (mask)
1983 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001984 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001985 if (mask)
1986 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1987 break;
1988 default:
1989 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001990 }
1991 /* skip the flush */
1992}
1993
1994static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001995 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001996{
1997 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001998 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001999
Alexander Duyckbd508172010-11-16 19:27:03 -08002000 switch (hw->mac.type) {
2001 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002002 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08002003 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
2004 break;
2005 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002006 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00002007 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08002008 if (mask)
2009 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00002010 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08002011 if (mask)
2012 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
2013 break;
2014 default:
2015 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002016 }
2017 /* skip the flush */
2018}
2019
Auke Kok9a799d72007-09-15 14:07:45 -07002020static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
2021{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002022 struct ixgbe_q_vector *q_vector = data;
2023 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002024 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002025 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002026
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002027 if (!q_vector->txr_count)
2028 return IRQ_HANDLED;
2029
2030 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2031 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002032 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002033 tx_ring->total_bytes = 0;
2034 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002035 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002036 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002037 }
2038
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002039 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002040 napi_schedule(&q_vector->napi);
2041
Auke Kok9a799d72007-09-15 14:07:45 -07002042 return IRQ_HANDLED;
2043}
2044
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002045/**
2046 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2047 * @irq: unused
2048 * @data: pointer to our q_vector struct for this interrupt vector
2049 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002050static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2051{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002052 struct ixgbe_q_vector *q_vector = data;
2053 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002054 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002055 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002056 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002057
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002058#ifdef CONFIG_IXGBE_DCA
2059 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2060 ixgbe_update_dca(q_vector);
2061#endif
2062
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002063 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002064 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002065 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002066 rx_ring->total_bytes = 0;
2067 rx_ring->total_packets = 0;
2068 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002069 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002070 }
2071
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002072 if (!q_vector->rxr_count)
2073 return IRQ_HANDLED;
2074
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002075 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002076 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002077
Auke Kok9a799d72007-09-15 14:07:45 -07002078 return IRQ_HANDLED;
2079}
2080
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002081static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2082{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002083 struct ixgbe_q_vector *q_vector = data;
2084 struct ixgbe_adapter *adapter = q_vector->adapter;
2085 struct ixgbe_ring *ring;
2086 int r_idx;
2087 int i;
2088
2089 if (!q_vector->txr_count && !q_vector->rxr_count)
2090 return IRQ_HANDLED;
2091
2092 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2093 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002094 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002095 ring->total_bytes = 0;
2096 ring->total_packets = 0;
2097 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002098 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002099 }
2100
2101 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2102 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002103 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002104 ring->total_bytes = 0;
2105 ring->total_packets = 0;
2106 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002107 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002108 }
2109
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002110 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002111 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002112
2113 return IRQ_HANDLED;
2114}
2115
2116/**
2117 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2118 * @napi: napi struct with our devices info in it
2119 * @budget: amount of work driver is allowed to do this pass, in packets
2120 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002121 * This function is optimized for cleaning one queue only on a single
2122 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002123 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002124static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2125{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002126 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002127 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002128 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002129 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002130 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002131 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002132
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002133#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002134 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002135 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002136#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002137
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002138 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2139 rx_ring = adapter->rx_ring[r_idx];
2140
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002141 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002142
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002143 /* If all Rx work done, exit the polling mode */
2144 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002145 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002146 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002147 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002148 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002149 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002150 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002151 }
2152
2153 return work_done;
2154}
2155
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002156/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002157 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002158 * @napi: napi struct with our devices info in it
2159 * @budget: amount of work driver is allowed to do this pass, in packets
2160 *
2161 * This function will clean more than one rx queue associated with a
2162 * q_vector.
2163 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002164static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002165{
2166 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002167 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002168 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002169 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002170 int work_done = 0, i;
2171 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002172 bool tx_clean_complete = true;
2173
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002174#ifdef CONFIG_IXGBE_DCA
2175 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2176 ixgbe_update_dca(q_vector);
2177#endif
2178
Alexander Duyck91281fd2009-06-04 16:00:27 +00002179 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2180 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002181 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002182 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2183 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002184 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002185 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002186
2187 /* attempt to distribute budget to each queue fairly, but don't allow
2188 * the budget to go below 1 because we'll exit polling */
2189 budget /= (q_vector->rxr_count ?: 1);
2190 budget = max(budget, 1);
2191 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2192 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002193 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002194 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002195 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002196 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002197 }
2198
2199 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002200 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002201 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002202 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002203 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002204 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002205 ixgbe_set_itr_msix(q_vector);
2206 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002207 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002208 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002209 return 0;
2210 }
2211
2212 return work_done;
2213}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002214
2215/**
2216 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2217 * @napi: napi struct with our devices info in it
2218 * @budget: amount of work driver is allowed to do this pass, in packets
2219 *
2220 * This function is optimized for cleaning one queue only on a single
2221 * q_vector!!!
2222 **/
2223static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2224{
2225 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002226 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002227 struct ixgbe_adapter *adapter = q_vector->adapter;
2228 struct ixgbe_ring *tx_ring = NULL;
2229 int work_done = 0;
2230 long r_idx;
2231
Alexander Duyck91281fd2009-06-04 16:00:27 +00002232#ifdef CONFIG_IXGBE_DCA
2233 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002234 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002235#endif
2236
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002237 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2238 tx_ring = adapter->tx_ring[r_idx];
2239
Alexander Duyck91281fd2009-06-04 16:00:27 +00002240 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2241 work_done = budget;
2242
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002243 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002244 if (work_done < budget) {
2245 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002246 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002247 ixgbe_set_itr_msix(q_vector);
2248 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002249 ixgbe_irq_enable_queues(adapter,
2250 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002251 }
2252
2253 return work_done;
2254}
2255
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002257 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002258{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002259 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002260 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002261
2262 set_bit(r_idx, q_vector->rxr_idx);
2263 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002264 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002265}
Auke Kok9a799d72007-09-15 14:07:45 -07002266
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002268 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002270 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002271 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002272
2273 set_bit(t_idx, q_vector->txr_idx);
2274 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002275 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002276}
Auke Kok9a799d72007-09-15 14:07:45 -07002277
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002278/**
2279 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2280 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002281 *
2282 * This function maps descriptor rings to the queue-specific vectors
2283 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2284 * one vector per ring/queue, but on a constrained vector budget, we
2285 * group the rings as "efficiently" as possible. You would add new
2286 * mapping configurations in here.
2287 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002288static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002289{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002290 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002291 int v_start = 0;
2292 int rxr_idx = 0, txr_idx = 0;
2293 int rxr_remaining = adapter->num_rx_queues;
2294 int txr_remaining = adapter->num_tx_queues;
2295 int i, j;
2296 int rqpv, tqpv;
2297 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002298
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002299 /* No mapping required if MSI-X is disabled. */
2300 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002301 goto out;
2302
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002303 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2304
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305 /*
2306 * The ideal configuration...
2307 * We have enough vectors to map one per queue.
2308 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002309 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002310 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2311 map_vector_to_rxq(adapter, v_start, rxr_idx);
2312
2313 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2314 map_vector_to_txq(adapter, v_start, txr_idx);
2315
2316 goto out;
2317 }
2318
2319 /*
2320 * If we don't have enough vectors for a 1-to-1
2321 * mapping, we'll have to group them so there are
2322 * multiple queues per vector.
2323 */
2324 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002325 for (i = v_start; i < q_vectors; i++) {
2326 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002327 for (j = 0; j < rqpv; j++) {
2328 map_vector_to_rxq(adapter, i, rxr_idx);
2329 rxr_idx++;
2330 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002331 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002332 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002333 for (j = 0; j < tqpv; j++) {
2334 map_vector_to_txq(adapter, i, txr_idx);
2335 txr_idx++;
2336 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002337 }
Auke Kok9a799d72007-09-15 14:07:45 -07002338 }
Auke Kok9a799d72007-09-15 14:07:45 -07002339out:
Auke Kok9a799d72007-09-15 14:07:45 -07002340 return err;
2341}
2342
2343/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002344 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2345 * @adapter: board private structure
2346 *
2347 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2348 * interrupts from the kernel.
2349 **/
2350static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2351{
2352 struct net_device *netdev = adapter->netdev;
2353 irqreturn_t (*handler)(int, void *);
2354 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002355 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002356
2357 /* Decrement for Other and TCP Timer vectors */
2358 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2359
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002360 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002361 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002362 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002363
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002364#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2365 ? &ixgbe_msix_clean_many : \
2366 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2367 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2368 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002369 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002370 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2371 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002372
Joe Perchese8e9f692010-09-07 21:34:53 +00002373 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002374 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2375 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002376 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002377 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2378 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002379 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002380 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2381 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002382 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002383 } else {
2384 /* skip this unused q_vector */
2385 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002386 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002387 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002388 handler, 0, q_vector->name,
2389 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002390 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002391 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002392 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002393 goto free_queue_irqs;
2394 }
2395 }
2396
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002397 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002398 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002399 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002400 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002401 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002402 goto free_queue_irqs;
2403 }
2404
2405 return 0;
2406
2407free_queue_irqs:
2408 for (i = vector - 1; i >= 0; i--)
2409 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002410 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002411 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2412 pci_disable_msix(adapter->pdev);
2413 kfree(adapter->msix_entries);
2414 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002415 return err;
2416}
2417
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002418static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2419{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002420 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002421 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2422 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002423 u32 new_itr = q_vector->eitr;
2424 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002425
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002426 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002427 q_vector->tx_itr,
2428 tx_ring->total_packets,
2429 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002430 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002431 q_vector->rx_itr,
2432 rx_ring->total_packets,
2433 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002434
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002435 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002436
2437 switch (current_itr) {
2438 /* counts and packets in update_itr are dependent on these numbers */
2439 case lowest_latency:
2440 new_itr = 100000;
2441 break;
2442 case low_latency:
2443 new_itr = 20000; /* aka hwitr = ~200 */
2444 break;
2445 case bulk_latency:
2446 new_itr = 8000;
2447 break;
2448 default:
2449 break;
2450 }
2451
2452 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002453 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002454 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002455
Alexander Duyck125601b2010-11-16 19:27:08 -08002456 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002457 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002458
2459 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002460 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002461}
2462
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002463/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002464 * ixgbe_irq_enable - Enable default interrupt generation settings
2465 * @adapter: board private structure
2466 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002467static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2468 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002469{
2470 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002471
2472 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002473 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2474 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002475 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2476 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002477 switch (adapter->hw.mac.type) {
2478 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002479 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002480 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002481 mask |= IXGBE_EIMS_GPI_SDP1;
2482 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002483 if (adapter->num_vfs)
2484 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002485 break;
2486 default:
2487 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002488 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002489 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2490 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2491 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002492
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002493 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002494 if (queues)
2495 ixgbe_irq_enable_queues(adapter, ~0);
2496 if (flush)
2497 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002498
2499 if (adapter->num_vfs > 32) {
2500 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2501 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2502 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002503}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002504
2505/**
2506 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002507 * @irq: interrupt number
2508 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002509 **/
2510static irqreturn_t ixgbe_intr(int irq, void *data)
2511{
2512 struct net_device *netdev = data;
2513 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2514 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002515 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002516 u32 eicr;
2517
Don Skidmore54037502009-02-21 15:42:56 -08002518 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002519 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002520 * before the read of EICR.
2521 */
2522 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2523
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002524 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2525 * therefore no explict interrupt disable is necessary */
2526 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002527 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002528 /*
2529 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002530 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002531 * have disabled interrupts due to EIAM
2532 * finish the workaround of silicon errata on 82598. Unmask
2533 * the interrupt that we masked before the EICR read.
2534 */
2535 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2536 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002537 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002538 }
Auke Kok9a799d72007-09-15 14:07:45 -07002539
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002540 if (eicr & IXGBE_EICR_LSC)
2541 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002542
Alexander Duyckbd508172010-11-16 19:27:03 -08002543 switch (hw->mac.type) {
2544 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002545 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002546 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2547 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
2548 adapter->interrupt_event = eicr;
2549 schedule_work(&adapter->check_overtemp_task);
2550 }
2551 break;
2552 default:
2553 break;
2554 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002555
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002556 ixgbe_check_fan_failure(adapter, eicr);
2557
Alexander Duyck7a921c92009-05-06 10:43:28 +00002558 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002559 adapter->tx_ring[0]->total_packets = 0;
2560 adapter->tx_ring[0]->total_bytes = 0;
2561 adapter->rx_ring[0]->total_packets = 0;
2562 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002563 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002564 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002565 }
2566
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002567 /*
2568 * re-enable link(maybe) and non-queue interrupts, no flush.
2569 * ixgbe_poll will re-enable the queue interrupts
2570 */
2571
2572 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2573 ixgbe_irq_enable(adapter, false, false);
2574
Auke Kok9a799d72007-09-15 14:07:45 -07002575 return IRQ_HANDLED;
2576}
2577
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002578static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2579{
2580 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2581
2582 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002583 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002584 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2585 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2586 q_vector->rxr_count = 0;
2587 q_vector->txr_count = 0;
2588 }
2589}
2590
Auke Kok9a799d72007-09-15 14:07:45 -07002591/**
2592 * ixgbe_request_irq - initialize interrupts
2593 * @adapter: board private structure
2594 *
2595 * Attempts to configure interrupts using the best available
2596 * capabilities of the hardware and kernel.
2597 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002598static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002599{
2600 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002601 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002602
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002603 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2604 err = ixgbe_request_msix_irqs(adapter);
2605 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002606 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Joe Perchese8e9f692010-09-07 21:34:53 +00002607 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002608 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002609 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Joe Perchese8e9f692010-09-07 21:34:53 +00002610 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002611 }
2612
Auke Kok9a799d72007-09-15 14:07:45 -07002613 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002614 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002615
Auke Kok9a799d72007-09-15 14:07:45 -07002616 return err;
2617}
2618
2619static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2620{
2621 struct net_device *netdev = adapter->netdev;
2622
2623 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002624 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002625
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002626 q_vectors = adapter->num_msix_vectors;
2627
2628 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002629 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002630
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002631 i--;
2632 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002633 /* free only the irqs that were actually requested */
2634 if (!adapter->q_vector[i]->rxr_count &&
2635 !adapter->q_vector[i]->txr_count)
2636 continue;
2637
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002638 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002639 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002640 }
2641
2642 ixgbe_reset_q_vectors(adapter);
2643 } else {
2644 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002645 }
2646}
2647
2648/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002649 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2650 * @adapter: board private structure
2651 **/
2652static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2653{
Alexander Duyckbd508172010-11-16 19:27:03 -08002654 switch (adapter->hw.mac.type) {
2655 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002656 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002657 break;
2658 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002659 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002660 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2661 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002662 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002663 if (adapter->num_vfs > 32)
2664 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002665 break;
2666 default:
2667 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002668 }
2669 IXGBE_WRITE_FLUSH(&adapter->hw);
2670 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2671 int i;
2672 for (i = 0; i < adapter->num_msix_vectors; i++)
2673 synchronize_irq(adapter->msix_entries[i].vector);
2674 } else {
2675 synchronize_irq(adapter->pdev->irq);
2676 }
2677}
2678
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002679/**
Auke Kok9a799d72007-09-15 14:07:45 -07002680 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2681 *
2682 **/
2683static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2684{
Auke Kok9a799d72007-09-15 14:07:45 -07002685 struct ixgbe_hw *hw = &adapter->hw;
2686
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002687 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002688 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002689
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002690 ixgbe_set_ivar(adapter, 0, 0, 0);
2691 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002692
2693 map_vector_to_rxq(adapter, 0, 0);
2694 map_vector_to_txq(adapter, 0, 0);
2695
Emil Tantilov396e7992010-07-01 20:05:12 +00002696 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002697}
2698
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002699/**
2700 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2701 * @adapter: board private structure
2702 * @ring: structure containing ring specific data
2703 *
2704 * Configure the Tx descriptor ring after a reset.
2705 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002706void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2707 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002708{
2709 struct ixgbe_hw *hw = &adapter->hw;
2710 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002711 int wait_loop = 10;
2712 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002713 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002714
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002715 /* disable queue to avoid issues while updating state */
2716 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2717 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2718 txdctl & ~IXGBE_TXDCTL_ENABLE);
2719 IXGBE_WRITE_FLUSH(hw);
2720
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002721 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002722 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002723 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2724 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2725 ring->count * sizeof(union ixgbe_adv_tx_desc));
2726 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2727 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002728 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002729
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002730 /* configure fetching thresholds */
2731 if (adapter->rx_itr_setting == 0) {
2732 /* cannot set wthresh when itr==0 */
2733 txdctl &= ~0x007F0000;
2734 } else {
2735 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2736 txdctl |= (8 << 16);
2737 }
2738 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2739 /* PThresh workaround for Tx hang with DFP enabled. */
2740 txdctl |= 32;
2741 }
2742
2743 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002744 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2745 adapter->atr_sample_rate) {
2746 ring->atr_sample_rate = adapter->atr_sample_rate;
2747 ring->atr_count = 0;
2748 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2749 } else {
2750 ring->atr_sample_rate = 0;
2751 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002752
John Fastabendc84d3242010-11-16 19:27:12 -08002753 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2754
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002755 /* enable queue */
2756 txdctl |= IXGBE_TXDCTL_ENABLE;
2757 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2758
2759 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2760 if (hw->mac.type == ixgbe_mac_82598EB &&
2761 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2762 return;
2763
2764 /* poll to verify queue is enabled */
2765 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002766 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002767 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2768 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2769 if (!wait_loop)
2770 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002771}
2772
Alexander Duyck120ff942010-08-19 13:34:50 +00002773static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2774{
2775 struct ixgbe_hw *hw = &adapter->hw;
2776 u32 rttdcs;
2777 u32 mask;
2778
2779 if (hw->mac.type == ixgbe_mac_82598EB)
2780 return;
2781
2782 /* disable the arbiter while setting MTQC */
2783 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2784 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2785 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2786
2787 /* set transmit pool layout */
2788 mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
2789 switch (adapter->flags & mask) {
2790
2791 case (IXGBE_FLAG_SRIOV_ENABLED):
2792 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2793 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2794 break;
2795
2796 case (IXGBE_FLAG_DCB_ENABLED):
2797 /* We enable 8 traffic classes, DCB only */
2798 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2799 (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
2800 break;
2801
2802 default:
2803 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2804 break;
2805 }
2806
2807 /* re-enable the arbiter */
2808 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2809 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2810}
2811
Auke Kok9a799d72007-09-15 14:07:45 -07002812/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002813 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002814 * @adapter: board private structure
2815 *
2816 * Configure the Tx unit of the MAC after a reset.
2817 **/
2818static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2819{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002820 struct ixgbe_hw *hw = &adapter->hw;
2821 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002822 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002823
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002824 ixgbe_setup_mtqc(adapter);
2825
2826 if (hw->mac.type != ixgbe_mac_82598EB) {
2827 /* DMATXCTL.EN must be before Tx queues are enabled */
2828 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2829 dmatxctl |= IXGBE_DMATXCTL_TE;
2830 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2831 }
2832
Auke Kok9a799d72007-09-15 14:07:45 -07002833 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002834 for (i = 0; i < adapter->num_tx_queues; i++)
2835 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002836}
2837
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002838#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002839
Yi Zoua6616b42009-08-06 13:05:23 +00002840static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002841 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002842{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002843 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002844 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002845
Alexander Duyckbd508172010-11-16 19:27:03 -08002846 switch (adapter->hw.mac.type) {
2847 case ixgbe_mac_82598EB: {
2848 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2849 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002850 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002851 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002852 break;
2853 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002854 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002855 default:
2856 break;
2857 }
2858
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002859 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002860
2861 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2862 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002863 if (adapter->num_vfs)
2864 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002865
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002866 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2867 IXGBE_SRRCTL_BSIZEHDR_MASK;
2868
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002869 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002870#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2871 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2872#else
2873 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2874#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002875 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002876 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002877 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2878 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002879 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002880 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002881
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002882 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002883}
2884
Alexander Duyck05abb122010-08-19 13:35:41 +00002885static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002886{
Alexander Duyck05abb122010-08-19 13:35:41 +00002887 struct ixgbe_hw *hw = &adapter->hw;
2888 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002889 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2890 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002891 u32 mrqc = 0, reta = 0;
2892 u32 rxcsum;
2893 int i, j;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002894 int mask;
2895
Alexander Duyck05abb122010-08-19 13:35:41 +00002896 /* Fill out hash function seeds */
2897 for (i = 0; i < 10; i++)
2898 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002899
Alexander Duyck05abb122010-08-19 13:35:41 +00002900 /* Fill out redirection table */
2901 for (i = 0, j = 0; i < 128; i++, j++) {
2902 if (j == adapter->ring_feature[RING_F_RSS].indices)
2903 j = 0;
2904 /* reta = 4-byte sliding window of
2905 * 0x00..(indices-1)(indices-1)00..etc. */
2906 reta = (reta << 8) | (j * 0x11);
2907 if ((i & 3) == 3)
2908 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2909 }
2910
2911 /* Disable indicating checksum in descriptor, enables RSS hash */
2912 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2913 rxcsum |= IXGBE_RXCSUM_PCSD;
2914 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2915
2916 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2917 mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
2918 else
2919 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002920#ifdef CONFIG_IXGBE_DCB
Alexander Duyck05abb122010-08-19 13:35:41 +00002921 | IXGBE_FLAG_DCB_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002922#endif
Alexander Duyck05abb122010-08-19 13:35:41 +00002923 | IXGBE_FLAG_SRIOV_ENABLED
2924 );
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002925
2926 switch (mask) {
John Fastabend8187cd42011-02-23 05:58:08 +00002927#ifdef CONFIG_IXGBE_DCB
2928 case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED):
2929 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2930 break;
2931 case (IXGBE_FLAG_DCB_ENABLED):
2932 mrqc = IXGBE_MRQC_RT8TCEN;
2933 break;
2934#endif /* CONFIG_IXGBE_DCB */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002935 case (IXGBE_FLAG_RSS_ENABLED):
2936 mrqc = IXGBE_MRQC_RSSEN;
2937 break;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002938 case (IXGBE_FLAG_SRIOV_ENABLED):
2939 mrqc = IXGBE_MRQC_VMDQEN;
2940 break;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002941 default:
2942 break;
2943 }
2944
Alexander Duyck05abb122010-08-19 13:35:41 +00002945 /* Perform hash on these packet types */
2946 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2947 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2948 | IXGBE_MRQC_RSS_FIELD_IPV6
2949 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2950
2951 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002952}
2953
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002954/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002955 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2956 * @adapter: address of board private structure
2957 * @ring: structure containing ring specific data
2958 **/
2959void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2960 struct ixgbe_ring *ring)
2961{
2962 struct ixgbe_hw *hw = &adapter->hw;
2963 u32 rscctrl;
2964 u8 reg_idx = ring->reg_idx;
2965
2966 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2967 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
2968 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2969}
2970
2971/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002972 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2973 * @adapter: address of board private structure
2974 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002975 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08002976void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002977 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002978{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002979 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002980 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea552009-11-23 10:45:11 -08002981 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002982 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002983
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002984 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002985 return;
2986
2987 rx_buf_len = ring->rx_buf_len;
2988 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002989 rscctrl |= IXGBE_RSCCTL_RSCEN;
2990 /*
2991 * we must limit the number of descriptors so that the
2992 * total size of max desc * buf_len is not greater
2993 * than 65535
2994 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002995 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002996#if (MAX_SKB_FRAGS > 16)
2997 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2998#elif (MAX_SKB_FRAGS > 8)
2999 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3000#elif (MAX_SKB_FRAGS > 4)
3001 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3002#else
3003 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
3004#endif
3005 } else {
3006 if (rx_buf_len < IXGBE_RXBUFFER_4096)
3007 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
3008 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
3009 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
3010 else
3011 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
3012 }
Alexander Duyck73670962010-08-19 13:38:34 +00003013 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00003014}
3015
Alexander Duyck9e10e042010-08-19 13:40:06 +00003016/**
3017 * ixgbe_set_uta - Set unicast filter table address
3018 * @adapter: board private structure
3019 *
3020 * The unicast table address is a register array of 32-bit registers.
3021 * The table is meant to be used in a way similar to how the MTA is used
3022 * however due to certain limitations in the hardware it is necessary to
3023 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3024 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3025 **/
3026static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3027{
3028 struct ixgbe_hw *hw = &adapter->hw;
3029 int i;
3030
3031 /* The UTA table only exists on 82599 hardware and newer */
3032 if (hw->mac.type < ixgbe_mac_82599EB)
3033 return;
3034
3035 /* we only need to do this if VMDq is enabled */
3036 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3037 return;
3038
3039 for (i = 0; i < 128; i++)
3040 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3041}
3042
3043#define IXGBE_MAX_RX_DESC_POLL 10
3044static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3045 struct ixgbe_ring *ring)
3046{
3047 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003048 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3049 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003050 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003051
3052 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3053 if (hw->mac.type == ixgbe_mac_82598EB &&
3054 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3055 return;
3056
3057 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003058 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003059 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3060 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3061
3062 if (!wait_loop) {
3063 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3064 "the polling period\n", reg_idx);
3065 }
3066}
3067
Yi Zou2d39d572011-01-06 14:29:56 +00003068void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3069 struct ixgbe_ring *ring)
3070{
3071 struct ixgbe_hw *hw = &adapter->hw;
3072 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3073 u32 rxdctl;
3074 u8 reg_idx = ring->reg_idx;
3075
3076 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3077 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3078
3079 /* write value back with RXDCTL.ENABLE bit cleared */
3080 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3081
3082 if (hw->mac.type == ixgbe_mac_82598EB &&
3083 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3084 return;
3085
3086 /* the hardware may take up to 100us to really disable the rx queue */
3087 do {
3088 udelay(10);
3089 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3090 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3091
3092 if (!wait_loop) {
3093 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3094 "the polling period\n", reg_idx);
3095 }
3096}
3097
Alexander Duyck84418e32010-08-19 13:40:54 +00003098void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3099 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003100{
3101 struct ixgbe_hw *hw = &adapter->hw;
3102 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003103 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003104 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003105
Alexander Duyck9e10e042010-08-19 13:40:06 +00003106 /* disable queue to avoid issues while updating state */
3107 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003108 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003109
Alexander Duyckacd37172010-08-19 13:36:05 +00003110 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3111 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3112 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3113 ring->count * sizeof(union ixgbe_adv_rx_desc));
3114 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3115 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003116 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003117
3118 ixgbe_configure_srrctl(adapter, ring);
3119 ixgbe_configure_rscctl(adapter, ring);
3120
Greg Rosee9f98072011-01-26 01:06:07 +00003121 /* If operating in IOV mode set RLPML for X540 */
3122 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3123 hw->mac.type == ixgbe_mac_X540) {
3124 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3125 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3126 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3127 }
3128
Alexander Duyck9e10e042010-08-19 13:40:06 +00003129 if (hw->mac.type == ixgbe_mac_82598EB) {
3130 /*
3131 * enable cache line friendly hardware writes:
3132 * PTHRESH=32 descriptors (half the internal cache),
3133 * this also removes ugly rx_no_buffer_count increment
3134 * HTHRESH=4 descriptors (to minimize latency on fetch)
3135 * WTHRESH=8 burst writeback up to two cache lines
3136 */
3137 rxdctl &= ~0x3FFFFF;
3138 rxdctl |= 0x080420;
3139 }
3140
3141 /* enable receive descriptor ring */
3142 rxdctl |= IXGBE_RXDCTL_ENABLE;
3143 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3144
3145 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08003146 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003147}
3148
Alexander Duyck48654522010-08-19 13:36:27 +00003149static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3150{
3151 struct ixgbe_hw *hw = &adapter->hw;
3152 int p;
3153
3154 /* PSRTYPE must be initialized in non 82598 adapters */
3155 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003156 IXGBE_PSRTYPE_UDPHDR |
3157 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003158 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003159 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003160
3161 if (hw->mac.type == ixgbe_mac_82598EB)
3162 return;
3163
3164 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3165 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3166
3167 for (p = 0; p < adapter->num_rx_pools; p++)
3168 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3169 psrtype);
3170}
3171
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003172static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3173{
3174 struct ixgbe_hw *hw = &adapter->hw;
3175 u32 gcr_ext;
3176 u32 vt_reg_bits;
3177 u32 reg_offset, vf_shift;
3178 u32 vmdctl;
3179
3180 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3181 return;
3182
3183 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3184 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3185 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3186 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3187
3188 vf_shift = adapter->num_vfs % 32;
3189 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3190
3191 /* Enable only the PF's pool for Tx/Rx */
3192 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3193 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3194 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3195 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3196 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3197
3198 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3199 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3200
3201 /*
3202 * Set up VF register offsets for selected VT Mode,
3203 * i.e. 32 or 64 VFs for SR-IOV
3204 */
3205 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3206 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3207 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3208 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3209
3210 /* enable Tx loopback for VF/PF communication */
3211 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003212 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003213 hw->mac.ops.set_mac_anti_spoofing(hw,
3214 (adapter->antispoofing_enabled =
3215 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003216 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003217}
3218
Alexander Duyck477de6e2010-08-19 13:38:11 +00003219static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003220{
Auke Kok9a799d72007-09-15 14:07:45 -07003221 struct ixgbe_hw *hw = &adapter->hw;
3222 struct net_device *netdev = adapter->netdev;
3223 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003224 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003225 struct ixgbe_ring *rx_ring;
3226 int i;
3227 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003228
Auke Kok9a799d72007-09-15 14:07:45 -07003229 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003230 /* On by default */
3231 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3232
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003233 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003234 if (adapter->num_vfs)
3235 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3236
3237 /* Disable packet split due to 82599 erratum #45 */
3238 if (hw->mac.type == ixgbe_mac_82599EB)
3239 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003240
3241 /* Set the RX buffer length according to the mode */
3242 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003243 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003244 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003245 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003246 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003247 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003248 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003249 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3250 }
3251
3252#ifdef IXGBE_FCOE
3253 /* adjust max frame to be able to do baby jumbo for FCoE */
3254 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3255 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3256 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3257
3258#endif /* IXGBE_FCOE */
3259 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3260 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3261 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3262 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3263
3264 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003265 }
3266
Auke Kok9a799d72007-09-15 14:07:45 -07003267 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003268 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3269 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003270 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3271
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003272 /*
3273 * Setup the HW Rx Head and Tail Descriptor Pointers and
3274 * the Base and Length of the Rx Descriptor Ring
3275 */
Auke Kok9a799d72007-09-15 14:07:45 -07003276 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003277 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003278 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003279
Yi Zou6e455b892009-08-06 13:05:44 +00003280 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003281 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003282 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003283 clear_ring_ps_enabled(rx_ring);
3284
3285 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3286 set_ring_rsc_enabled(rx_ring);
3287 else
3288 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003289
Yi Zou63f39bd2009-05-17 12:34:35 +00003290#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003291 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003292 struct ixgbe_ring_feature *f;
3293 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003294 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003295 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003296 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3297 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003298 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003299 } else if (!ring_is_rsc_enabled(rx_ring) &&
3300 !ring_is_ps_enabled(rx_ring)) {
3301 rx_ring->rx_buf_len =
3302 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003303 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003304 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003305#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003306 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003307}
3308
Alexander Duyck73670962010-08-19 13:38:34 +00003309static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3310{
3311 struct ixgbe_hw *hw = &adapter->hw;
3312 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3313
3314 switch (hw->mac.type) {
3315 case ixgbe_mac_82598EB:
3316 /*
3317 * For VMDq support of different descriptor types or
3318 * buffer sizes through the use of multiple SRRCTL
3319 * registers, RDRXCTL.MVMEN must be set to 1
3320 *
3321 * also, the manual doesn't mention it clearly but DCA hints
3322 * will only use queue 0's tags unless this bit is set. Side
3323 * effects of setting this bit are only that SRRCTL must be
3324 * fully programmed [0..15]
3325 */
3326 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3327 break;
3328 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003329 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003330 /* Disable RSC for ACK packets */
3331 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3332 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3333 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3334 /* hardware requires some bits to be set by default */
3335 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3336 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3337 break;
3338 default:
3339 /* We should do nothing since we don't know this hardware */
3340 return;
3341 }
3342
3343 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3344}
3345
Alexander Duyck477de6e2010-08-19 13:38:11 +00003346/**
3347 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3348 * @adapter: board private structure
3349 *
3350 * Configure the Rx unit of the MAC after a reset.
3351 **/
3352static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3353{
3354 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003355 int i;
3356 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003357
3358 /* disable receives while setting up the descriptors */
3359 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3360 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3361
3362 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003363 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003364
Alexander Duyck9e10e042010-08-19 13:40:06 +00003365 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003366 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003367
Alexander Duyck9e10e042010-08-19 13:40:06 +00003368 ixgbe_set_uta(adapter);
3369
Alexander Duyck477de6e2010-08-19 13:38:11 +00003370 /* set_rx_buffer_len must be called before ring initialization */
3371 ixgbe_set_rx_buffer_len(adapter);
3372
3373 /*
3374 * Setup the HW Rx Head and Tail Descriptor Pointers and
3375 * the Base and Length of the Rx Descriptor Ring
3376 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003377 for (i = 0; i < adapter->num_rx_queues; i++)
3378 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003379
Alexander Duyck9e10e042010-08-19 13:40:06 +00003380 /* disable drop enable for 82598 parts */
3381 if (hw->mac.type == ixgbe_mac_82598EB)
3382 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3383
3384 /* enable all receives */
3385 rxctrl |= IXGBE_RXCTRL_RXEN;
3386 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003387}
3388
Auke Kok9a799d72007-09-15 14:07:45 -07003389static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3390{
3391 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003392 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003393 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003394
3395 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003396 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003397 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003398}
3399
3400static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3401{
3402 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003403 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003404 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003405
Auke Kok9a799d72007-09-15 14:07:45 -07003406 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003407 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003408 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003409}
3410
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003411/**
3412 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3413 * @adapter: driver data
3414 */
3415static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3416{
3417 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003418 u32 vlnctrl;
3419
3420 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3421 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3422 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3423}
3424
3425/**
3426 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3427 * @adapter: driver data
3428 */
3429static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3430{
3431 struct ixgbe_hw *hw = &adapter->hw;
3432 u32 vlnctrl;
3433
3434 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3435 vlnctrl |= IXGBE_VLNCTRL_VFE;
3436 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3437 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3438}
3439
3440/**
3441 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3442 * @adapter: driver data
3443 */
3444static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3445{
3446 struct ixgbe_hw *hw = &adapter->hw;
3447 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003448 int i, j;
3449
3450 switch (hw->mac.type) {
3451 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003452 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3453 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003454 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3455 break;
3456 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003457 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003458 for (i = 0; i < adapter->num_rx_queues; i++) {
3459 j = adapter->rx_ring[i]->reg_idx;
3460 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3461 vlnctrl &= ~IXGBE_RXDCTL_VME;
3462 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3463 }
3464 break;
3465 default:
3466 break;
3467 }
3468}
3469
3470/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003471 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003472 * @adapter: driver data
3473 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003474static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003475{
3476 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003477 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003478 int i, j;
3479
3480 switch (hw->mac.type) {
3481 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003482 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3483 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003484 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3485 break;
3486 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003487 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003488 for (i = 0; i < adapter->num_rx_queues; i++) {
3489 j = adapter->rx_ring[i]->reg_idx;
3490 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3491 vlnctrl |= IXGBE_RXDCTL_VME;
3492 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3493 }
3494 break;
3495 default:
3496 break;
3497 }
3498}
3499
Auke Kok9a799d72007-09-15 14:07:45 -07003500static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3501{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003502 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003503
Jesse Grossf62bbb52010-10-20 13:56:10 +00003504 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3505
3506 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3507 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003508}
3509
3510/**
Alexander Duyck28500622010-06-15 09:25:48 +00003511 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3512 * @netdev: network interface device structure
3513 *
3514 * Writes unicast address list to the RAR table.
3515 * Returns: -ENOMEM on failure/insufficient address space
3516 * 0 on no addresses written
3517 * X on writing X addresses to the RAR table
3518 **/
3519static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3520{
3521 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3522 struct ixgbe_hw *hw = &adapter->hw;
3523 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00003524 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003525 int count = 0;
3526
3527 /* return ENOMEM indicating insufficient memory for addresses */
3528 if (netdev_uc_count(netdev) > rar_entries)
3529 return -ENOMEM;
3530
3531 if (!netdev_uc_empty(netdev) && rar_entries) {
3532 struct netdev_hw_addr *ha;
3533 /* return error if we do not support writing to RAR table */
3534 if (!hw->mac.ops.set_rar)
3535 return -ENOMEM;
3536
3537 netdev_for_each_uc_addr(ha, netdev) {
3538 if (!rar_entries)
3539 break;
3540 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3541 vfn, IXGBE_RAH_AV);
3542 count++;
3543 }
3544 }
3545 /* write the addresses in reverse order to avoid write combining */
3546 for (; rar_entries > 0 ; rar_entries--)
3547 hw->mac.ops.clear_rar(hw, rar_entries);
3548
3549 return count;
3550}
3551
3552/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003553 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003554 * @netdev: network interface device structure
3555 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003556 * The set_rx_method entry point is called whenever the unicast/multicast
3557 * address list or the network interface flags are updated. This routine is
3558 * responsible for configuring the hardware for proper unicast, multicast and
3559 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003560 **/
Greg Rose7f870472010-01-09 02:25:29 +00003561void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003562{
3563 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3564 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003565 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3566 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003567
3568 /* Check for Promiscuous and All Multicast modes */
3569
3570 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3571
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003572 /* set all bits that we expect to always be set */
3573 fctrl |= IXGBE_FCTRL_BAM;
3574 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3575 fctrl |= IXGBE_FCTRL_PMCF;
3576
Alexander Duyck28500622010-06-15 09:25:48 +00003577 /* clear the bits we are changing the status of */
3578 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3579
Auke Kok9a799d72007-09-15 14:07:45 -07003580 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003581 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003582 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003583 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003584 /* don't hardware filter vlans in promisc mode */
3585 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003586 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003587 if (netdev->flags & IFF_ALLMULTI) {
3588 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003589 vmolr |= IXGBE_VMOLR_MPE;
3590 } else {
3591 /*
3592 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003593 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003594 * that we can at least receive multicast traffic
3595 */
3596 hw->mac.ops.update_mc_addr_list(hw, netdev);
3597 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003598 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003599 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003600 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003601 /*
3602 * Write addresses to available RAR registers, if there is not
3603 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003604 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003605 */
3606 count = ixgbe_write_uc_addr_list(netdev);
3607 if (count < 0) {
3608 fctrl |= IXGBE_FCTRL_UPE;
3609 vmolr |= IXGBE_VMOLR_ROPE;
3610 }
3611 }
3612
3613 if (adapter->num_vfs) {
3614 ixgbe_restore_vf_multicasts(adapter);
3615 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3616 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3617 IXGBE_VMOLR_ROPE);
3618 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003619 }
3620
3621 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003622
3623 if (netdev->features & NETIF_F_HW_VLAN_RX)
3624 ixgbe_vlan_strip_enable(adapter);
3625 else
3626 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003627}
3628
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003629static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3630{
3631 int q_idx;
3632 struct ixgbe_q_vector *q_vector;
3633 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3634
3635 /* legacy and MSI only use one vector */
3636 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3637 q_vectors = 1;
3638
3639 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003640 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003641 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003642 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003643 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3644 if (!q_vector->rxr_count || !q_vector->txr_count) {
3645 if (q_vector->txr_count == 1)
3646 napi->poll = &ixgbe_clean_txonly;
3647 else if (q_vector->rxr_count == 1)
3648 napi->poll = &ixgbe_clean_rxonly;
3649 }
3650 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003651
3652 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003653 }
3654}
3655
3656static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3657{
3658 int q_idx;
3659 struct ixgbe_q_vector *q_vector;
3660 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3661
3662 /* legacy and MSI only use one vector */
3663 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3664 q_vectors = 1;
3665
3666 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003667 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003668 napi_disable(&q_vector->napi);
3669 }
3670}
3671
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003672#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003673/*
3674 * ixgbe_configure_dcb - Configure DCB hardware
3675 * @adapter: ixgbe adapter struct
3676 *
3677 * This is called by the driver on open to configure the DCB hardware.
3678 * This is also called by the gennetlink interface when reconfiguring
3679 * the DCB state.
3680 */
3681static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3682{
3683 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend9806307a2010-10-28 00:59:57 +00003684 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003685
Alexander Duyck67ebd792010-08-19 13:34:04 +00003686 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3687 if (hw->mac.type == ixgbe_mac_82598EB)
3688 netif_set_gso_max_size(adapter->netdev, 65536);
3689 return;
3690 }
3691
3692 if (hw->mac.type == ixgbe_mac_82598EB)
3693 netif_set_gso_max_size(adapter->netdev, 32768);
3694
Alexander Duyck2f90b862008-11-20 20:52:10 -08003695
Alexander Duyck2f90b862008-11-20 20:52:10 -08003696 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003697 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003698
Alexander Duyck2f90b862008-11-20 20:52:10 -08003699 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003700
3701 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003702 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3703#ifdef CONFIG_FCOE
3704 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3705 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3706#endif
3707 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3708 DCB_TX_CONFIG);
3709 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3710 DCB_RX_CONFIG);
3711 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3712 } else {
3713 struct net_device *dev = adapter->netdev;
3714
3715 if (adapter->ixgbe_ieee_ets)
3716 dev->dcbnl_ops->ieee_setets(dev,
3717 adapter->ixgbe_ieee_ets);
3718 if (adapter->ixgbe_ieee_pfc)
3719 dev->dcbnl_ops->ieee_setpfc(dev,
3720 adapter->ixgbe_ieee_pfc);
3721 }
John Fastabend8187cd42011-02-23 05:58:08 +00003722
3723 /* Enable RSS Hash per TC */
3724 if (hw->mac.type != ixgbe_mac_82598EB) {
3725 int i;
3726 u32 reg = 0;
3727
3728 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3729 u8 msb = 0;
3730 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3731
3732 while (cnt >>= 1)
3733 msb++;
3734
3735 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3736 }
3737 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3738 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003739}
3740
3741#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003742static void ixgbe_configure(struct ixgbe_adapter *adapter)
3743{
3744 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003745 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003746 int i;
3747
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003748#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003749 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003750#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003751
Jesse Grossf62bbb52010-10-20 13:56:10 +00003752 ixgbe_set_rx_mode(netdev);
3753 ixgbe_restore_vlan(adapter);
3754
Yi Zoueacd73f2009-05-13 13:11:06 +00003755#ifdef IXGBE_FCOE
3756 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3757 ixgbe_configure_fcoe(adapter);
3758
3759#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003760 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3761 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003762 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003763 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003764 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3765 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3766 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3767 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003768 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003769
Auke Kok9a799d72007-09-15 14:07:45 -07003770 ixgbe_configure_tx(adapter);
3771 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003772}
3773
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003774static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3775{
3776 switch (hw->phy.type) {
3777 case ixgbe_phy_sfp_avago:
3778 case ixgbe_phy_sfp_ftl:
3779 case ixgbe_phy_sfp_intel:
3780 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003781 case ixgbe_phy_sfp_passive_tyco:
3782 case ixgbe_phy_sfp_passive_unknown:
3783 case ixgbe_phy_sfp_active_unknown:
3784 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003785 return true;
3786 default:
3787 return false;
3788 }
3789}
3790
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003791/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003792 * ixgbe_sfp_link_config - set up SFP+ link
3793 * @adapter: pointer to private adapter struct
3794 **/
3795static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3796{
Alexander Duyck70864002011-04-27 09:13:56 +00003797 /*
3798 * We are assuming the worst case scenerio here, and that
3799 * is that an SFP was inserted/removed after the reset
3800 * but before SFP detection was enabled. As such the best
3801 * solution is to just start searching as soon as we start
3802 */
3803 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
3804 adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003805
Alexander Duyck70864002011-04-27 09:13:56 +00003806 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003807}
3808
3809/**
3810 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003811 * @hw: pointer to private hardware struct
3812 *
3813 * Returns 0 on success, negative on failure
3814 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003815static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003816{
3817 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003818 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003819 u32 ret = IXGBE_ERR_LINK_SETUP;
3820
3821 if (hw->mac.ops.check_link)
3822 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3823
3824 if (ret)
3825 goto link_cfg_out;
3826
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003827 autoneg = hw->phy.autoneg_advertised;
3828 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003829 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3830 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003831 if (ret)
3832 goto link_cfg_out;
3833
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003834 if (hw->mac.ops.setup_link)
3835 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003836link_cfg_out:
3837 return ret;
3838}
3839
Alexander Duycka34bcff2010-08-19 13:39:20 +00003840static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003841{
Auke Kok9a799d72007-09-15 14:07:45 -07003842 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003843 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003844
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003845 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003846 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3847 IXGBE_GPIE_OCD;
3848 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003849 /*
3850 * use EIAM to auto-mask when MSI-X interrupt is asserted
3851 * this saves a register write for every interrupt
3852 */
3853 switch (hw->mac.type) {
3854 case ixgbe_mac_82598EB:
3855 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3856 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003857 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003858 case ixgbe_mac_X540:
3859 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003860 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3861 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3862 break;
3863 }
3864 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003865 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3866 * specifically only auto mask tx and rx interrupts */
3867 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003868 }
3869
Alexander Duycka34bcff2010-08-19 13:39:20 +00003870 /* XXX: to interrupt immediately for EICS writes, enable this */
3871 /* gpie |= IXGBE_GPIE_EIMEN; */
3872
3873 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3874 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3875 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003876 }
3877
Alexander Duycka34bcff2010-08-19 13:39:20 +00003878 /* Enable fan failure interrupt */
3879 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003880 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003881
Don Skidmore2698b202011-04-13 07:01:52 +00003882 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003883 gpie |= IXGBE_SDP1_GPIEN;
3884 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003885 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003886
3887 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3888}
3889
3890static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3891{
3892 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003893 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003894 u32 ctrl_ext;
3895
3896 ixgbe_get_hw_control(adapter);
3897 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003898
Auke Kok9a799d72007-09-15 14:07:45 -07003899 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3900 ixgbe_configure_msix(adapter);
3901 else
3902 ixgbe_configure_msi_and_legacy(adapter);
3903
Don Skidmorec6ecf392010-12-03 03:31:51 +00003904 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3905 if (hw->mac.ops.enable_tx_laser &&
3906 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003907 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003908 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003909 hw->mac.ops.enable_tx_laser(hw);
3910
Auke Kok9a799d72007-09-15 14:07:45 -07003911 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003912 ixgbe_napi_enable_all(adapter);
3913
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003914 if (ixgbe_is_sfp(hw)) {
3915 ixgbe_sfp_link_config(adapter);
3916 } else {
3917 err = ixgbe_non_sfp_link_config(hw);
3918 if (err)
3919 e_err(probe, "link_config FAILED %d\n", err);
3920 }
3921
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003922 /* clear any pending interrupts, may auto mask */
3923 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003924 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003925
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003926 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003927 * If this adapter has a fan, check to see if we had a failure
3928 * before we enabled the interrupt.
3929 */
3930 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3931 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3932 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003933 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003934 }
3935
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003936 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003937 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003938
Auke Kok9a799d72007-09-15 14:07:45 -07003939 /* bring the link up in the watchdog, this could race with our first
3940 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003941 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3942 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07003943 mod_timer(&adapter->watchdog_timer, jiffies);
Alexander Duyck70864002011-04-27 09:13:56 +00003944 mod_timer(&adapter->service_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003945
3946 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3947 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3948 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3949 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3950
Auke Kok9a799d72007-09-15 14:07:45 -07003951 return 0;
3952}
3953
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003954void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3955{
3956 WARN_ON(in_interrupt());
Alexander Duyck70864002011-04-27 09:13:56 +00003957 /* put off any impending NetWatchDogTimeout */
3958 adapter->netdev->trans_start = jiffies;
3959
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003960 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003961 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003962 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003963 /*
3964 * If SR-IOV enabled then wait a bit before bringing the adapter
3965 * back up to give the VFs time to respond to the reset. The
3966 * two second wait is based upon the watchdog timer cycle in
3967 * the VF driver.
3968 */
3969 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3970 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003971 ixgbe_up(adapter);
3972 clear_bit(__IXGBE_RESETTING, &adapter->state);
3973}
3974
Auke Kok9a799d72007-09-15 14:07:45 -07003975int ixgbe_up(struct ixgbe_adapter *adapter)
3976{
3977 /* hardware has been reset, we need to reload some things */
3978 ixgbe_configure(adapter);
3979
3980 return ixgbe_up_complete(adapter);
3981}
3982
3983void ixgbe_reset(struct ixgbe_adapter *adapter)
3984{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003985 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003986 int err;
3987
Alexander Duyck70864002011-04-27 09:13:56 +00003988 /* lock SFP init bit to prevent race conditions with the watchdog */
3989 while (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
3990 usleep_range(1000, 2000);
3991
3992 /* clear all SFP and link config related flags while holding SFP_INIT */
3993 adapter->flags2 &= ~(IXGBE_FLAG2_SEARCH_FOR_SFP |
3994 IXGBE_FLAG2_SFP_NEEDS_RESET);
3995 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
3996
Don Skidmore8ca783a2009-05-26 20:40:47 -07003997 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003998 switch (err) {
3999 case 0:
4000 case IXGBE_ERR_SFP_NOT_PRESENT:
Alexander Duyck70864002011-04-27 09:13:56 +00004001 case IXGBE_ERR_SFP_NOT_SUPPORTED:
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004002 break;
4003 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00004004 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004005 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004006 case IXGBE_ERR_EEPROM_VERSION:
4007 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00004008 e_dev_warn("This device is a pre-production adapter/LOM. "
4009 "Please be aware there may be issuesassociated with "
4010 "your hardware. If you are experiencing problems "
4011 "please contact your Intel or hardware "
4012 "representative who provided you with this "
4013 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004014 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004015 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004016 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004017 }
Auke Kok9a799d72007-09-15 14:07:45 -07004018
Alexander Duyck70864002011-04-27 09:13:56 +00004019 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
4020
Auke Kok9a799d72007-09-15 14:07:45 -07004021 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004022 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4023 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004024}
4025
Auke Kok9a799d72007-09-15 14:07:45 -07004026/**
4027 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004028 * @rx_ring: ring to free buffers from
4029 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004030static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004031{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004032 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004033 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004034 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004035
Alexander Duyck84418e32010-08-19 13:40:54 +00004036 /* ring already cleared, nothing to do */
4037 if (!rx_ring->rx_buffer_info)
4038 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004039
Alexander Duyck84418e32010-08-19 13:40:54 +00004040 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004041 for (i = 0; i < rx_ring->count; i++) {
4042 struct ixgbe_rx_buffer *rx_buffer_info;
4043
4044 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4045 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004046 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004047 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004048 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004049 rx_buffer_info->dma = 0;
4050 }
4051 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004052 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004053 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004054 do {
4055 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004056 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004057 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004058 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004059 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004060 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004061 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004062 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004063 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004064 skb = skb->prev;
4065 dev_kfree_skb(this);
4066 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004067 }
4068 if (!rx_buffer_info->page)
4069 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004070 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004071 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004072 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004073 rx_buffer_info->page_dma = 0;
4074 }
Auke Kok9a799d72007-09-15 14:07:45 -07004075 put_page(rx_buffer_info->page);
4076 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004077 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004078 }
4079
4080 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4081 memset(rx_ring->rx_buffer_info, 0, size);
4082
4083 /* Zero out the descriptor ring */
4084 memset(rx_ring->desc, 0, rx_ring->size);
4085
4086 rx_ring->next_to_clean = 0;
4087 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004088}
4089
4090/**
4091 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004092 * @tx_ring: ring to be cleaned
4093 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004094static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004095{
4096 struct ixgbe_tx_buffer *tx_buffer_info;
4097 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004098 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004099
Alexander Duyck84418e32010-08-19 13:40:54 +00004100 /* ring already cleared, nothing to do */
4101 if (!tx_ring->tx_buffer_info)
4102 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004103
Alexander Duyck84418e32010-08-19 13:40:54 +00004104 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004105 for (i = 0; i < tx_ring->count; i++) {
4106 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004107 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004108 }
4109
4110 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4111 memset(tx_ring->tx_buffer_info, 0, size);
4112
4113 /* Zero out the descriptor ring */
4114 memset(tx_ring->desc, 0, tx_ring->size);
4115
4116 tx_ring->next_to_use = 0;
4117 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004118}
4119
4120/**
Auke Kok9a799d72007-09-15 14:07:45 -07004121 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4122 * @adapter: board private structure
4123 **/
4124static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4125{
4126 int i;
4127
4128 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004129 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004130}
4131
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004132/**
4133 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4134 * @adapter: board private structure
4135 **/
4136static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4137{
4138 int i;
4139
4140 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004141 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004142}
4143
Auke Kok9a799d72007-09-15 14:07:45 -07004144void ixgbe_down(struct ixgbe_adapter *adapter)
4145{
4146 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004147 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004148 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004149 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004150 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004151 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004152
4153 /* signal that we are down to the interrupt handler */
4154 set_bit(__IXGBE_DOWN, &adapter->state);
4155
Greg Rose767081a2010-01-22 22:46:40 +00004156 /* disable receive for all VFs and wait one second */
4157 if (adapter->num_vfs) {
Greg Rose767081a2010-01-22 22:46:40 +00004158 /* ping all the active vfs to let them know we are going down */
4159 ixgbe_ping_all_vfs(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004160
Greg Rose767081a2010-01-22 22:46:40 +00004161 /* Disable all VFTE/VFRE TX/RX */
4162 ixgbe_disable_tx_rx(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004163
4164 /* Mark all the VFs as inactive */
4165 for (i = 0 ; i < adapter->num_vfs; i++)
4166 adapter->vfinfo[i].clear_to_send = 0;
Greg Rose767081a2010-01-22 22:46:40 +00004167 }
4168
Auke Kok9a799d72007-09-15 14:07:45 -07004169 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004170 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4171 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004172
Yi Zou2d39d572011-01-06 14:29:56 +00004173 /* disable all enabled rx queues */
4174 for (i = 0; i < adapter->num_rx_queues; i++)
4175 /* this call also flushes the previous write */
4176 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4177
Don Skidmore032b4322011-03-18 09:32:53 +00004178 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004179
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004180 netif_tx_stop_all_queues(netdev);
4181
Auke Kok9a799d72007-09-15 14:07:45 -07004182 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004183 cancel_work_sync(&adapter->watchdog_task);
Alexander Duyck70864002011-04-27 09:13:56 +00004184 /* call carrier off first to avoid false dev_watchdog timeouts */
John Fastabendc0dfb902010-04-27 02:13:39 +00004185 netif_carrier_off(netdev);
4186 netif_tx_disable(netdev);
4187
4188 ixgbe_irq_disable(adapter);
4189
4190 ixgbe_napi_disable_all(adapter);
4191
Alexander Duyck70864002011-04-27 09:13:56 +00004192 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
4193
4194 del_timer_sync(&adapter->service_timer);
4195
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004196 /* Cleanup the affinity_hint CPU mask memory and callback */
4197 for (i = 0; i < num_q_vectors; i++) {
4198 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4199 /* clear the affinity_mask in the IRQ descriptor */
4200 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4201 /* release the CPU mask memory */
4202 free_cpumask_var(q_vector->affinity_mask);
4203 }
4204
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004205 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4206 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
4207 cancel_work_sync(&adapter->fdir_reinit_task);
4208
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004209 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
4210 cancel_work_sync(&adapter->check_overtemp_task);
4211
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004212 /* disable transmits in the hardware now that interrupts are off */
4213 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004214 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4215 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
4216 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00004217 (txdctl & ~IXGBE_TXDCTL_ENABLE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004218 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00004219 /* Disable the Tx DMA engine on 82599 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004220 switch (hw->mac.type) {
4221 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004222 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004223 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004224 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4225 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004226 break;
4227 default:
4228 break;
4229 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004230
Paul Larson6f4a0e42008-06-24 17:00:56 -07004231 if (!pci_channel_offline(adapter->pdev))
4232 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004233
4234 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4235 if (hw->mac.ops.disable_tx_laser &&
4236 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004237 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004238 (hw->mac.type == ixgbe_mac_82599EB))))
4239 hw->mac.ops.disable_tx_laser(hw);
4240
Auke Kok9a799d72007-09-15 14:07:45 -07004241 ixgbe_clean_all_tx_rings(adapter);
4242 ixgbe_clean_all_rx_rings(adapter);
4243
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004244#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004245 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004246 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004247#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004248}
4249
Auke Kok9a799d72007-09-15 14:07:45 -07004250/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004251 * ixgbe_poll - NAPI Rx polling callback
4252 * @napi: structure for representing this polling device
4253 * @budget: how many packets driver is allowed to clean
4254 *
4255 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004256 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004257static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004258{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004259 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004260 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004261 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004262 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004263
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004264#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004265 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4266 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004267#endif
4268
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004269 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4270 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004271
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004272 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004273 work_done = budget;
4274
David S. Miller53e52c72008-01-07 21:06:12 -08004275 /* If budget not fully consumed, exit the polling mode */
4276 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004277 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004278 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004279 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004280 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004281 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004282 }
Auke Kok9a799d72007-09-15 14:07:45 -07004283 return work_done;
4284}
4285
4286/**
4287 * ixgbe_tx_timeout - Respond to a Tx Hang
4288 * @netdev: network interface device structure
4289 **/
4290static void ixgbe_tx_timeout(struct net_device *netdev)
4291{
4292 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4293
John Fastabendc84d3242010-11-16 19:27:12 -08004294 adapter->tx_timeout_count++;
4295
Auke Kok9a799d72007-09-15 14:07:45 -07004296 /* Do the reset outside of interrupt context */
4297 schedule_work(&adapter->reset_task);
4298}
4299
4300static void ixgbe_reset_task(struct work_struct *work)
4301{
4302 struct ixgbe_adapter *adapter;
4303 adapter = container_of(work, struct ixgbe_adapter, reset_task);
4304
Alexander Duyck2f90b862008-11-20 20:52:10 -08004305 /* If we're already down or resetting, just bail */
4306 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4307 test_bit(__IXGBE_RESETTING, &adapter->state))
4308 return;
4309
Taku Izumidcd79ae2010-04-27 14:39:53 +00004310 ixgbe_dump(adapter);
4311 netdev_err(adapter->netdev, "Reset adapter\n");
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004312 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004313}
4314
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004315/**
4316 * ixgbe_set_rss_queues: Allocate queues for RSS
4317 * @adapter: board private structure to initialize
4318 *
4319 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4320 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4321 *
4322 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004323static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4324{
4325 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004326 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004327
4328 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004329 f->mask = 0xF;
4330 adapter->num_rx_queues = f->indices;
4331 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004332 ret = true;
4333 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004334 ret = false;
4335 }
4336
4337 return ret;
4338}
4339
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004340/**
4341 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4342 * @adapter: board private structure to initialize
4343 *
4344 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4345 * to the original CPU that initiated the Tx session. This runs in addition
4346 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4347 * Rx load across CPUs using RSS.
4348 *
4349 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004350static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004351{
4352 bool ret = false;
4353 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4354
4355 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4356 f_fdir->mask = 0;
4357
4358 /* Flow Director must have RSS enabled */
4359 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4360 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4361 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4362 adapter->num_tx_queues = f_fdir->indices;
4363 adapter->num_rx_queues = f_fdir->indices;
4364 ret = true;
4365 } else {
4366 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4367 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4368 }
4369 return ret;
4370}
4371
Yi Zou0331a832009-05-17 12:33:52 +00004372#ifdef IXGBE_FCOE
4373/**
4374 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4375 * @adapter: board private structure to initialize
4376 *
4377 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4378 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4379 * rx queues out of the max number of rx queues, instead, it is used as the
4380 * index of the first rx queue used by FCoE.
4381 *
4382 **/
4383static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4384{
Yi Zou0331a832009-05-17 12:33:52 +00004385 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4386
John Fastabende5b64632011-03-08 03:44:52 +00004387 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4388 return false;
4389
4390 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4391#ifdef CONFIG_IXGBE_DCB
4392 int tc;
4393 struct net_device *dev = adapter->netdev;
4394
4395 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4396 f->indices = dev->tc_to_txq[tc].count;
4397 f->mask = dev->tc_to_txq[tc].offset;
4398#endif
4399 } else {
4400 f->indices = min((int)num_online_cpus(), f->indices);
4401
Yi Zou8de8b2e2009-09-03 14:55:50 +00004402 adapter->num_rx_queues = 1;
4403 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004404
Yi Zou0331a832009-05-17 12:33:52 +00004405 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004406 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004407 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4408 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4409 ixgbe_set_fdir_queues(adapter);
4410 else
4411 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004412 }
4413 /* adding FCoE rx rings to the end */
4414 f->mask = adapter->num_rx_queues;
4415 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004416 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004417 }
4418
John Fastabende5b64632011-03-08 03:44:52 +00004419 return true;
4420}
4421#endif /* IXGBE_FCOE */
4422
4423#ifdef CONFIG_IXGBE_DCB
4424static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4425{
4426 bool ret = false;
4427 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4428 int i, q;
4429
4430 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4431 return ret;
4432
4433 f->indices = 0;
4434 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4435 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4436 f->indices += q;
4437 }
4438
4439 f->mask = 0x7 << 3;
4440 adapter->num_rx_queues = f->indices;
4441 adapter->num_tx_queues = f->indices;
4442 ret = true;
4443
4444#ifdef IXGBE_FCOE
4445 /* FCoE enabled queues require special configuration done through
4446 * configure_fcoe() and others. Here we map FCoE indices onto the
4447 * DCB queue pairs allowing FCoE to own configuration later.
4448 */
4449 ixgbe_set_fcoe_queues(adapter);
4450#endif
4451
Yi Zou0331a832009-05-17 12:33:52 +00004452 return ret;
4453}
John Fastabende5b64632011-03-08 03:44:52 +00004454#endif
Yi Zou0331a832009-05-17 12:33:52 +00004455
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004456/**
4457 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4458 * @adapter: board private structure to initialize
4459 *
4460 * IOV doesn't actually use anything, so just NAK the
4461 * request for now and let the other queue routines
4462 * figure out what to do.
4463 */
4464static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4465{
4466 return false;
4467}
4468
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004469/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004470 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004471 * @adapter: board private structure to initialize
4472 *
4473 * This is the top level queue allocation routine. The order here is very
4474 * important, starting with the "most" number of features turned on at once,
4475 * and ending with the smallest set of features. This way large combinations
4476 * can be allocated if they're turned on, and smaller combinations are the
4477 * fallthrough conditions.
4478 *
4479 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004480static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004481{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004482 /* Start with base case */
4483 adapter->num_rx_queues = 1;
4484 adapter->num_tx_queues = 1;
4485 adapter->num_rx_pools = adapter->num_rx_queues;
4486 adapter->num_rx_queues_per_pool = 1;
4487
4488 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004489 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004490
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004491#ifdef CONFIG_IXGBE_DCB
4492 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004493 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004494
4495#endif
John Fastabende5b64632011-03-08 03:44:52 +00004496#ifdef IXGBE_FCOE
4497 if (ixgbe_set_fcoe_queues(adapter))
4498 goto done;
4499
4500#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004501 if (ixgbe_set_fdir_queues(adapter))
4502 goto done;
4503
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004504 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004505 goto done;
4506
4507 /* fallback to base case */
4508 adapter->num_rx_queues = 1;
4509 adapter->num_tx_queues = 1;
4510
4511done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004512 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004513 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004514 return netif_set_real_num_rx_queues(adapter->netdev,
4515 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004516}
4517
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004518static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004519 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004520{
4521 int err, vector_threshold;
4522
4523 /* We'll want at least 3 (vector_threshold):
4524 * 1) TxQ[0] Cleanup
4525 * 2) RxQ[0] Cleanup
4526 * 3) Other (Link Status Change, etc.)
4527 * 4) TCP Timer (optional)
4528 */
4529 vector_threshold = MIN_MSIX_COUNT;
4530
4531 /* The more we get, the more we will assign to Tx/Rx Cleanup
4532 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4533 * Right now, we simply care about how many we'll get; we'll
4534 * set them up later while requesting irq's.
4535 */
4536 while (vectors >= vector_threshold) {
4537 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004538 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004539 if (!err) /* Success in acquiring all requested vectors. */
4540 break;
4541 else if (err < 0)
4542 vectors = 0; /* Nasty failure, quit now */
4543 else /* err == number of vectors we should try again with */
4544 vectors = err;
4545 }
4546
4547 if (vectors < vector_threshold) {
4548 /* Can't allocate enough MSI-X interrupts? Oh well.
4549 * This just means we'll go with either a single MSI
4550 * vector or fall back to legacy interrupts.
4551 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004552 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4553 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004554 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4555 kfree(adapter->msix_entries);
4556 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004557 } else {
4558 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004559 /*
4560 * Adjust for only the vectors we'll use, which is minimum
4561 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4562 * vectors we were allocated.
4563 */
4564 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004565 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004566 }
4567}
4568
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004569/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004570 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004571 * @adapter: board private structure to initialize
4572 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004573 * Cache the descriptor ring offsets for RSS to the assigned rings.
4574 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004575 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004576static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004577{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004578 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004579
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004580 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4581 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004582
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004583 for (i = 0; i < adapter->num_rx_queues; i++)
4584 adapter->rx_ring[i]->reg_idx = i;
4585 for (i = 0; i < adapter->num_tx_queues; i++)
4586 adapter->tx_ring[i]->reg_idx = i;
4587
4588 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004589}
4590
4591#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004592
4593/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004594static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4595 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004596{
4597 struct net_device *dev = adapter->netdev;
4598 struct ixgbe_hw *hw = &adapter->hw;
4599 u8 num_tcs = netdev_get_num_tc(dev);
4600
4601 *tx = 0;
4602 *rx = 0;
4603
4604 switch (hw->mac.type) {
4605 case ixgbe_mac_82598EB:
4606 *tx = tc << 3;
4607 *rx = tc << 2;
4608 break;
4609 case ixgbe_mac_82599EB:
4610 case ixgbe_mac_X540:
4611 if (num_tcs == 8) {
4612 if (tc < 3) {
4613 *tx = tc << 5;
4614 *rx = tc << 4;
4615 } else if (tc < 5) {
4616 *tx = ((tc + 2) << 4);
4617 *rx = tc << 4;
4618 } else if (tc < num_tcs) {
4619 *tx = ((tc + 8) << 3);
4620 *rx = tc << 4;
4621 }
4622 } else if (num_tcs == 4) {
4623 *rx = tc << 5;
4624 switch (tc) {
4625 case 0:
4626 *tx = 0;
4627 break;
4628 case 1:
4629 *tx = 64;
4630 break;
4631 case 2:
4632 *tx = 96;
4633 break;
4634 case 3:
4635 *tx = 112;
4636 break;
4637 default:
4638 break;
4639 }
4640 }
4641 break;
4642 default:
4643 break;
4644 }
4645}
4646
4647#define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4648
4649/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4650 * classes.
4651 *
4652 * @netdev: net device to configure
4653 * @tc: number of traffic classes to enable
4654 */
4655int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4656{
4657 int i;
4658 unsigned int q, offset = 0;
4659
4660 if (!tc) {
4661 netdev_reset_tc(dev);
4662 } else {
John Fastabend24095aa2011-02-23 05:58:03 +00004663 struct ixgbe_adapter *adapter = netdev_priv(dev);
4664
4665 /* Hardware supports up to 8 traffic classes */
4666 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
John Fastabende5b64632011-03-08 03:44:52 +00004667 return -EINVAL;
4668
4669 /* Partition Tx queues evenly amongst traffic classes */
4670 for (i = 0; i < tc; i++) {
4671 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4672 netdev_set_prio_tc_map(dev, i, i);
4673 netdev_set_tc_queue(dev, i, q, offset);
4674 offset += q;
4675 }
John Fastabend24095aa2011-02-23 05:58:03 +00004676
4677 /* This enables multiple traffic class support in the hardware
4678 * which defaults to strict priority transmission by default.
4679 * If traffic classes are already enabled perhaps through DCB
4680 * code path then existing configuration will be used.
4681 */
4682 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4683 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4684 struct ieee_ets ets = {
4685 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4686 };
4687 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4688
4689 dev->dcbnl_ops->setdcbx(dev, mode);
4690 dev->dcbnl_ops->ieee_setets(dev, &ets);
4691 }
John Fastabende5b64632011-03-08 03:44:52 +00004692 }
4693 return 0;
4694}
4695
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004696/**
4697 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4698 * @adapter: board private structure to initialize
4699 *
4700 * Cache the descriptor ring offsets for DCB to the assigned rings.
4701 *
4702 **/
4703static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4704{
John Fastabende5b64632011-03-08 03:44:52 +00004705 struct net_device *dev = adapter->netdev;
4706 int i, j, k;
4707 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004708
Alexander Duyckbd508172010-11-16 19:27:03 -08004709 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4710 return false;
4711
John Fastabende5b64632011-03-08 03:44:52 +00004712 for (i = 0, k = 0; i < num_tcs; i++) {
4713 unsigned int tx_s, rx_s;
4714 u16 count = dev->tc_to_txq[i].count;
4715
4716 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4717 for (j = 0; j < count; j++, k++) {
4718 adapter->tx_ring[k]->reg_idx = tx_s + j;
4719 adapter->rx_ring[k]->reg_idx = rx_s + j;
4720 adapter->tx_ring[k]->dcb_tc = i;
4721 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004722 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004723 }
John Fastabende5b64632011-03-08 03:44:52 +00004724
4725 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004726}
4727#endif
4728
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004729/**
4730 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4731 * @adapter: board private structure to initialize
4732 *
4733 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4734 *
4735 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004736static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004737{
4738 int i;
4739 bool ret = false;
4740
4741 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4742 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4743 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4744 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004745 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004746 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004747 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004748 ret = true;
4749 }
4750
4751 return ret;
4752}
4753
Yi Zou0331a832009-05-17 12:33:52 +00004754#ifdef IXGBE_FCOE
4755/**
4756 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4757 * @adapter: board private structure to initialize
4758 *
4759 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4760 *
4761 */
4762static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4763{
Yi Zou0331a832009-05-17 12:33:52 +00004764 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004765 int i;
4766 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004767
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004768 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4769 return false;
4770
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004771 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4772 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4773 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4774 ixgbe_cache_ring_fdir(adapter);
4775 else
4776 ixgbe_cache_ring_rss(adapter);
4777
4778 fcoe_rx_i = f->mask;
4779 fcoe_tx_i = f->mask;
4780 }
4781 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4782 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4783 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4784 }
4785 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004786}
4787
4788#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004789/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004790 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4791 * @adapter: board private structure to initialize
4792 *
4793 * SR-IOV doesn't use any descriptor rings but changes the default if
4794 * no other mapping is used.
4795 *
4796 */
4797static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4798{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004799 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4800 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004801 if (adapter->num_vfs)
4802 return true;
4803 else
4804 return false;
4805}
4806
4807/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004808 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4809 * @adapter: board private structure to initialize
4810 *
4811 * Once we know the feature-set enabled for the device, we'll cache
4812 * the register offset the descriptor ring is assigned to.
4813 *
4814 * Note, the order the various feature calls is important. It must start with
4815 * the "most" features enabled at the same time, then trickle down to the
4816 * least amount of features turned on at once.
4817 **/
4818static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4819{
4820 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004821 adapter->rx_ring[0]->reg_idx = 0;
4822 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004823
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004824 if (ixgbe_cache_ring_sriov(adapter))
4825 return;
4826
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004827#ifdef CONFIG_IXGBE_DCB
4828 if (ixgbe_cache_ring_dcb(adapter))
4829 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004830#endif
John Fastabende5b64632011-03-08 03:44:52 +00004831
4832#ifdef IXGBE_FCOE
4833 if (ixgbe_cache_ring_fcoe(adapter))
4834 return;
4835#endif /* IXGBE_FCOE */
4836
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004837 if (ixgbe_cache_ring_fdir(adapter))
4838 return;
4839
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004840 if (ixgbe_cache_ring_rss(adapter))
4841 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004842}
4843
Auke Kok9a799d72007-09-15 14:07:45 -07004844/**
4845 * ixgbe_alloc_queues - Allocate memory for all rings
4846 * @adapter: board private structure to initialize
4847 *
4848 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004849 * number of queues at compile-time. The polling_netdev array is
4850 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004851 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004852static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004853{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004854 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004855
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004856 if (nid < 0 || !node_online(nid))
4857 nid = first_online_node;
4858
4859 for (; tx < adapter->num_tx_queues; tx++) {
4860 struct ixgbe_ring *ring;
4861
4862 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004863 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004864 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004865 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004866 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004867 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004868 ring->queue_index = tx;
4869 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004870 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004871 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004872
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004873 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004874 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004875
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004876 for (; rx < adapter->num_rx_queues; rx++) {
4877 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004878
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004879 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004880 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004881 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004882 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004883 goto err_allocation;
4884 ring->count = adapter->rx_ring_count;
4885 ring->queue_index = rx;
4886 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004887 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004888 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004889
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004890 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004891 }
4892
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004893 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004894
4895 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004896
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004897err_allocation:
4898 while (tx)
4899 kfree(adapter->tx_ring[--tx]);
4900
4901 while (rx)
4902 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004903 return -ENOMEM;
4904}
4905
4906/**
4907 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4908 * @adapter: board private structure to initialize
4909 *
4910 * Attempt to configure the interrupts using the best available
4911 * capabilities of the hardware and the kernel.
4912 **/
Al Virofeea6a52008-11-27 15:34:07 -08004913static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004914{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004915 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004916 int err = 0;
4917 int vector, v_budget;
4918
4919 /*
4920 * It's easy to be greedy for MSI-X vectors, but it really
4921 * doesn't do us much good if we have a lot more vectors
4922 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004923 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004924 */
4925 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004926 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004927
4928 /*
4929 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004930 * hw.mac->max_msix_vectors vectors. With features
4931 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4932 * descriptor queues supported by our device. Thus, we cap it off in
4933 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004934 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004935 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004936
4937 /* A failure in MSI-X entry allocation isn't fatal, but it does
4938 * mean we disable MSI-X capabilities of the adapter. */
4939 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004940 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004941 if (adapter->msix_entries) {
4942 for (vector = 0; vector < v_budget; vector++)
4943 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004944
Alexander Duyck7a921c92009-05-06 10:43:28 +00004945 ixgbe_acquire_msix_vectors(adapter, v_budget);
4946
4947 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4948 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004949 }
David S. Miller26d27842010-05-03 15:18:22 -07004950
Alexander Duyck7a921c92009-05-06 10:43:28 +00004951 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4952 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004953 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4954 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4955 e_err(probe,
4956 "Flow Director is not supported while multiple "
4957 "queues are disabled. Disabling Flow Director\n");
4958 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004959 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4960 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4961 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004962 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4963 ixgbe_disable_sriov(adapter);
4964
Ben Hutchings847f53f2010-09-27 08:28:56 +00004965 err = ixgbe_set_num_queues(adapter);
4966 if (err)
4967 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004968
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004969 err = pci_enable_msi(adapter->pdev);
4970 if (!err) {
4971 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4972 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004973 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4974 "Unable to allocate MSI interrupt, "
4975 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004976 /* reset err */
4977 err = 0;
4978 }
4979
4980out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004981 return err;
4982}
4983
Alexander Duyck7a921c92009-05-06 10:43:28 +00004984/**
4985 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4986 * @adapter: board private structure to initialize
4987 *
4988 * We allocate one q_vector per queue interrupt. If allocation fails we
4989 * return -ENOMEM.
4990 **/
4991static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4992{
4993 int q_idx, num_q_vectors;
4994 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004995 int (*poll)(struct napi_struct *, int);
4996
4997 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4998 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004999 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005000 } else {
5001 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005002 poll = &ixgbe_poll;
5003 }
5004
5005 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005006 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005007 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005008 if (!q_vector)
5009 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00005010 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005011 if (!q_vector)
5012 goto err_out;
5013 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005014 if (q_vector->txr_count && !q_vector->rxr_count)
5015 q_vector->eitr = adapter->tx_eitr_param;
5016 else
5017 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005018 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005019 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005020 adapter->q_vector[q_idx] = q_vector;
5021 }
5022
5023 return 0;
5024
5025err_out:
5026 while (q_idx) {
5027 q_idx--;
5028 q_vector = adapter->q_vector[q_idx];
5029 netif_napi_del(&q_vector->napi);
5030 kfree(q_vector);
5031 adapter->q_vector[q_idx] = NULL;
5032 }
5033 return -ENOMEM;
5034}
5035
5036/**
5037 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5038 * @adapter: board private structure to initialize
5039 *
5040 * This function frees the memory allocated to the q_vectors. In addition if
5041 * NAPI is enabled it will delete any references to the NAPI struct prior
5042 * to freeing the q_vector.
5043 **/
5044static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5045{
5046 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005047
Alexander Duyck91281fd2009-06-04 16:00:27 +00005048 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005049 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005050 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005051 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005052
5053 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5054 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005055 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005056 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005057 kfree(q_vector);
5058 }
5059}
5060
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005061static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005062{
5063 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5064 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5065 pci_disable_msix(adapter->pdev);
5066 kfree(adapter->msix_entries);
5067 adapter->msix_entries = NULL;
5068 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5069 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5070 pci_disable_msi(adapter->pdev);
5071 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005072}
5073
5074/**
5075 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5076 * @adapter: board private structure to initialize
5077 *
5078 * We determine which interrupt scheme to use based on...
5079 * - Kernel support (MSI, MSI-X)
5080 * - which can be user-defined (via MODULE_PARAM)
5081 * - Hardware queue count (num_*_queues)
5082 * - defined by miscellaneous hardware support/features (RSS, etc.)
5083 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005084int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005085{
5086 int err;
5087
5088 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005089 err = ixgbe_set_num_queues(adapter);
5090 if (err)
5091 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005092
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005093 err = ixgbe_set_interrupt_capability(adapter);
5094 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005095 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005096 goto err_set_interrupt;
5097 }
5098
Alexander Duyck7a921c92009-05-06 10:43:28 +00005099 err = ixgbe_alloc_q_vectors(adapter);
5100 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005101 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005102 goto err_alloc_q_vectors;
5103 }
5104
5105 err = ixgbe_alloc_queues(adapter);
5106 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005107 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005108 goto err_alloc_queues;
5109 }
5110
Emil Tantilov849c4542010-06-03 16:53:41 +00005111 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005112 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5113 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005114
5115 set_bit(__IXGBE_DOWN, &adapter->state);
5116
5117 return 0;
5118
Alexander Duyck7a921c92009-05-06 10:43:28 +00005119err_alloc_queues:
5120 ixgbe_free_q_vectors(adapter);
5121err_alloc_q_vectors:
5122 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005123err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005124 return err;
5125}
5126
Eric Dumazet1a515022010-11-16 19:26:42 -08005127static void ring_free_rcu(struct rcu_head *head)
5128{
5129 kfree(container_of(head, struct ixgbe_ring, rcu));
5130}
5131
Alexander Duyck7a921c92009-05-06 10:43:28 +00005132/**
5133 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5134 * @adapter: board private structure to clear interrupt scheme on
5135 *
5136 * We go through and clear interrupt specific resources and reset the structure
5137 * to pre-load conditions
5138 **/
5139void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5140{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005141 int i;
5142
5143 for (i = 0; i < adapter->num_tx_queues; i++) {
5144 kfree(adapter->tx_ring[i]);
5145 adapter->tx_ring[i] = NULL;
5146 }
5147 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005148 struct ixgbe_ring *ring = adapter->rx_ring[i];
5149
5150 /* ixgbe_get_stats64() might access this ring, we must wait
5151 * a grace period before freeing it.
5152 */
5153 call_rcu(&ring->rcu, ring_free_rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005154 adapter->rx_ring[i] = NULL;
5155 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005156
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005157 adapter->num_tx_queues = 0;
5158 adapter->num_rx_queues = 0;
5159
Alexander Duyck7a921c92009-05-06 10:43:28 +00005160 ixgbe_free_q_vectors(adapter);
5161 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005162}
5163
5164/**
5165 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5166 * @adapter: board private structure to initialize
5167 *
5168 * ixgbe_sw_init initializes the Adapter private data structure.
5169 * Fields are initialized based on PCI device information and
5170 * OS network device settings (MTU size).
5171 **/
5172static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5173{
5174 struct ixgbe_hw *hw = &adapter->hw;
5175 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005176 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005177 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005178#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005179 int j;
5180 struct tc_configuration *tc;
5181#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005182 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005183
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005184 /* PCI config space info */
5185
5186 hw->vendor_id = pdev->vendor;
5187 hw->device_id = pdev->device;
5188 hw->revision_id = pdev->revision;
5189 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5190 hw->subsystem_device_id = pdev->subsystem_device;
5191
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005192 /* Set capability flags */
5193 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5194 adapter->ring_feature[RING_F_RSS].indices = rss;
5195 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005196 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005197 switch (hw->mac.type) {
5198 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005199 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5200 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005201 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005202 break;
5203 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005204 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005205 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005206 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5207 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005208 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5209 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005210 /* n-tuple support exists, always init our spinlock */
5211 spin_lock_init(&adapter->fdir_perfect_lock);
5212 /* Flow Director hash filters enabled */
5213 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5214 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005215 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005216 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005217 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005218#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005219 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5220 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5221 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005222#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005223 /* Default traffic class to use for FCoE */
5224 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005225 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005226#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005227#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005228 break;
5229 default:
5230 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005231 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005232
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005233#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005234 /* Configure DCB traffic classes */
5235 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5236 tc = &adapter->dcb_cfg.tc_config[j];
5237 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5238 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5239 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5240 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5241 tc->dcb_pfc = pfc_disabled;
5242 }
5243 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5244 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5245 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005246 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005247 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005248 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005249 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005250 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005251
5252#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005253
5254 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005255 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005256 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005257#ifdef CONFIG_DCB
5258 adapter->last_lfc_mode = hw->fc.current_mode;
5259#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005260 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5261 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005262 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5263 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005264 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005265
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005266 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005267 adapter->rx_itr_setting = 1;
5268 adapter->rx_eitr_param = 20000;
5269 adapter->tx_itr_setting = 1;
5270 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005271
5272 /* set defaults for eitr in MegaBytes */
5273 adapter->eitr_low = 10;
5274 adapter->eitr_high = 20;
5275
5276 /* set default ring sizes */
5277 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5278 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5279
Auke Kok9a799d72007-09-15 14:07:45 -07005280 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005281 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005282 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005283 return -EIO;
5284 }
5285
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005286 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005287 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5288
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005289 /* get assigned NUMA node */
5290 adapter->node = dev_to_node(&pdev->dev);
5291
Auke Kok9a799d72007-09-15 14:07:45 -07005292 set_bit(__IXGBE_DOWN, &adapter->state);
5293
5294 return 0;
5295}
5296
5297/**
5298 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005299 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005300 *
5301 * Return 0 on success, negative on failure
5302 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005303int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005304{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005305 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005306 int size;
5307
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005308 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005309 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005310 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005311 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005312 if (!tx_ring->tx_buffer_info)
5313 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005314
5315 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005316 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005317 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005318
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005319 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005320 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005321 if (!tx_ring->desc)
5322 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005323
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005324 tx_ring->next_to_use = 0;
5325 tx_ring->next_to_clean = 0;
5326 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005327 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005328
5329err:
5330 vfree(tx_ring->tx_buffer_info);
5331 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005332 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005333 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005334}
5335
5336/**
Alexander Duyck69888672008-09-11 20:05:39 -07005337 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5338 * @adapter: board private structure
5339 *
5340 * If this function returns with an error, then it's possible one or
5341 * more of the rings is populated (while the rest are not). It is the
5342 * callers duty to clean those orphaned rings.
5343 *
5344 * Return 0 on success, negative on failure
5345 **/
5346static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5347{
5348 int i, err = 0;
5349
5350 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005351 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005352 if (!err)
5353 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005354 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005355 break;
5356 }
5357
5358 return err;
5359}
5360
5361/**
Auke Kok9a799d72007-09-15 14:07:45 -07005362 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005363 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005364 *
5365 * Returns 0 on success, negative on failure
5366 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005367int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005368{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005369 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005370 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005371
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005372 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005373 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005374 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005375 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005376 if (!rx_ring->rx_buffer_info)
5377 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005378
Auke Kok9a799d72007-09-15 14:07:45 -07005379 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005380 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5381 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005382
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005383 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005384 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005385
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 if (!rx_ring->desc)
5387 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005388
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005389 rx_ring->next_to_clean = 0;
5390 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005391
5392 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005393err:
5394 vfree(rx_ring->rx_buffer_info);
5395 rx_ring->rx_buffer_info = NULL;
5396 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005397 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005398}
5399
5400/**
Alexander Duyck69888672008-09-11 20:05:39 -07005401 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5402 * @adapter: board private structure
5403 *
5404 * If this function returns with an error, then it's possible one or
5405 * more of the rings is populated (while the rest are not). It is the
5406 * callers duty to clean those orphaned rings.
5407 *
5408 * Return 0 on success, negative on failure
5409 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005410static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5411{
5412 int i, err = 0;
5413
5414 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005415 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005416 if (!err)
5417 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005418 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005419 break;
5420 }
5421
5422 return err;
5423}
5424
5425/**
Auke Kok9a799d72007-09-15 14:07:45 -07005426 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005427 * @tx_ring: Tx descriptor ring for a specific queue
5428 *
5429 * Free all transmit software resources
5430 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005431void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005432{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005433 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005434
5435 vfree(tx_ring->tx_buffer_info);
5436 tx_ring->tx_buffer_info = NULL;
5437
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005438 /* if not set, then don't free */
5439 if (!tx_ring->desc)
5440 return;
5441
5442 dma_free_coherent(tx_ring->dev, tx_ring->size,
5443 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005444
5445 tx_ring->desc = NULL;
5446}
5447
5448/**
5449 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5450 * @adapter: board private structure
5451 *
5452 * Free all transmit software resources
5453 **/
5454static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5455{
5456 int i;
5457
5458 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005459 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005460 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005461}
5462
5463/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005464 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005465 * @rx_ring: ring to clean the resources from
5466 *
5467 * Free all receive software resources
5468 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005469void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005470{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005471 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005472
5473 vfree(rx_ring->rx_buffer_info);
5474 rx_ring->rx_buffer_info = NULL;
5475
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005476 /* if not set, then don't free */
5477 if (!rx_ring->desc)
5478 return;
5479
5480 dma_free_coherent(rx_ring->dev, rx_ring->size,
5481 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005482
5483 rx_ring->desc = NULL;
5484}
5485
5486/**
5487 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5488 * @adapter: board private structure
5489 *
5490 * Free all receive software resources
5491 **/
5492static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5493{
5494 int i;
5495
5496 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005497 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005498 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005499}
5500
5501/**
Auke Kok9a799d72007-09-15 14:07:45 -07005502 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5503 * @netdev: network interface device structure
5504 * @new_mtu: new value for maximum frame size
5505 *
5506 * Returns 0 on success, negative on failure
5507 **/
5508static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5509{
5510 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005511 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005512 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5513
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005514 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005515 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5516 hw->mac.type != ixgbe_mac_X540) {
5517 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5518 return -EINVAL;
5519 } else {
5520 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5521 return -EINVAL;
5522 }
Auke Kok9a799d72007-09-15 14:07:45 -07005523
Emil Tantilov396e7992010-07-01 20:05:12 +00005524 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005525 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005526 netdev->mtu = new_mtu;
5527
John Fastabend16b61be2010-11-16 19:26:44 -08005528 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5529 hw->fc.low_water = FC_LOW_WATER(max_frame);
5530
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005531 if (netif_running(netdev))
5532 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005533
5534 return 0;
5535}
5536
5537/**
5538 * ixgbe_open - Called when a network interface is made active
5539 * @netdev: network interface device structure
5540 *
5541 * Returns 0 on success, negative value on failure
5542 *
5543 * The open entry point is called when a network interface is made
5544 * active by the system (IFF_UP). At this point all resources needed
5545 * for transmit and receive operations are allocated, the interrupt
5546 * handler is registered with the OS, the watchdog timer is started,
5547 * and the stack is notified that the interface is ready.
5548 **/
5549static int ixgbe_open(struct net_device *netdev)
5550{
5551 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5552 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005553
Auke Kok4bebfaa2008-02-11 09:26:01 -08005554 /* disallow open during test */
5555 if (test_bit(__IXGBE_TESTING, &adapter->state))
5556 return -EBUSY;
5557
Jesse Brandeburg54386462009-04-17 20:44:27 +00005558 netif_carrier_off(netdev);
5559
Auke Kok9a799d72007-09-15 14:07:45 -07005560 /* allocate transmit descriptors */
5561 err = ixgbe_setup_all_tx_resources(adapter);
5562 if (err)
5563 goto err_setup_tx;
5564
Auke Kok9a799d72007-09-15 14:07:45 -07005565 /* allocate receive descriptors */
5566 err = ixgbe_setup_all_rx_resources(adapter);
5567 if (err)
5568 goto err_setup_rx;
5569
5570 ixgbe_configure(adapter);
5571
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005572 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005573 if (err)
5574 goto err_req_irq;
5575
Auke Kok9a799d72007-09-15 14:07:45 -07005576 err = ixgbe_up_complete(adapter);
5577 if (err)
5578 goto err_up;
5579
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005580 netif_tx_start_all_queues(netdev);
5581
Auke Kok9a799d72007-09-15 14:07:45 -07005582 return 0;
5583
5584err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005585 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005586 ixgbe_free_irq(adapter);
5587err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005588err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005589 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005590err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005591 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005592 ixgbe_reset(adapter);
5593
5594 return err;
5595}
5596
5597/**
5598 * ixgbe_close - Disables a network interface
5599 * @netdev: network interface device structure
5600 *
5601 * Returns 0, this is not allowed to fail
5602 *
5603 * The close entry point is called when an interface is de-activated
5604 * by the OS. The hardware is still under the drivers control, but
5605 * needs to be disabled. A global MAC reset is issued to stop the
5606 * hardware, and all transmit and receive resources are freed.
5607 **/
5608static int ixgbe_close(struct net_device *netdev)
5609{
5610 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005611
5612 ixgbe_down(adapter);
5613 ixgbe_free_irq(adapter);
5614
5615 ixgbe_free_all_tx_resources(adapter);
5616 ixgbe_free_all_rx_resources(adapter);
5617
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005618 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005619
5620 return 0;
5621}
5622
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005623#ifdef CONFIG_PM
5624static int ixgbe_resume(struct pci_dev *pdev)
5625{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005626 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5627 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005628 u32 err;
5629
5630 pci_set_power_state(pdev, PCI_D0);
5631 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005632 /*
5633 * pci_restore_state clears dev->state_saved so call
5634 * pci_save_state to restore it.
5635 */
5636 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005637
5638 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005639 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005640 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005641 return err;
5642 }
5643 pci_set_master(pdev);
5644
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005645 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005646
5647 err = ixgbe_init_interrupt_scheme(adapter);
5648 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005649 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005650 return err;
5651 }
5652
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005653 ixgbe_reset(adapter);
5654
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005655 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5656
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005657 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005658 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005659 if (err)
5660 return err;
5661 }
5662
5663 netif_device_attach(netdev);
5664
5665 return 0;
5666}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005667#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005668
5669static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005670{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005671 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5672 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005673 struct ixgbe_hw *hw = &adapter->hw;
5674 u32 ctrl, fctrl;
5675 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005676#ifdef CONFIG_PM
5677 int retval = 0;
5678#endif
5679
5680 netif_device_detach(netdev);
5681
5682 if (netif_running(netdev)) {
5683 ixgbe_down(adapter);
5684 ixgbe_free_irq(adapter);
5685 ixgbe_free_all_tx_resources(adapter);
5686 ixgbe_free_all_rx_resources(adapter);
5687 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005688
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005689 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005690#ifdef CONFIG_DCB
5691 kfree(adapter->ixgbe_ieee_pfc);
5692 kfree(adapter->ixgbe_ieee_ets);
5693#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005694
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005695#ifdef CONFIG_PM
5696 retval = pci_save_state(pdev);
5697 if (retval)
5698 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005699
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005700#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005701 if (wufc) {
5702 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005703
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005704 /* turn on all-multi mode if wake on multicast is enabled */
5705 if (wufc & IXGBE_WUFC_MC) {
5706 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5707 fctrl |= IXGBE_FCTRL_MPE;
5708 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5709 }
5710
5711 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5712 ctrl |= IXGBE_CTRL_GIO_DIS;
5713 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5714
5715 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5716 } else {
5717 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5718 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5719 }
5720
Alexander Duyckbd508172010-11-16 19:27:03 -08005721 switch (hw->mac.type) {
5722 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005723 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005724 break;
5725 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005726 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005727 pci_wake_from_d3(pdev, !!wufc);
5728 break;
5729 default:
5730 break;
5731 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005732
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005733 *enable_wake = !!wufc;
5734
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005735 ixgbe_release_hw_control(adapter);
5736
5737 pci_disable_device(pdev);
5738
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005739 return 0;
5740}
5741
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005742#ifdef CONFIG_PM
5743static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5744{
5745 int retval;
5746 bool wake;
5747
5748 retval = __ixgbe_shutdown(pdev, &wake);
5749 if (retval)
5750 return retval;
5751
5752 if (wake) {
5753 pci_prepare_to_sleep(pdev);
5754 } else {
5755 pci_wake_from_d3(pdev, false);
5756 pci_set_power_state(pdev, PCI_D3hot);
5757 }
5758
5759 return 0;
5760}
5761#endif /* CONFIG_PM */
5762
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005763static void ixgbe_shutdown(struct pci_dev *pdev)
5764{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005765 bool wake;
5766
5767 __ixgbe_shutdown(pdev, &wake);
5768
5769 if (system_state == SYSTEM_POWER_OFF) {
5770 pci_wake_from_d3(pdev, wake);
5771 pci_set_power_state(pdev, PCI_D3hot);
5772 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005773}
5774
5775/**
Auke Kok9a799d72007-09-15 14:07:45 -07005776 * ixgbe_update_stats - Update the board statistics counters.
5777 * @adapter: board private structure
5778 **/
5779void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5780{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005781 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005782 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005783 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005784 u64 total_mpc = 0;
5785 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005786 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5787 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5788 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005789
Don Skidmored08935c2010-06-11 13:20:29 +00005790 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5791 test_bit(__IXGBE_RESETTING, &adapter->state))
5792 return;
5793
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005794 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005795 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005796 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005797 for (i = 0; i < 16; i++)
5798 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005799 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005800 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005801 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5802 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005803 }
5804 adapter->rsc_total_count = rsc_count;
5805 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005806 }
5807
Alexander Duyck5b7da512010-11-16 19:26:50 -08005808 for (i = 0; i < adapter->num_rx_queues; i++) {
5809 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5810 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5811 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5812 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5813 bytes += rx_ring->stats.bytes;
5814 packets += rx_ring->stats.packets;
5815 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005816 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005817 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5818 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5819 netdev->stats.rx_bytes = bytes;
5820 netdev->stats.rx_packets = packets;
5821
5822 bytes = 0;
5823 packets = 0;
5824 /* gather some stats to the adapter struct that are per queue */
5825 for (i = 0; i < adapter->num_tx_queues; i++) {
5826 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5827 restart_queue += tx_ring->tx_stats.restart_queue;
5828 tx_busy += tx_ring->tx_stats.tx_busy;
5829 bytes += tx_ring->stats.bytes;
5830 packets += tx_ring->stats.packets;
5831 }
5832 adapter->restart_queue = restart_queue;
5833 adapter->tx_busy = tx_busy;
5834 netdev->stats.tx_bytes = bytes;
5835 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005836
Joe Perches7ca647b2010-09-07 21:35:40 +00005837 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005838 for (i = 0; i < 8; i++) {
5839 /* for packet buffers not used, the register should read 0 */
5840 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5841 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005842 hwstats->mpc[i] += mpc;
5843 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005844 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005845 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5846 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5847 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5848 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5849 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005850 switch (hw->mac.type) {
5851 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005852 hwstats->pxonrxc[i] +=
5853 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005854 break;
5855 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005856 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005857 hwstats->pxonrxc[i] +=
5858 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005859 break;
5860 default:
5861 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005862 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005863 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5864 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005865 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005866 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005867 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005868 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005869
John Fastabendc84d3242010-11-16 19:27:12 -08005870 ixgbe_update_xoff_received(adapter);
5871
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005872 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005873 switch (hw->mac.type) {
5874 case ixgbe_mac_82598EB:
5875 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005876 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5877 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5878 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5879 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005880 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005881 /* OS2BMC stats are X540 only*/
5882 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5883 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5884 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5885 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5886 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005887 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005888 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005889 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005890 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005891 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005892 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005893 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005894 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5895 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005896#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005897 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5898 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5899 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5900 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5901 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5902 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005903#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005904 break;
5905 default:
5906 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005907 }
Auke Kok9a799d72007-09-15 14:07:45 -07005908 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005909 hwstats->bprc += bprc;
5910 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005911 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005912 hwstats->mprc -= bprc;
5913 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5914 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5915 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5916 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5917 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5918 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5919 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5920 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005921 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005922 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005923 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->lxofftxc += lxoff;
5925 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5926 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5927 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005928 /*
5929 * 82598 errata - tx of flow control packets is included in tx counters
5930 */
5931 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005932 hwstats->gptc -= xon_off_tot;
5933 hwstats->mptc -= xon_off_tot;
5934 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5935 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5936 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5937 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5938 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5939 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5940 hwstats->ptc64 -= xon_off_tot;
5941 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5942 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5943 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5944 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5945 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5946 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005947
5948 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005949 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005950
5951 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005952 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005953 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005954 netdev->stats.rx_length_errors = hwstats->rlec;
5955 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005956 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005957}
5958
5959/**
5960 * ixgbe_watchdog - Timer Call-back
5961 * @data: pointer to adapter cast into an unsigned long
5962 **/
5963static void ixgbe_watchdog(unsigned long data)
5964{
5965 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005966 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005967 u64 eics = 0;
5968 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005969
Alexander Duyckfe49f042009-06-04 16:00:09 +00005970 /*
5971 * Do the watchdog outside of interrupt context due to the lovely
5972 * delays that some of the newer hardware requires
5973 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005974
Alexander Duyckfe49f042009-06-04 16:00:09 +00005975 if (test_bit(__IXGBE_DOWN, &adapter->state))
5976 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00005977
Alexander Duyckfe49f042009-06-04 16:00:09 +00005978 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
5979 /*
5980 * for legacy and MSI interrupts don't set any bits
5981 * that are enabled for EIAM, because this operation
5982 * would set *both* EIMS and EICS for any bit in EIAM
5983 */
5984 IXGBE_WRITE_REG(hw, IXGBE_EICS,
5985 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
5986 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005987 }
5988
Alexander Duyckfe49f042009-06-04 16:00:09 +00005989 /* get one bit for every active tx/rx interrupt vector */
5990 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
5991 struct ixgbe_q_vector *qv = adapter->q_vector[i];
5992 if (qv->rxr_count || qv->txr_count)
5993 eics |= ((u64)1 << i);
5994 }
5995
5996 /* Cause software interrupt to ensure rx rings are cleaned */
5997 ixgbe_irq_rearm_queues(adapter, eics);
5998
5999watchdog_reschedule:
6000 /* Reset the timer */
6001 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
6002
6003watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006004 schedule_work(&adapter->watchdog_task);
6005}
6006
6007/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006008 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
6009 * @work: pointer to work_struct containing our data
6010 **/
6011static void ixgbe_fdir_reinit_task(struct work_struct *work)
6012{
6013 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006014 struct ixgbe_adapter,
6015 fdir_reinit_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006016 struct ixgbe_hw *hw = &adapter->hw;
6017 int i;
6018
6019 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6020 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006021 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
6022 &(adapter->tx_ring[i]->state));
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006023 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006024 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006025 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006026 }
6027 /* Done FDIR Re-initialization, enable transmits */
6028 netif_tx_start_all_queues(adapter->netdev);
6029}
6030
Greg Rosea985b6c32010-11-18 03:02:52 +00006031static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6032{
6033 u32 ssvpc;
6034
6035 /* Do not perform spoof check for 82598 */
6036 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6037 return;
6038
6039 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6040
6041 /*
6042 * ssvpc register is cleared on read, if zero then no
6043 * spoofed packets in the last interval.
6044 */
6045 if (!ssvpc)
6046 return;
6047
6048 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6049}
6050
John Fastabend10eec952010-02-03 14:23:32 +00006051static DEFINE_MUTEX(ixgbe_watchdog_lock);
6052
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006053/**
Alexander Duyck69888672008-09-11 20:05:39 -07006054 * ixgbe_watchdog_task - worker thread to bring link up
6055 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006056 **/
6057static void ixgbe_watchdog_task(struct work_struct *work)
6058{
6059 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006060 struct ixgbe_adapter,
6061 watchdog_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006062 struct net_device *netdev = adapter->netdev;
6063 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend10eec952010-02-03 14:23:32 +00006064 u32 link_speed;
6065 bool link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006066 int i;
6067 struct ixgbe_ring *tx_ring;
6068 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006069
John Fastabend10eec952010-02-03 14:23:32 +00006070 mutex_lock(&ixgbe_watchdog_lock);
6071
6072 link_up = adapter->link_up;
6073 link_speed = adapter->link_speed;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006074
6075 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
6076 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006077 if (link_up) {
6078#ifdef CONFIG_DCB
6079 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6080 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006081 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006082 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006083 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006084 }
6085#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006086 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006087#endif
6088 }
6089
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006090 if (link_up ||
6091 time_after(jiffies, (adapter->link_check_timeout +
Joe Perchese8e9f692010-09-07 21:34:53 +00006092 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006093 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006094 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006095 }
6096 adapter->link_up = link_up;
6097 adapter->link_speed = link_speed;
6098 }
Auke Kok9a799d72007-09-15 14:07:45 -07006099
6100 if (link_up) {
6101 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006102 bool flow_rx, flow_tx;
6103
Alexander Duyckbd508172010-11-16 19:27:03 -08006104 switch (hw->mac.type) {
6105 case ixgbe_mac_82598EB: {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006106 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6107 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00006108 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6109 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006110 }
Alexander Duyckbd508172010-11-16 19:27:03 -08006111 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006112 case ixgbe_mac_82599EB:
6113 case ixgbe_mac_X540: {
Alexander Duyckbd508172010-11-16 19:27:03 -08006114 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6115 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6116 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6117 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6118 }
6119 break;
6120 default:
6121 flow_tx = false;
6122 flow_rx = false;
6123 break;
6124 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006125
Emil Tantilov396e7992010-07-01 20:05:12 +00006126 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
Jeff Kirshera46e5342008-11-27 00:22:21 -08006127 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
Emil Tantilov849c4542010-06-03 16:53:41 +00006128 "10 Gbps" :
6129 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +00006130 "1 Gbps" :
6131 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6132 "100 Mbps" :
6133 "unknown speed"))),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006134 ((flow_rx && flow_tx) ? "RX/TX" :
Emil Tantilov849c4542010-06-03 16:53:41 +00006135 (flow_rx ? "RX" :
6136 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07006137
6138 netif_carrier_on(netdev);
Lior Levyff4ab202011-03-11 02:03:07 +00006139 ixgbe_check_vf_rate_limit(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006140 } else {
6141 /* Force detection of hung controller */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006142 for (i = 0; i < adapter->num_tx_queues; i++) {
6143 tx_ring = adapter->tx_ring[i];
6144 set_check_for_tx_hang(tx_ring);
6145 }
Auke Kok9a799d72007-09-15 14:07:45 -07006146 }
6147 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006148 adapter->link_up = false;
6149 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006150 if (netif_carrier_ok(netdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00006151 e_info(drv, "NIC Link is Down\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006152 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006153 }
6154 }
6155
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006156 if (!netif_carrier_ok(netdev)) {
6157 for (i = 0; i < adapter->num_tx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006158 tx_ring = adapter->tx_ring[i];
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006159 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6160 some_tx_pending = 1;
6161 break;
6162 }
6163 }
6164
6165 if (some_tx_pending) {
6166 /* We've lost link, so the controller stops DMA,
6167 * but we've got queued Tx work that's never going
6168 * to get done, so reset controller to flush Tx.
6169 * (Do the reset outside of interrupt context).
6170 */
6171 schedule_work(&adapter->reset_task);
6172 }
6173 }
6174
Greg Rosea985b6c32010-11-18 03:02:52 +00006175 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006176 ixgbe_update_stats(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006177 mutex_unlock(&ixgbe_watchdog_lock);
Auke Kok9a799d72007-09-15 14:07:45 -07006178}
6179
Alexander Duyck70864002011-04-27 09:13:56 +00006180/**
6181 * ixgbe_sfp_detection_subtask - poll for SFP+ cable
6182 * @adapter - the ixgbe adapter structure
6183 **/
6184static void ixgbe_sfp_detection_subtask(struct ixgbe_adapter *adapter)
6185{
6186 struct ixgbe_hw *hw = &adapter->hw;
6187 s32 err;
6188
6189 /* not searching for SFP so there is nothing to do here */
6190 if (!(adapter->flags2 & IXGBE_FLAG2_SEARCH_FOR_SFP) &&
6191 !(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6192 return;
6193
6194 /* someone else is in init, wait until next service event */
6195 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6196 return;
6197
6198 err = hw->phy.ops.identify_sfp(hw);
6199 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6200 goto sfp_out;
6201
6202 if (err == IXGBE_ERR_SFP_NOT_PRESENT) {
6203 /* If no cable is present, then we need to reset
6204 * the next time we find a good cable. */
6205 adapter->flags2 |= IXGBE_FLAG2_SFP_NEEDS_RESET;
6206 }
6207
6208 /* exit on error */
6209 if (err)
6210 goto sfp_out;
6211
6212 /* exit if reset not needed */
6213 if (!(adapter->flags2 & IXGBE_FLAG2_SFP_NEEDS_RESET))
6214 goto sfp_out;
6215
6216 adapter->flags2 &= ~IXGBE_FLAG2_SFP_NEEDS_RESET;
6217
6218 /*
6219 * A module may be identified correctly, but the EEPROM may not have
6220 * support for that module. setup_sfp() will fail in that case, so
6221 * we should not allow that module to load.
6222 */
6223 if (hw->mac.type == ixgbe_mac_82598EB)
6224 err = hw->phy.ops.reset(hw);
6225 else
6226 err = hw->mac.ops.setup_sfp(hw);
6227
6228 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED)
6229 goto sfp_out;
6230
6231 adapter->flags |= IXGBE_FLAG_NEED_LINK_CONFIG;
6232 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
6233
6234sfp_out:
6235 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6236
6237 if ((err == IXGBE_ERR_SFP_NOT_SUPPORTED) &&
6238 (adapter->netdev->reg_state == NETREG_REGISTERED)) {
6239 e_dev_err("failed to initialize because an unsupported "
6240 "SFP+ module type was detected.\n");
6241 e_dev_err("Reload the driver after installing a "
6242 "supported module.\n");
6243 unregister_netdev(adapter->netdev);
6244 }
6245}
6246
6247/**
6248 * ixgbe_sfp_link_config_subtask - set up link SFP after module install
6249 * @adapter - the ixgbe adapter structure
6250 **/
6251static void ixgbe_sfp_link_config_subtask(struct ixgbe_adapter *adapter)
6252{
6253 struct ixgbe_hw *hw = &adapter->hw;
6254 u32 autoneg;
6255 bool negotiation;
6256
6257 if (!(adapter->flags & IXGBE_FLAG_NEED_LINK_CONFIG))
6258 return;
6259
6260 /* someone else is in init, wait until next service event */
6261 if (test_and_set_bit(__IXGBE_IN_SFP_INIT, &adapter->state))
6262 return;
6263
6264 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_CONFIG;
6265
6266 autoneg = hw->phy.autoneg_advertised;
6267 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
6268 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
6269 hw->mac.autotry_restart = false;
6270 if (hw->mac.ops.setup_link)
6271 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
6272
6273 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6274 adapter->link_check_timeout = jiffies;
6275 clear_bit(__IXGBE_IN_SFP_INIT, &adapter->state);
6276}
6277
6278/**
6279 * ixgbe_service_timer - Timer Call-back
6280 * @data: pointer to adapter cast into an unsigned long
6281 **/
6282static void ixgbe_service_timer(unsigned long data)
6283{
6284 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
6285 unsigned long next_event_offset;
6286
6287 /* poll faster when waiting for link */
6288 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE)
6289 next_event_offset = HZ / 10;
6290 else
6291 next_event_offset = HZ * 2;
6292
6293 /* Reset the timer */
6294 mod_timer(&adapter->service_timer, next_event_offset + jiffies);
6295
6296 ixgbe_service_event_schedule(adapter);
6297}
6298
6299/**
6300 * ixgbe_service_task - manages and runs subtasks
6301 * @work: pointer to work_struct containing our data
6302 **/
6303static void ixgbe_service_task(struct work_struct *work)
6304{
6305 struct ixgbe_adapter *adapter = container_of(work,
6306 struct ixgbe_adapter,
6307 service_task);
6308
6309 ixgbe_sfp_detection_subtask(adapter);
6310 ixgbe_sfp_link_config_subtask(adapter);
6311
6312 ixgbe_service_event_complete(adapter);
6313}
6314
Auke Kok9a799d72007-09-15 14:07:45 -07006315static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006316 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006317 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006318{
6319 struct ixgbe_adv_tx_context_desc *context_desc;
6320 unsigned int i;
6321 int err;
6322 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006323 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6324 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006325
6326 if (skb_is_gso(skb)) {
6327 if (skb_header_cloned(skb)) {
6328 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6329 if (err)
6330 return err;
6331 }
6332 l4len = tcp_hdrlen(skb);
6333 *hdr_len += l4len;
6334
Hao Zheng5e09a102010-11-11 13:47:59 +00006335 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006336 struct iphdr *iph = ip_hdr(skb);
6337 iph->tot_len = 0;
6338 iph->check = 0;
6339 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006340 iph->daddr, 0,
6341 IPPROTO_TCP,
6342 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006343 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006344 ipv6_hdr(skb)->payload_len = 0;
6345 tcp_hdr(skb)->check =
6346 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006347 &ipv6_hdr(skb)->daddr,
6348 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006349 }
6350
6351 i = tx_ring->next_to_use;
6352
6353 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006354 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006355
6356 /* VLAN MACLEN IPLEN */
6357 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6358 vlan_macip_lens |=
6359 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6360 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006361 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006362 *hdr_len += skb_network_offset(skb);
6363 vlan_macip_lens |=
6364 (skb_transport_header(skb) - skb_network_header(skb));
6365 *hdr_len +=
6366 (skb_transport_header(skb) - skb_network_header(skb));
6367 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6368 context_desc->seqnum_seed = 0;
6369
6370 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006371 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006372 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006373
Hao Zheng5e09a102010-11-11 13:47:59 +00006374 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006375 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6376 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6377 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6378
6379 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006380 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006381 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6382 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006383 /* use index 1 for TSO */
6384 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006385 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6386
6387 tx_buffer_info->time_stamp = jiffies;
6388 tx_buffer_info->next_to_watch = i;
6389
6390 i++;
6391 if (i == tx_ring->count)
6392 i = 0;
6393 tx_ring->next_to_use = i;
6394
6395 return true;
6396 }
6397 return false;
6398}
6399
Hao Zheng5e09a102010-11-11 13:47:59 +00006400static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6401 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006402{
6403 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006404
6405 switch (protocol) {
6406 case cpu_to_be16(ETH_P_IP):
6407 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6408 switch (ip_hdr(skb)->protocol) {
6409 case IPPROTO_TCP:
6410 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6411 break;
6412 case IPPROTO_SCTP:
6413 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6414 break;
6415 }
6416 break;
6417 case cpu_to_be16(ETH_P_IPV6):
6418 /* XXX what about other V6 headers?? */
6419 switch (ipv6_hdr(skb)->nexthdr) {
6420 case IPPROTO_TCP:
6421 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6422 break;
6423 case IPPROTO_SCTP:
6424 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6425 break;
6426 }
6427 break;
6428 default:
6429 if (unlikely(net_ratelimit()))
6430 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006431 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006432 break;
6433 }
6434
6435 return rtn;
6436}
6437
Auke Kok9a799d72007-09-15 14:07:45 -07006438static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006439 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006440 struct sk_buff *skb, u32 tx_flags,
6441 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006442{
6443 struct ixgbe_adv_tx_context_desc *context_desc;
6444 unsigned int i;
6445 struct ixgbe_tx_buffer *tx_buffer_info;
6446 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6447
6448 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6449 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6450 i = tx_ring->next_to_use;
6451 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006452 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006453
6454 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6455 vlan_macip_lens |=
6456 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6457 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006458 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006459 if (skb->ip_summed == CHECKSUM_PARTIAL)
6460 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006461 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006462
6463 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6464 context_desc->seqnum_seed = 0;
6465
6466 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006467 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006468
Joe Perches7ca647b2010-09-07 21:35:40 +00006469 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006470 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006471
6472 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006473 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006474 context_desc->mss_l4len_idx = 0;
6475
6476 tx_buffer_info->time_stamp = jiffies;
6477 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006478
Auke Kok9a799d72007-09-15 14:07:45 -07006479 i++;
6480 if (i == tx_ring->count)
6481 i = 0;
6482 tx_ring->next_to_use = i;
6483
6484 return true;
6485 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006486
Auke Kok9a799d72007-09-15 14:07:45 -07006487 return false;
6488}
6489
6490static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006491 struct ixgbe_ring *tx_ring,
6492 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006493 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006494{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006495 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006496 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006497 unsigned int len;
6498 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006499 unsigned int offset = 0, size, count = 0, i;
6500 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6501 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006502 unsigned int bytecount = skb->len;
6503 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006504
6505 i = tx_ring->next_to_use;
6506
Yi Zoueacd73f2009-05-13 13:11:06 +00006507 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6508 /* excluding fcoe_crc_eof for FCoE */
6509 total -= sizeof(struct fcoe_crc_eof);
6510
6511 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006512 while (len) {
6513 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6514 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6515
6516 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006517 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006518 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006519 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006520 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006521 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006522 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006523 tx_buffer_info->time_stamp = jiffies;
6524 tx_buffer_info->next_to_watch = i;
6525
6526 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006527 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006528 offset += size;
6529 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006530
6531 if (len) {
6532 i++;
6533 if (i == tx_ring->count)
6534 i = 0;
6535 }
Auke Kok9a799d72007-09-15 14:07:45 -07006536 }
6537
6538 for (f = 0; f < nr_frags; f++) {
6539 struct skb_frag_struct *frag;
6540
6541 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006542 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006543 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006544
6545 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006546 i++;
6547 if (i == tx_ring->count)
6548 i = 0;
6549
Auke Kok9a799d72007-09-15 14:07:45 -07006550 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6551 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6552
6553 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006554 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006555 frag->page,
6556 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006557 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006558 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006559 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006560 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006561 tx_buffer_info->time_stamp = jiffies;
6562 tx_buffer_info->next_to_watch = i;
6563
6564 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006565 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006566 offset += size;
6567 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006568 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006569 if (total == 0)
6570 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006571 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006572
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006573 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6574 gso_segs = skb_shinfo(skb)->gso_segs;
6575#ifdef IXGBE_FCOE
6576 /* adjust for FCoE Sequence Offload */
6577 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6578 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6579 skb_shinfo(skb)->gso_size);
6580#endif /* IXGBE_FCOE */
6581 bytecount += (gso_segs - 1) * hdr_len;
6582
6583 /* multiply data chunks by size of headers */
6584 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6585 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006586 tx_ring->tx_buffer_info[i].skb = skb;
6587 tx_ring->tx_buffer_info[first].next_to_watch = i;
6588
6589 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006590
6591dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006592 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006593
6594 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6595 tx_buffer_info->dma = 0;
6596 tx_buffer_info->time_stamp = 0;
6597 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006598 if (count)
6599 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006600
6601 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006602 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006603 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006604 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006605 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006606 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006607 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006608 }
6609
Anton Blancharde44d38e2010-02-03 13:12:51 +00006610 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006611}
6612
Alexander Duyck84ea2592010-11-16 19:26:49 -08006613static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006614 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006615{
6616 union ixgbe_adv_tx_desc *tx_desc = NULL;
6617 struct ixgbe_tx_buffer *tx_buffer_info;
6618 u32 olinfo_status = 0, cmd_type_len = 0;
6619 unsigned int i;
6620 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6621
6622 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6623
6624 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6625
6626 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6627 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6628
6629 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6630 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6631
6632 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006633 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006634
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006635 /* use index 1 context for tso */
6636 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006637 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6638 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006639 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006640
6641 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6642 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006643 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006644
Yi Zoueacd73f2009-05-13 13:11:06 +00006645 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6646 olinfo_status |= IXGBE_ADVTXD_CC;
6647 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6648 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6649 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6650 }
6651
Auke Kok9a799d72007-09-15 14:07:45 -07006652 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6653
6654 i = tx_ring->next_to_use;
6655 while (count--) {
6656 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006657 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006658 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6659 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006660 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006661 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006662 i++;
6663 if (i == tx_ring->count)
6664 i = 0;
6665 }
6666
6667 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6668
6669 /*
6670 * Force memory writes to complete before letting h/w
6671 * know there are new descriptors to fetch. (Only
6672 * applicable for weak-ordered memory model archs,
6673 * such as IA-64).
6674 */
6675 wmb();
6676
6677 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006678 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006679}
6680
Alexander Duyck69830522011-01-06 14:29:58 +00006681static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6682 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006683{
Alexander Duyck69830522011-01-06 14:29:58 +00006684 struct ixgbe_q_vector *q_vector = ring->q_vector;
6685 union ixgbe_atr_hash_dword input = { .dword = 0 };
6686 union ixgbe_atr_hash_dword common = { .dword = 0 };
6687 union {
6688 unsigned char *network;
6689 struct iphdr *ipv4;
6690 struct ipv6hdr *ipv6;
6691 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006692 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006693 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006694
Alexander Duyck69830522011-01-06 14:29:58 +00006695 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6696 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006697 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006698
Alexander Duyck69830522011-01-06 14:29:58 +00006699 /* do nothing if sampling is disabled */
6700 if (!ring->atr_sample_rate)
6701 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006702
Alexander Duyck69830522011-01-06 14:29:58 +00006703 ring->atr_count++;
6704
6705 /* snag network header to get L4 type and address */
6706 hdr.network = skb_network_header(skb);
6707
6708 /* Currently only IPv4/IPv6 with TCP is supported */
6709 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6710 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6711 (protocol != __constant_htons(ETH_P_IP) ||
6712 hdr.ipv4->protocol != IPPROTO_TCP))
6713 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006714
6715 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006716
Alexander Duyck69830522011-01-06 14:29:58 +00006717 /* skip this packet since the socket is closing */
6718 if (th->fin)
6719 return;
6720
6721 /* sample on all syn packets or once every atr sample count */
6722 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6723 return;
6724
6725 /* reset sample count */
6726 ring->atr_count = 0;
6727
6728 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6729
6730 /*
6731 * src and dst are inverted, think how the receiver sees them
6732 *
6733 * The input is broken into two sections, a non-compressed section
6734 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6735 * is XORed together and stored in the compressed dword.
6736 */
6737 input.formatted.vlan_id = vlan_id;
6738
6739 /*
6740 * since src port and flex bytes occupy the same word XOR them together
6741 * and write the value to source port portion of compressed dword
6742 */
6743 if (vlan_id)
6744 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6745 else
6746 common.port.src ^= th->dest ^ protocol;
6747 common.port.dst ^= th->source;
6748
6749 if (protocol == __constant_htons(ETH_P_IP)) {
6750 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6751 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6752 } else {
6753 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6754 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6755 hdr.ipv6->saddr.s6_addr32[1] ^
6756 hdr.ipv6->saddr.s6_addr32[2] ^
6757 hdr.ipv6->saddr.s6_addr32[3] ^
6758 hdr.ipv6->daddr.s6_addr32[0] ^
6759 hdr.ipv6->daddr.s6_addr32[1] ^
6760 hdr.ipv6->daddr.s6_addr32[2] ^
6761 hdr.ipv6->daddr.s6_addr32[3];
6762 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006763
6764 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006765 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6766 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006767}
6768
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006769static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006770{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006771 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006772 /* Herbert's original patch had:
6773 * smp_mb__after_netif_stop_queue();
6774 * but since that doesn't exist yet, just open code it. */
6775 smp_mb();
6776
6777 /* We need to check again in a case another CPU has just
6778 * made room available. */
6779 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6780 return -EBUSY;
6781
6782 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006783 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006784 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006785 return 0;
6786}
6787
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006788static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006789{
6790 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6791 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006792 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006793}
6794
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006795static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6796{
6797 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006798 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006799#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006800 __be16 protocol;
6801
6802 protocol = vlan_get_protocol(skb);
6803
John Fastabende5b64632011-03-08 03:44:52 +00006804 if (((protocol == htons(ETH_P_FCOE)) ||
6805 (protocol == htons(ETH_P_FIP))) &&
6806 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6807 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6808 txq += adapter->ring_feature[RING_F_FCOE].mask;
6809 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006810 }
6811#endif
6812
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006813 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6814 while (unlikely(txq >= dev->real_num_tx_queues))
6815 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006816 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006817 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006818
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006819 return skb_tx_hash(dev, skb);
6820}
6821
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006822netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006823 struct ixgbe_adapter *adapter,
6824 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006825{
Auke Kok9a799d72007-09-15 14:07:45 -07006826 unsigned int first;
6827 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006828 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006829 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006830 int count = 0;
6831 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006832 __be16 protocol;
6833
6834 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006835
Jesse Grosseab6d182010-10-20 13:56:03 +00006836 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006837 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006838 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6839 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006840 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006841 }
6842 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6843 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006844 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6845 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006846 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006847 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6848 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006849 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006850
Yi Zou09ad1cc2009-09-03 14:56:10 +00006851#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006852 /* for FCoE with DCB, we force the priority to what
6853 * was specified by the switch */
6854 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006855 (protocol == htons(ETH_P_FCOE)))
6856 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006857#endif
6858
Yi Zoueacd73f2009-05-13 13:11:06 +00006859 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006860 if (skb_is_gso(skb) ||
6861 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006862 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6863 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006864 count++;
6865
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006866 count += TXD_USE_COUNT(skb_headlen(skb));
6867 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006868 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6869
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006870 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006871 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006872 return NETDEV_TX_BUSY;
6873 }
Auke Kok9a799d72007-09-15 14:07:45 -07006874
Auke Kok9a799d72007-09-15 14:07:45 -07006875 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006876 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6877#ifdef IXGBE_FCOE
6878 /* setup tx offload for FCoE */
6879 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6880 if (tso < 0) {
6881 dev_kfree_skb_any(skb);
6882 return NETDEV_TX_OK;
6883 }
6884 if (tso)
6885 tx_flags |= IXGBE_TX_FLAGS_FSO;
6886#endif /* IXGBE_FCOE */
6887 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006888 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006889 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006890 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6891 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006892 if (tso < 0) {
6893 dev_kfree_skb_any(skb);
6894 return NETDEV_TX_OK;
6895 }
6896
6897 if (tso)
6898 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006899 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6900 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006901 (skb->ip_summed == CHECKSUM_PARTIAL))
6902 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006903 }
6904
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006905 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006906 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006907 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006908 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6909 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006910 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006911 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006912
Alexander Duyck44df32c2009-03-31 21:34:23 +00006913 } else {
6914 dev_kfree_skb_any(skb);
6915 tx_ring->tx_buffer_info[first].time_stamp = 0;
6916 tx_ring->next_to_use = first;
6917 }
Auke Kok9a799d72007-09-15 14:07:45 -07006918
6919 return NETDEV_TX_OK;
6920}
6921
Alexander Duyck84418e32010-08-19 13:40:54 +00006922static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6923{
6924 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6925 struct ixgbe_ring *tx_ring;
6926
6927 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006928 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006929}
6930
Auke Kok9a799d72007-09-15 14:07:45 -07006931/**
Auke Kok9a799d72007-09-15 14:07:45 -07006932 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6933 * @netdev: network interface device structure
6934 * @p: pointer to an address structure
6935 *
6936 * Returns 0 on success, negative on failure
6937 **/
6938static int ixgbe_set_mac(struct net_device *netdev, void *p)
6939{
6940 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006941 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006942 struct sockaddr *addr = p;
6943
6944 if (!is_valid_ether_addr(addr->sa_data))
6945 return -EADDRNOTAVAIL;
6946
6947 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006948 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006949
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006950 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6951 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006952
6953 return 0;
6954}
6955
Ben Hutchings6b73e102009-04-29 08:08:58 +00006956static int
6957ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6958{
6959 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6960 struct ixgbe_hw *hw = &adapter->hw;
6961 u16 value;
6962 int rc;
6963
6964 if (prtad != hw->phy.mdio.prtad)
6965 return -EINVAL;
6966 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6967 if (!rc)
6968 rc = value;
6969 return rc;
6970}
6971
6972static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6973 u16 addr, u16 value)
6974{
6975 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6976 struct ixgbe_hw *hw = &adapter->hw;
6977
6978 if (prtad != hw->phy.mdio.prtad)
6979 return -EINVAL;
6980 return hw->phy.ops.write_reg(hw, addr, devad, value);
6981}
6982
6983static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6984{
6985 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6986
6987 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6988}
6989
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006990/**
6991 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006992 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006993 * @netdev: network interface device structure
6994 *
6995 * Returns non-zero on failure
6996 **/
6997static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6998{
6999 int err = 0;
7000 struct ixgbe_adapter *adapter = netdev_priv(dev);
7001 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7002
7003 if (is_valid_ether_addr(mac->san_addr)) {
7004 rtnl_lock();
7005 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7006 rtnl_unlock();
7007 }
7008 return err;
7009}
7010
7011/**
7012 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00007013 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007014 * @netdev: network interface device structure
7015 *
7016 * Returns non-zero on failure
7017 **/
7018static int ixgbe_del_sanmac_netdev(struct net_device *dev)
7019{
7020 int err = 0;
7021 struct ixgbe_adapter *adapter = netdev_priv(dev);
7022 struct ixgbe_mac_info *mac = &adapter->hw.mac;
7023
7024 if (is_valid_ether_addr(mac->san_addr)) {
7025 rtnl_lock();
7026 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
7027 rtnl_unlock();
7028 }
7029 return err;
7030}
7031
Auke Kok9a799d72007-09-15 14:07:45 -07007032#ifdef CONFIG_NET_POLL_CONTROLLER
7033/*
7034 * Polling 'interrupt' - used by things like netconsole to send skbs
7035 * without having to re-enable interrupts. It's not called while
7036 * the interrupt routine is executing.
7037 */
7038static void ixgbe_netpoll(struct net_device *netdev)
7039{
7040 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007041 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007042
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007043 /* if interface is down do nothing */
7044 if (test_bit(__IXGBE_DOWN, &adapter->state))
7045 return;
7046
Auke Kok9a799d72007-09-15 14:07:45 -07007047 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007048 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7049 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7050 for (i = 0; i < num_q_vectors; i++) {
7051 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7052 ixgbe_msix_clean_many(0, q_vector);
7053 }
7054 } else {
7055 ixgbe_intr(adapter->pdev->irq, netdev);
7056 }
Auke Kok9a799d72007-09-15 14:07:45 -07007057 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007058}
7059#endif
7060
Eric Dumazetde1036b2010-10-20 23:00:04 +00007061static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7062 struct rtnl_link_stats64 *stats)
7063{
7064 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7065 int i;
7066
Eric Dumazet1a515022010-11-16 19:26:42 -08007067 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007068 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007069 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007070 u64 bytes, packets;
7071 unsigned int start;
7072
Eric Dumazet1a515022010-11-16 19:26:42 -08007073 if (ring) {
7074 do {
7075 start = u64_stats_fetch_begin_bh(&ring->syncp);
7076 packets = ring->stats.packets;
7077 bytes = ring->stats.bytes;
7078 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7079 stats->rx_packets += packets;
7080 stats->rx_bytes += bytes;
7081 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007082 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007083
7084 for (i = 0; i < adapter->num_tx_queues; i++) {
7085 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7086 u64 bytes, packets;
7087 unsigned int start;
7088
7089 if (ring) {
7090 do {
7091 start = u64_stats_fetch_begin_bh(&ring->syncp);
7092 packets = ring->stats.packets;
7093 bytes = ring->stats.bytes;
7094 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7095 stats->tx_packets += packets;
7096 stats->tx_bytes += bytes;
7097 }
7098 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007099 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007100 /* following stats updated by ixgbe_watchdog_task() */
7101 stats->multicast = netdev->stats.multicast;
7102 stats->rx_errors = netdev->stats.rx_errors;
7103 stats->rx_length_errors = netdev->stats.rx_length_errors;
7104 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7105 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7106 return stats;
7107}
7108
7109
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007110static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007111 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007112 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007113 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007114 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007115 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007116 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7117 .ndo_validate_addr = eth_validate_addr,
7118 .ndo_set_mac_address = ixgbe_set_mac,
7119 .ndo_change_mtu = ixgbe_change_mtu,
7120 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007121 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7122 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007123 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007124 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7125 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7126 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7127 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007128 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007129#ifdef CONFIG_IXGBE_DCB
7130 .ndo_setup_tc = ixgbe_setup_tc,
7131#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007132#ifdef CONFIG_NET_POLL_CONTROLLER
7133 .ndo_poll_controller = ixgbe_netpoll,
7134#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007135#ifdef IXGBE_FCOE
7136 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007137 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007138 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007139 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7140 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007141 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007142#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007143};
7144
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007145static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7146 const struct ixgbe_info *ii)
7147{
7148#ifdef CONFIG_PCI_IOV
7149 struct ixgbe_hw *hw = &adapter->hw;
7150 int err;
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007151 int num_vf_macvlans, i;
7152 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007153
Greg Rose3377eba792010-12-07 08:16:45 +00007154 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007155 return;
7156
7157 /* The 82599 supports up to 64 VFs per physical function
7158 * but this implementation limits allocation to 63 so that
7159 * basic networking resources are still available to the
7160 * physical function
7161 */
7162 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7163 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7164 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7165 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007166 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007167 goto err_novfs;
7168 }
Greg Rosea1cbb15c2011-05-13 01:33:48 +00007169
7170 num_vf_macvlans = hw->mac.num_rar_entries -
7171 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7172
7173 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7174 sizeof(struct vf_macvlans),
7175 GFP_KERNEL);
7176 if (mv_list) {
7177 /* Initialize list of VF macvlans */
7178 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7179 for (i = 0; i < num_vf_macvlans; i++) {
7180 mv_list->vf = -1;
7181 mv_list->free = true;
7182 mv_list->rar_entry = hw->mac.num_rar_entries -
7183 (i + adapter->num_vfs + 1);
7184 list_add(&mv_list->l, &adapter->vf_mvs.l);
7185 mv_list++;
7186 }
7187 }
7188
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007189 /* If call to enable VFs succeeded then allocate memory
7190 * for per VF control structures.
7191 */
7192 adapter->vfinfo =
7193 kcalloc(adapter->num_vfs,
7194 sizeof(struct vf_data_storage), GFP_KERNEL);
7195 if (adapter->vfinfo) {
7196 /* Now that we're sure SR-IOV is enabled
7197 * and memory allocated set up the mailbox parameters
7198 */
7199 ixgbe_init_mbx_params_pf(hw);
7200 memcpy(&hw->mbx.ops, ii->mbx_ops,
7201 sizeof(hw->mbx.ops));
7202
7203 /* Disable RSC when in SR-IOV mode */
7204 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7205 IXGBE_FLAG2_RSC_ENABLED);
7206 return;
7207 }
7208
7209 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007210 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7211 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007212 pci_disable_sriov(adapter->pdev);
7213
7214err_novfs:
7215 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7216 adapter->num_vfs = 0;
7217#endif /* CONFIG_PCI_IOV */
7218}
7219
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007220/**
Auke Kok9a799d72007-09-15 14:07:45 -07007221 * ixgbe_probe - Device Initialization Routine
7222 * @pdev: PCI device information struct
7223 * @ent: entry in ixgbe_pci_tbl
7224 *
7225 * Returns 0 on success, negative on failure
7226 *
7227 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7228 * The OS initialization, configuring of the adapter private structure,
7229 * and a hardware reset occur.
7230 **/
7231static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007232 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007233{
7234 struct net_device *netdev;
7235 struct ixgbe_adapter *adapter = NULL;
7236 struct ixgbe_hw *hw;
7237 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007238 static int cards_found;
7239 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007240 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007241 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007242#ifdef IXGBE_FCOE
7243 u16 device_caps;
7244#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007245 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007246
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007247 /* Catch broken hardware that put the wrong VF device ID in
7248 * the PCIe SR-IOV capability.
7249 */
7250 if (pdev->is_virtfn) {
7251 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7252 pci_name(pdev), pdev->vendor, pdev->device);
7253 return -EINVAL;
7254 }
7255
gouji-new9ce77662009-05-06 10:44:45 +00007256 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007257 if (err)
7258 return err;
7259
Nick Nunley1b507732010-04-27 13:10:27 +00007260 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7261 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007262 pci_using_dac = 1;
7263 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007264 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007265 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007266 err = dma_set_coherent_mask(&pdev->dev,
7267 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007268 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007269 dev_err(&pdev->dev,
7270 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007271 goto err_dma;
7272 }
7273 }
7274 pci_using_dac = 0;
7275 }
7276
gouji-new9ce77662009-05-06 10:44:45 +00007277 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007278 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007279 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007280 dev_err(&pdev->dev,
7281 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007282 goto err_pci_reg;
7283 }
7284
Frans Pop19d5afd2009-10-02 10:04:12 -07007285 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007286
Auke Kok9a799d72007-09-15 14:07:45 -07007287 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007288 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007289
John Fastabendc85a2612010-02-25 23:15:21 +00007290 if (ii->mac == ixgbe_mac_82598EB)
7291 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7292 else
7293 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7294
John Fastabende5b64632011-03-08 03:44:52 +00007295#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007296 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007297#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007298 indices += min_t(unsigned int, num_possible_cpus(),
7299 IXGBE_MAX_FCOE_INDICES);
7300#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007301 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007302 if (!netdev) {
7303 err = -ENOMEM;
7304 goto err_alloc_etherdev;
7305 }
7306
Auke Kok9a799d72007-09-15 14:07:45 -07007307 SET_NETDEV_DEV(netdev, &pdev->dev);
7308
Auke Kok9a799d72007-09-15 14:07:45 -07007309 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007310 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007311
7312 adapter->netdev = netdev;
7313 adapter->pdev = pdev;
7314 hw = &adapter->hw;
7315 hw->back = adapter;
7316 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7317
Jeff Kirsher05857982008-09-11 19:57:00 -07007318 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007319 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007320 if (!hw->hw_addr) {
7321 err = -EIO;
7322 goto err_ioremap;
7323 }
7324
7325 for (i = 1; i <= 5; i++) {
7326 if (pci_resource_len(pdev, i) == 0)
7327 continue;
7328 }
7329
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007330 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007331 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007332 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007333 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007334
Auke Kok9a799d72007-09-15 14:07:45 -07007335 adapter->bd_number = cards_found;
7336
Auke Kok9a799d72007-09-15 14:07:45 -07007337 /* Setup hw api */
7338 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007339 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007340
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007341 /* EEPROM */
7342 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7343 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7344 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7345 if (!(eec & (1 << 8)))
7346 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7347
7348 /* PHY */
7349 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007350 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007351 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7352 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7353 hw->phy.mdio.mmds = 0;
7354 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7355 hw->phy.mdio.dev = netdev;
7356 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7357 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007358
Don Skidmore8ca783a2009-05-26 20:40:47 -07007359 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007360
7361 /* setup the private structure */
7362 err = ixgbe_sw_init(adapter);
7363 if (err)
7364 goto err_sw_init;
7365
Don Skidmoree86bff02010-02-11 04:14:08 +00007366 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007367 switch (adapter->hw.mac.type) {
7368 case ixgbe_mac_82599EB:
7369 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007370 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007371 break;
7372 default:
7373 break;
7374 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007375
Don Skidmorebf069c92009-05-07 10:39:54 +00007376 /*
7377 * If there is a fan on this device and it has failed log the
7378 * failure.
7379 */
7380 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7381 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7382 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007383 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007384 }
7385
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007386 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007387 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007388 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007389 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007390 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7391 hw->mac.type == ixgbe_mac_82598EB) {
Don Skidmore8ca783a2009-05-26 20:40:47 -07007392 err = 0;
7393 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Alexander Duyck70864002011-04-27 09:13:56 +00007394 e_dev_err("failed to load because an unsupported SFP+ "
Emil Tantilov849c4542010-06-03 16:53:41 +00007395 "module type was detected.\n");
7396 e_dev_err("Reload the driver after installing a supported "
7397 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007398 goto err_sw_init;
7399 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007400 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007401 goto err_sw_init;
7402 }
7403
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007404 ixgbe_probe_vf(adapter, ii);
7405
Emil Tantilov396e7992010-07-01 20:05:12 +00007406 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007407 NETIF_F_IP_CSUM |
7408 NETIF_F_HW_VLAN_TX |
7409 NETIF_F_HW_VLAN_RX |
7410 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007411
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007412 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007413 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007414 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007415 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007416 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007417
Don Skidmore58be7662011-04-12 09:42:11 +00007418 switch (adapter->hw.mac.type) {
7419 case ixgbe_mac_82599EB:
7420 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007421 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007422 break;
7423 default:
7424 break;
7425 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007426
Jeff Kirsherad31c402008-06-05 04:05:30 -07007427 netdev->vlan_features |= NETIF_F_TSO;
7428 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007429 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007430 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007431 netdev->vlan_features |= NETIF_F_SG;
7432
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007433 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7434 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7435 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007436
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007437#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007438 netdev->dcbnl_ops = &dcbnl_ops;
7439#endif
7440
Yi Zoueacd73f2009-05-13 13:11:06 +00007441#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007442 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007443 if (hw->mac.ops.get_device_caps) {
7444 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007445 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7446 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007447 }
7448 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007449 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7450 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7451 netdev->vlan_features |= NETIF_F_FSO;
7452 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7453 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007454#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007455 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007456 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007457 netdev->vlan_features |= NETIF_F_HIGHDMA;
7458 }
Auke Kok9a799d72007-09-15 14:07:45 -07007459
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007460 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007461 netdev->features |= NETIF_F_LRO;
7462
Auke Kok9a799d72007-09-15 14:07:45 -07007463 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007464 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007465 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007466 err = -EIO;
7467 goto err_eeprom;
7468 }
7469
7470 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7471 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7472
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007473 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007474 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007475 err = -EIO;
7476 goto err_eeprom;
7477 }
7478
Don Skidmorec6ecf392010-12-03 03:31:51 +00007479 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7480 if (hw->mac.ops.disable_tx_laser &&
7481 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007482 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007483 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007484 hw->mac.ops.disable_tx_laser(hw);
7485
Alexander Duyck70864002011-04-27 09:13:56 +00007486 setup_timer(&adapter->service_timer, &ixgbe_service_timer,
7487 (unsigned long) adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007488 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00007489 adapter->watchdog_timer.function = ixgbe_watchdog;
Auke Kok9a799d72007-09-15 14:07:45 -07007490 adapter->watchdog_timer.data = (unsigned long)adapter;
7491
7492 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007493 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007494
Alexander Duyck70864002011-04-27 09:13:56 +00007495 INIT_WORK(&adapter->service_task, ixgbe_service_task);
7496 clear_bit(__IXGBE_SERVICE_SCHED, &adapter->state);
7497
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007498 err = ixgbe_init_interrupt_scheme(adapter);
7499 if (err)
7500 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007501
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007502 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7503 netdev->features &= ~NETIF_F_RXHASH;
7504
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007505 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007506 case IXGBE_DEV_ID_82599_SFP:
7507 /* Only this subdevice supports WOL */
7508 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7509 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7510 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7511 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007512 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7513 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007514 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7515 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7516 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7517 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007518 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007519 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007520 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007521 break;
7522 default:
7523 adapter->wol = 0;
7524 break;
7525 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007526 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7527
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007528 /* pick up the PCI bus settings for reporting later */
7529 hw->mac.ops.get_bus_info(hw);
7530
Auke Kok9a799d72007-09-15 14:07:45 -07007531 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007532 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007533 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7534 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007535 "Unknown"),
7536 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7537 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7538 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7539 "Unknown"),
7540 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007541
7542 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7543 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007544 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007545 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007546 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007547 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007548 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007549 else
Don Skidmore289700db2010-12-03 03:32:58 +00007550 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7551 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007552
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007553 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007554 e_dev_warn("PCI-Express bandwidth available for this card is "
7555 "not sufficient for optimal performance.\n");
7556 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7557 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007558 }
7559
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007560 /* save off EEPROM version number */
7561 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7562
Auke Kok9a799d72007-09-15 14:07:45 -07007563 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007564 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007565
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007566 if (err == IXGBE_ERR_EEPROM_VERSION) {
7567 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007568 e_dev_warn("This device is a pre-production adapter/LOM. "
7569 "Please be aware there may be issues associated "
7570 "with your hardware. If you are experiencing "
7571 "problems please contact your Intel or hardware "
7572 "representative who provided you with this "
7573 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007574 }
Auke Kok9a799d72007-09-15 14:07:45 -07007575 strcpy(netdev->name, "eth%d");
7576 err = register_netdev(netdev);
7577 if (err)
7578 goto err_register;
7579
Jesse Brandeburg54386462009-04-17 20:44:27 +00007580 /* carrier off reporting is important to ethtool even BEFORE open */
7581 netif_carrier_off(netdev);
7582
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007583 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7584 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7585 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
7586
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007587 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Joe Perchese8e9f692010-09-07 21:34:53 +00007588 INIT_WORK(&adapter->check_overtemp_task,
7589 ixgbe_check_overtemp_task);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007590#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007591 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007592 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007593 ixgbe_setup_dca(adapter);
7594 }
7595#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007596 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007597 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007598 for (i = 0; i < adapter->num_vfs; i++)
7599 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7600 }
7601
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007602 /* add san mac addr to netdev */
7603 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007604
Emil Tantilov849c4542010-06-03 16:53:41 +00007605 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007606 cards_found++;
7607 return 0;
7608
7609err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007610 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007611 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007612err_sw_init:
7613err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007614 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7615 ixgbe_disable_sriov(adapter);
Alexander Duyck70864002011-04-27 09:13:56 +00007616 adapter->flags2 &= ~IXGBE_FLAG2_SEARCH_FOR_SFP;
Auke Kok9a799d72007-09-15 14:07:45 -07007617 iounmap(hw->hw_addr);
7618err_ioremap:
7619 free_netdev(netdev);
7620err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007621 pci_release_selected_regions(pdev,
7622 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007623err_pci_reg:
7624err_dma:
7625 pci_disable_device(pdev);
7626 return err;
7627}
7628
7629/**
7630 * ixgbe_remove - Device Removal Routine
7631 * @pdev: PCI device information struct
7632 *
7633 * ixgbe_remove is called by the PCI subsystem to alert the driver
7634 * that it should release a PCI device. The could be caused by a
7635 * Hot-Plug event, or because the driver is going to be removed from
7636 * memory.
7637 **/
7638static void __devexit ixgbe_remove(struct pci_dev *pdev)
7639{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007640 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7641 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007642
7643 set_bit(__IXGBE_DOWN, &adapter->state);
Alexander Duyck70864002011-04-27 09:13:56 +00007644 cancel_work_sync(&adapter->service_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007645
7646 /*
7647 * The timers may be rescheduled, so explicitly disable them
7648 * from being rescheduled.
Donald Skidmorec4900be2008-11-20 21:11:42 -08007649 */
Auke Kok9a799d72007-09-15 14:07:45 -07007650 del_timer_sync(&adapter->watchdog_timer);
Tejun Heo760141a2010-12-12 16:45:14 +01007651
Donald Skidmorec4900be2008-11-20 21:11:42 -08007652 cancel_work_sync(&adapter->watchdog_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007653 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7654 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7655 cancel_work_sync(&adapter->fdir_reinit_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007656 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
7657 cancel_work_sync(&adapter->check_overtemp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007658
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007659#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007660 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7661 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7662 dca_remove_requester(&pdev->dev);
7663 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7664 }
7665
7666#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007667#ifdef IXGBE_FCOE
7668 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7669 ixgbe_cleanup_fcoe(adapter);
7670
7671#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007672
7673 /* remove the added san mac */
7674 ixgbe_del_sanmac_netdev(netdev);
7675
Donald Skidmorec4900be2008-11-20 21:11:42 -08007676 if (netdev->reg_state == NETREG_REGISTERED)
7677 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007678
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007679 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7680 ixgbe_disable_sriov(adapter);
7681
Alexander Duyck7a921c92009-05-06 10:43:28 +00007682 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007683
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007684 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007685
7686 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007687 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007688 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007689
Emil Tantilov849c4542010-06-03 16:53:41 +00007690 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007691
Auke Kok9a799d72007-09-15 14:07:45 -07007692 free_netdev(netdev);
7693
Frans Pop19d5afd2009-10-02 10:04:12 -07007694 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007695
Auke Kok9a799d72007-09-15 14:07:45 -07007696 pci_disable_device(pdev);
7697}
7698
7699/**
7700 * ixgbe_io_error_detected - called when PCI error is detected
7701 * @pdev: Pointer to PCI device
7702 * @state: The current pci connection state
7703 *
7704 * This function is called after a PCI bus error affecting
7705 * this device has been detected.
7706 */
7707static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007708 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007709{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007710 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7711 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007712
7713 netif_device_detach(netdev);
7714
Breno Leitao3044b8d2009-05-06 10:44:26 +00007715 if (state == pci_channel_io_perm_failure)
7716 return PCI_ERS_RESULT_DISCONNECT;
7717
Auke Kok9a799d72007-09-15 14:07:45 -07007718 if (netif_running(netdev))
7719 ixgbe_down(adapter);
7720 pci_disable_device(pdev);
7721
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007722 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007723 return PCI_ERS_RESULT_NEED_RESET;
7724}
7725
7726/**
7727 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7728 * @pdev: Pointer to PCI device
7729 *
7730 * Restart the card from scratch, as if from a cold-boot.
7731 */
7732static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7733{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007734 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007735 pci_ers_result_t result;
7736 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007737
gouji-new9ce77662009-05-06 10:44:45 +00007738 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007739 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007740 result = PCI_ERS_RESULT_DISCONNECT;
7741 } else {
7742 pci_set_master(pdev);
7743 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007744 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007745
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007746 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007747
7748 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007749 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007750 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007751 }
Auke Kok9a799d72007-09-15 14:07:45 -07007752
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007753 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7754 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007755 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7756 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007757 /* non-fatal, continue */
7758 }
Auke Kok9a799d72007-09-15 14:07:45 -07007759
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007760 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007761}
7762
7763/**
7764 * ixgbe_io_resume - called when traffic can start flowing again.
7765 * @pdev: Pointer to PCI device
7766 *
7767 * This callback is called when the error recovery driver tells us that
7768 * its OK to resume normal operation.
7769 */
7770static void ixgbe_io_resume(struct pci_dev *pdev)
7771{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007772 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7773 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007774
7775 if (netif_running(netdev)) {
7776 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007777 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007778 return;
7779 }
7780 }
7781
7782 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007783}
7784
7785static struct pci_error_handlers ixgbe_err_handler = {
7786 .error_detected = ixgbe_io_error_detected,
7787 .slot_reset = ixgbe_io_slot_reset,
7788 .resume = ixgbe_io_resume,
7789};
7790
7791static struct pci_driver ixgbe_driver = {
7792 .name = ixgbe_driver_name,
7793 .id_table = ixgbe_pci_tbl,
7794 .probe = ixgbe_probe,
7795 .remove = __devexit_p(ixgbe_remove),
7796#ifdef CONFIG_PM
7797 .suspend = ixgbe_suspend,
7798 .resume = ixgbe_resume,
7799#endif
7800 .shutdown = ixgbe_shutdown,
7801 .err_handler = &ixgbe_err_handler
7802};
7803
7804/**
7805 * ixgbe_init_module - Driver Registration Routine
7806 *
7807 * ixgbe_init_module is the first routine called when the driver is
7808 * loaded. All it does is register with the PCI subsystem.
7809 **/
7810static int __init ixgbe_init_module(void)
7811{
7812 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007813 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007814 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007815
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007816#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007817 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007818#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007819
Auke Kok9a799d72007-09-15 14:07:45 -07007820 ret = pci_register_driver(&ixgbe_driver);
7821 return ret;
7822}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007823
Auke Kok9a799d72007-09-15 14:07:45 -07007824module_init(ixgbe_init_module);
7825
7826/**
7827 * ixgbe_exit_module - Driver Exit Cleanup Routine
7828 *
7829 * ixgbe_exit_module is called just before the driver is removed
7830 * from memory.
7831 **/
7832static void __exit ixgbe_exit_module(void)
7833{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007834#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007835 dca_unregister_notify(&dca_notifier);
7836#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007837 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007838 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007839}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007840
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007841#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007842static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007843 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007844{
7845 int ret_val;
7846
7847 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007848 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007849
7850 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7851}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007852
Alexander Duyckb4533682009-03-31 21:32:42 +00007853#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007854
Auke Kok9a799d72007-09-15 14:07:45 -07007855module_exit(ixgbe_exit_module);
7856
7857/* ixgbe_main.c */