blob: f8196e0d2745c0f73258a4c99efa6838cbb3ac1a [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 Skidmorefe15e8e2010-11-16 19:27:16 -080067 [board_X540] = &ixgbe_X540_info,
Auke Kok9a799d72007-09-15 14:07:45 -070068};
69
70/* ixgbe_pci_tbl - PCI Device ID Table
71 *
72 * Wildcard entries (PCI_ANY_ID) should come last
73 * Last entry must be all 0s
74 *
75 * { Vendor ID, Device ID, SubVendor ID, SubDevice ID,
76 * Class, Class Mask, private data (not used) }
77 */
Alexey Dobriyana3aa1882010-01-07 11:58:11 +000078static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = {
Don Skidmore1e336d02009-01-26 20:57:51 -080079 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598),
80 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070081 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070082 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070083 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT),
Auke Kok3957d632007-10-31 15:22:10 -070084 board_82598 },
Jesse Brandeburg0befdb32008-10-31 00:46:40 -070085 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT),
86 board_82598 },
Peter P Waskiewicz Jr3845bec2009-07-16 15:50:52 +000087 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2),
88 board_82598 },
Auke Kok9a799d72007-09-15 14:07:45 -070089 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4),
Auke Kok3957d632007-10-31 15:22:10 -070090 board_82598 },
Jesse Brandeburg8d792cd2008-08-08 16:24:19 -070091 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT),
92 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080093 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT),
94 board_82598 },
95 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM),
96 board_82598 },
Jesse Brandeburgb95f5fc2008-09-11 19:58:59 -070097 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR),
98 board_82598 },
Donald Skidmorec4900be2008-11-20 21:11:42 -080099 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM),
100 board_82598 },
Don Skidmore2f21bdd2009-02-01 01:18:23 -0800101 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX),
102 board_82598 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000103 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4),
104 board_82599 },
Peter P Waskiewicz Jr1fcf03e2009-05-17 20:58:04 +0000105 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM),
106 board_82599 },
Don Skidmore74757d42009-12-08 07:22:23 +0000107 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR),
108 board_82599 },
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000109 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP),
110 board_82599 },
Don Skidmore38ad1c82009-10-08 15:35:58 +0000111 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM),
112 board_82599 },
Don Skidmoredbfec662009-10-02 08:58:25 +0000113 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ),
114 board_82599 },
Peter P Waskiewicz Jr89111842009-09-14 07:47:49 +0000115 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4),
116 board_82599 },
Don Skidmoredbffcb22010-12-03 03:32:34 +0000117 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_BACKPLANE_FCOE),
118 board_82599 },
119 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_FCOE),
120 board_82599 },
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -0700121 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_T3_LOM),
122 board_82599 },
Don Skidmore312eb932009-10-02 08:58:04 +0000123 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE),
124 board_82599 },
Don Skidmoreb93a2222010-11-16 19:27:17 -0800125 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_X540T),
Don Skidmored9946532010-12-09 06:55:19 +0000126 board_X540 },
Emil Tantilov4c40ef02011-03-24 07:06:02 +0000127 {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_SF2),
128 board_82599 },
Auke Kok9a799d72007-09-15 14:07:45 -0700129
130 /* required last entry */
131 {0, }
132};
133MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl);
134
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400135#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800136static int ixgbe_notify_dca(struct notifier_block *, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +0000137 void *p);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800138static struct notifier_block dca_notifier = {
139 .notifier_call = ixgbe_notify_dca,
140 .next = NULL,
141 .priority = 0
142};
143#endif
144
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000145#ifdef CONFIG_PCI_IOV
146static unsigned int max_vfs;
147module_param(max_vfs, uint, 0);
Joe Perchese8e9f692010-09-07 21:34:53 +0000148MODULE_PARM_DESC(max_vfs,
149 "Maximum number of virtual functions to allocate per physical function");
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000150#endif /* CONFIG_PCI_IOV */
151
Auke Kok9a799d72007-09-15 14:07:45 -0700152MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>");
153MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver");
154MODULE_LICENSE("GPL");
155MODULE_VERSION(DRV_VERSION);
156
157#define DEFAULT_DEBUG_LEVEL_SHIFT 3
158
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000159static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter)
160{
161 struct ixgbe_hw *hw = &adapter->hw;
162 u32 gcr;
163 u32 gpie;
164 u32 vmdctl;
165
166#ifdef CONFIG_PCI_IOV
167 /* disable iov and allow time for transactions to clear */
168 pci_disable_sriov(adapter->pdev);
169#endif
170
171 /* turn off device IOV mode */
172 gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
173 gcr &= ~(IXGBE_GCR_EXT_SRIOV);
174 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr);
175 gpie = IXGBE_READ_REG(hw, IXGBE_GPIE);
176 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
177 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
178
179 /* set default pool back to 0 */
180 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
181 vmdctl &= ~IXGBE_VT_CTL_POOL_MASK;
182 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl);
183
184 /* take a breather then clean up driver data */
185 msleep(100);
Joe Perchese8e9f692010-09-07 21:34:53 +0000186
187 kfree(adapter->vfinfo);
Greg Rose1cdd1ec2010-01-09 02:26:46 +0000188 adapter->vfinfo = NULL;
189
190 adapter->num_vfs = 0;
191 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
192}
193
Taku Izumidcd79ae2010-04-27 14:39:53 +0000194struct ixgbe_reg_info {
195 u32 ofs;
196 char *name;
197};
198
199static const struct ixgbe_reg_info ixgbe_reg_info_tbl[] = {
200
201 /* General Registers */
202 {IXGBE_CTRL, "CTRL"},
203 {IXGBE_STATUS, "STATUS"},
204 {IXGBE_CTRL_EXT, "CTRL_EXT"},
205
206 /* Interrupt Registers */
207 {IXGBE_EICR, "EICR"},
208
209 /* RX Registers */
210 {IXGBE_SRRCTL(0), "SRRCTL"},
211 {IXGBE_DCA_RXCTRL(0), "DRXCTL"},
212 {IXGBE_RDLEN(0), "RDLEN"},
213 {IXGBE_RDH(0), "RDH"},
214 {IXGBE_RDT(0), "RDT"},
215 {IXGBE_RXDCTL(0), "RXDCTL"},
216 {IXGBE_RDBAL(0), "RDBAL"},
217 {IXGBE_RDBAH(0), "RDBAH"},
218
219 /* TX Registers */
220 {IXGBE_TDBAL(0), "TDBAL"},
221 {IXGBE_TDBAH(0), "TDBAH"},
222 {IXGBE_TDLEN(0), "TDLEN"},
223 {IXGBE_TDH(0), "TDH"},
224 {IXGBE_TDT(0), "TDT"},
225 {IXGBE_TXDCTL(0), "TXDCTL"},
226
227 /* List Terminator */
228 {}
229};
230
231
232/*
233 * ixgbe_regdump - register printout routine
234 */
235static void ixgbe_regdump(struct ixgbe_hw *hw, struct ixgbe_reg_info *reginfo)
236{
237 int i = 0, j = 0;
238 char rname[16];
239 u32 regs[64];
240
241 switch (reginfo->ofs) {
242 case IXGBE_SRRCTL(0):
243 for (i = 0; i < 64; i++)
244 regs[i] = IXGBE_READ_REG(hw, IXGBE_SRRCTL(i));
245 break;
246 case IXGBE_DCA_RXCTRL(0):
247 for (i = 0; i < 64; i++)
248 regs[i] = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(i));
249 break;
250 case IXGBE_RDLEN(0):
251 for (i = 0; i < 64; i++)
252 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDLEN(i));
253 break;
254 case IXGBE_RDH(0):
255 for (i = 0; i < 64; i++)
256 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDH(i));
257 break;
258 case IXGBE_RDT(0):
259 for (i = 0; i < 64; i++)
260 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDT(i));
261 break;
262 case IXGBE_RXDCTL(0):
263 for (i = 0; i < 64; i++)
264 regs[i] = IXGBE_READ_REG(hw, IXGBE_RXDCTL(i));
265 break;
266 case IXGBE_RDBAL(0):
267 for (i = 0; i < 64; i++)
268 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAL(i));
269 break;
270 case IXGBE_RDBAH(0):
271 for (i = 0; i < 64; i++)
272 regs[i] = IXGBE_READ_REG(hw, IXGBE_RDBAH(i));
273 break;
274 case IXGBE_TDBAL(0):
275 for (i = 0; i < 64; i++)
276 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAL(i));
277 break;
278 case IXGBE_TDBAH(0):
279 for (i = 0; i < 64; i++)
280 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDBAH(i));
281 break;
282 case IXGBE_TDLEN(0):
283 for (i = 0; i < 64; i++)
284 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDLEN(i));
285 break;
286 case IXGBE_TDH(0):
287 for (i = 0; i < 64; i++)
288 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDH(i));
289 break;
290 case IXGBE_TDT(0):
291 for (i = 0; i < 64; i++)
292 regs[i] = IXGBE_READ_REG(hw, IXGBE_TDT(i));
293 break;
294 case IXGBE_TXDCTL(0):
295 for (i = 0; i < 64; i++)
296 regs[i] = IXGBE_READ_REG(hw, IXGBE_TXDCTL(i));
297 break;
298 default:
Joe Perchesc7689572010-09-07 21:35:17 +0000299 pr_info("%-15s %08x\n", reginfo->name,
Taku Izumidcd79ae2010-04-27 14:39:53 +0000300 IXGBE_READ_REG(hw, reginfo->ofs));
301 return;
302 }
303
304 for (i = 0; i < 8; i++) {
305 snprintf(rname, 16, "%s[%d-%d]", reginfo->name, i*8, i*8+7);
Joe Perchesc7689572010-09-07 21:35:17 +0000306 pr_err("%-15s", rname);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000307 for (j = 0; j < 8; j++)
Joe Perchesc7689572010-09-07 21:35:17 +0000308 pr_cont(" %08x", regs[i*8+j]);
309 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000310 }
311
312}
313
314/*
315 * ixgbe_dump - Print registers, tx-rings and rx-rings
316 */
317static void ixgbe_dump(struct ixgbe_adapter *adapter)
318{
319 struct net_device *netdev = adapter->netdev;
320 struct ixgbe_hw *hw = &adapter->hw;
321 struct ixgbe_reg_info *reginfo;
322 int n = 0;
323 struct ixgbe_ring *tx_ring;
324 struct ixgbe_tx_buffer *tx_buffer_info;
325 union ixgbe_adv_tx_desc *tx_desc;
326 struct my_u0 { u64 a; u64 b; } *u0;
327 struct ixgbe_ring *rx_ring;
328 union ixgbe_adv_rx_desc *rx_desc;
329 struct ixgbe_rx_buffer *rx_buffer_info;
330 u32 staterr;
331 int i = 0;
332
333 if (!netif_msg_hw(adapter))
334 return;
335
336 /* Print netdevice Info */
337 if (netdev) {
338 dev_info(&adapter->pdev->dev, "Net device Info\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000339 pr_info("Device Name state "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000340 "trans_start last_rx\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000341 pr_info("%-15s %016lX %016lX %016lX\n",
342 netdev->name,
343 netdev->state,
344 netdev->trans_start,
345 netdev->last_rx);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000346 }
347
348 /* Print Registers */
349 dev_info(&adapter->pdev->dev, "Register Dump\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000350 pr_info(" Register Name Value\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000351 for (reginfo = (struct ixgbe_reg_info *)ixgbe_reg_info_tbl;
352 reginfo->name; reginfo++) {
353 ixgbe_regdump(hw, reginfo);
354 }
355
356 /* Print TX Ring Summary */
357 if (!netdev || !netif_running(netdev))
358 goto exit;
359
360 dev_info(&adapter->pdev->dev, "TX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000361 pr_info("Queue [NTU] [NTC] [bi(ntc)->dma ] leng ntw timestamp\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000362 for (n = 0; n < adapter->num_tx_queues; n++) {
363 tx_ring = adapter->tx_ring[n];
364 tx_buffer_info =
365 &tx_ring->tx_buffer_info[tx_ring->next_to_clean];
Joe Perchesc7689572010-09-07 21:35:17 +0000366 pr_info(" %5d %5X %5X %016llX %04X %3X %016llX\n",
Taku Izumidcd79ae2010-04-27 14:39:53 +0000367 n, tx_ring->next_to_use, tx_ring->next_to_clean,
368 (u64)tx_buffer_info->dma,
369 tx_buffer_info->length,
370 tx_buffer_info->next_to_watch,
371 (u64)tx_buffer_info->time_stamp);
372 }
373
374 /* Print TX Rings */
375 if (!netif_msg_tx_done(adapter))
376 goto rx_ring_summary;
377
378 dev_info(&adapter->pdev->dev, "TX Rings Dump\n");
379
380 /* Transmit Descriptor Formats
381 *
382 * Advanced Transmit Descriptor
383 * +--------------------------------------------------------------+
384 * 0 | Buffer Address [63:0] |
385 * +--------------------------------------------------------------+
386 * 8 | PAYLEN | PORTS | IDX | STA | DCMD |DTYP | RSV | DTALEN |
387 * +--------------------------------------------------------------+
388 * 63 46 45 40 39 36 35 32 31 24 23 20 19 0
389 */
390
391 for (n = 0; n < adapter->num_tx_queues; n++) {
392 tx_ring = adapter->tx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000393 pr_info("------------------------------------\n");
394 pr_info("TX QUEUE INDEX = %d\n", tx_ring->queue_index);
395 pr_info("------------------------------------\n");
396 pr_info("T [desc] [address 63:0 ] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000397 "[PlPOIdStDDt Ln] [bi->dma ] "
398 "leng ntw timestamp bi->skb\n");
399
400 for (i = 0; tx_ring->desc && (i < tx_ring->count); i++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000401 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000402 tx_buffer_info = &tx_ring->tx_buffer_info[i];
403 u0 = (struct my_u0 *)tx_desc;
Joe Perchesc7689572010-09-07 21:35:17 +0000404 pr_info("T [0x%03X] %016llX %016llX %016llX"
Taku Izumidcd79ae2010-04-27 14:39:53 +0000405 " %04X %3X %016llX %p", i,
406 le64_to_cpu(u0->a),
407 le64_to_cpu(u0->b),
408 (u64)tx_buffer_info->dma,
409 tx_buffer_info->length,
410 tx_buffer_info->next_to_watch,
411 (u64)tx_buffer_info->time_stamp,
412 tx_buffer_info->skb);
413 if (i == tx_ring->next_to_use &&
414 i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000415 pr_cont(" NTC/U\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000416 else if (i == tx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000417 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000418 else if (i == tx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000419 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000420 else
Joe Perchesc7689572010-09-07 21:35:17 +0000421 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000422
423 if (netif_msg_pktdata(adapter) &&
424 tx_buffer_info->dma != 0)
425 print_hex_dump(KERN_INFO, "",
426 DUMP_PREFIX_ADDRESS, 16, 1,
427 phys_to_virt(tx_buffer_info->dma),
428 tx_buffer_info->length, true);
429 }
430 }
431
432 /* Print RX Rings Summary */
433rx_ring_summary:
434 dev_info(&adapter->pdev->dev, "RX Rings Summary\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000435 pr_info("Queue [NTU] [NTC]\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000436 for (n = 0; n < adapter->num_rx_queues; n++) {
437 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000438 pr_info("%5d %5X %5X\n",
439 n, rx_ring->next_to_use, rx_ring->next_to_clean);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000440 }
441
442 /* Print RX Rings */
443 if (!netif_msg_rx_status(adapter))
444 goto exit;
445
446 dev_info(&adapter->pdev->dev, "RX Rings Dump\n");
447
448 /* Advanced Receive Descriptor (Read) Format
449 * 63 1 0
450 * +-----------------------------------------------------+
451 * 0 | Packet Buffer Address [63:1] |A0/NSE|
452 * +----------------------------------------------+------+
453 * 8 | Header Buffer Address [63:1] | DD |
454 * +-----------------------------------------------------+
455 *
456 *
457 * Advanced Receive Descriptor (Write-Back) Format
458 *
459 * 63 48 47 32 31 30 21 20 16 15 4 3 0
460 * +------------------------------------------------------+
461 * 0 | Packet IP |SPH| HDR_LEN | RSV|Packet| RSS |
462 * | Checksum Ident | | | | Type | Type |
463 * +------------------------------------------------------+
464 * 8 | VLAN Tag | Length | Extended Error | Extended Status |
465 * +------------------------------------------------------+
466 * 63 48 47 32 31 20 19 0
467 */
468 for (n = 0; n < adapter->num_rx_queues; n++) {
469 rx_ring = adapter->rx_ring[n];
Joe Perchesc7689572010-09-07 21:35:17 +0000470 pr_info("------------------------------------\n");
471 pr_info("RX QUEUE INDEX = %d\n", rx_ring->queue_index);
472 pr_info("------------------------------------\n");
473 pr_info("R [desc] [ PktBuf A0] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000474 "[ HeadBuf DD] [bi->dma ] [bi->skb] "
475 "<-- Adv Rx Read format\n");
Joe Perchesc7689572010-09-07 21:35:17 +0000476 pr_info("RWB[desc] [PcsmIpSHl PtRs] "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000477 "[vl er S cks ln] ---------------- [bi->skb] "
478 "<-- Adv Rx Write-Back format\n");
479
480 for (i = 0; i < rx_ring->count; i++) {
481 rx_buffer_info = &rx_ring->rx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +0000482 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Taku Izumidcd79ae2010-04-27 14:39:53 +0000483 u0 = (struct my_u0 *)rx_desc;
484 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
485 if (staterr & IXGBE_RXD_STAT_DD) {
486 /* Descriptor Done */
Joe Perchesc7689572010-09-07 21:35:17 +0000487 pr_info("RWB[0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000488 "%016llX ---------------- %p", i,
489 le64_to_cpu(u0->a),
490 le64_to_cpu(u0->b),
491 rx_buffer_info->skb);
492 } else {
Joe Perchesc7689572010-09-07 21:35:17 +0000493 pr_info("R [0x%03X] %016llX "
Taku Izumidcd79ae2010-04-27 14:39:53 +0000494 "%016llX %016llX %p", i,
495 le64_to_cpu(u0->a),
496 le64_to_cpu(u0->b),
497 (u64)rx_buffer_info->dma,
498 rx_buffer_info->skb);
499
500 if (netif_msg_pktdata(adapter)) {
501 print_hex_dump(KERN_INFO, "",
502 DUMP_PREFIX_ADDRESS, 16, 1,
503 phys_to_virt(rx_buffer_info->dma),
504 rx_ring->rx_buf_len, true);
505
506 if (rx_ring->rx_buf_len
507 < IXGBE_RXBUFFER_2048)
508 print_hex_dump(KERN_INFO, "",
509 DUMP_PREFIX_ADDRESS, 16, 1,
510 phys_to_virt(
511 rx_buffer_info->page_dma +
512 rx_buffer_info->page_offset
513 ),
514 PAGE_SIZE/2, true);
515 }
516 }
517
518 if (i == rx_ring->next_to_use)
Joe Perchesc7689572010-09-07 21:35:17 +0000519 pr_cont(" NTU\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000520 else if (i == rx_ring->next_to_clean)
Joe Perchesc7689572010-09-07 21:35:17 +0000521 pr_cont(" NTC\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000522 else
Joe Perchesc7689572010-09-07 21:35:17 +0000523 pr_cont("\n");
Taku Izumidcd79ae2010-04-27 14:39:53 +0000524
525 }
526 }
527
528exit:
529 return;
530}
531
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800532static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter)
533{
534 u32 ctrl_ext;
535
536 /* Let firmware take over control of h/w */
537 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
538 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000539 ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800540}
541
542static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter)
543{
544 u32 ctrl_ext;
545
546 /* Let firmware know the driver has taken over */
547 ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT);
548 IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT,
Joe Perchese8e9f692010-09-07 21:34:53 +0000549 ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -0800550}
Auke Kok9a799d72007-09-15 14:07:45 -0700551
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000552/*
553 * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors
554 * @adapter: pointer to adapter struct
555 * @direction: 0 for Rx, 1 for Tx, -1 for other causes
556 * @queue: queue to map the corresponding interrupt to
557 * @msix_vector: the vector to map to the corresponding queue
558 *
559 */
560static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction,
Joe Perchese8e9f692010-09-07 21:34:53 +0000561 u8 queue, u8 msix_vector)
Auke Kok9a799d72007-09-15 14:07:45 -0700562{
563 u32 ivar, index;
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000564 struct ixgbe_hw *hw = &adapter->hw;
565 switch (hw->mac.type) {
566 case ixgbe_mac_82598EB:
567 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
568 if (direction == -1)
569 direction = 0;
570 index = (((direction * 64) + queue) >> 2) & 0x1F;
571 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index));
572 ivar &= ~(0xFF << (8 * (queue & 0x3)));
573 ivar |= (msix_vector << (8 * (queue & 0x3)));
574 IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar);
575 break;
576 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800577 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +0000578 if (direction == -1) {
579 /* other causes */
580 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
581 index = ((queue & 1) * 8);
582 ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC);
583 ivar &= ~(0xFF << index);
584 ivar |= (msix_vector << index);
585 IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar);
586 break;
587 } else {
588 /* tx or rx causes */
589 msix_vector |= IXGBE_IVAR_ALLOC_VAL;
590 index = ((16 * (queue & 1)) + (8 * direction));
591 ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1));
592 ivar &= ~(0xFF << index);
593 ivar |= (msix_vector << index);
594 IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar);
595 break;
596 }
597 default:
598 break;
599 }
Auke Kok9a799d72007-09-15 14:07:45 -0700600}
601
Alexander Duyckfe49f042009-06-04 16:00:09 +0000602static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +0000603 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +0000604{
605 u32 mask;
606
Alexander Duyckbd508172010-11-16 19:27:03 -0800607 switch (adapter->hw.mac.type) {
608 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000609 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
610 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800611 break;
612 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800613 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +0000614 mask = (qmask & 0xFFFFFFFF);
615 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask);
616 mask = (qmask >> 32);
617 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask);
Alexander Duyckbd508172010-11-16 19:27:03 -0800618 break;
619 default:
620 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +0000621 }
622}
623
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800624void ixgbe_unmap_and_free_tx_resource(struct ixgbe_ring *tx_ring,
625 struct ixgbe_tx_buffer *tx_buffer_info)
Auke Kok9a799d72007-09-15 14:07:45 -0700626{
Alexander Duycke5a43542009-12-02 16:46:56 +0000627 if (tx_buffer_info->dma) {
628 if (tx_buffer_info->mapped_as_page)
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800629 dma_unmap_page(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000630 tx_buffer_info->dma,
631 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000632 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000633 else
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800634 dma_unmap_single(tx_ring->dev,
Alexander Duycke5a43542009-12-02 16:46:56 +0000635 tx_buffer_info->dma,
636 tx_buffer_info->length,
Nick Nunley1b507732010-04-27 13:10:27 +0000637 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +0000638 tx_buffer_info->dma = 0;
639 }
Auke Kok9a799d72007-09-15 14:07:45 -0700640 if (tx_buffer_info->skb) {
641 dev_kfree_skb_any(tx_buffer_info->skb);
642 tx_buffer_info->skb = NULL;
643 }
Alexander Duyck44df32c2009-03-31 21:34:23 +0000644 tx_buffer_info->time_stamp = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700645 /* tx_buffer_info must be completely set up in the transmit path */
646}
647
Yi Zou26f23d82009-11-06 12:56:00 +0000648/**
John Fastabendc84d3242010-11-16 19:27:12 -0800649 * ixgbe_dcb_txq_to_tc - convert a reg index to a traffic class
650 * @adapter: driver private struct
651 * @index: reg idx of queue to query (0-127)
Yi Zou26f23d82009-11-06 12:56:00 +0000652 *
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300653 * Helper function to determine the traffic index for a particular
John Fastabendc84d3242010-11-16 19:27:12 -0800654 * register index.
Yi Zou26f23d82009-11-06 12:56:00 +0000655 *
John Fastabendc84d3242010-11-16 19:27:12 -0800656 * Returns : a tc index for use in range 0-7, or 0-3
Yi Zou26f23d82009-11-06 12:56:00 +0000657 */
Don Skidmore3b2ee942011-01-28 02:28:26 +0000658static u8 ixgbe_dcb_txq_to_tc(struct ixgbe_adapter *adapter, u8 reg_idx)
Yi Zou26f23d82009-11-06 12:56:00 +0000659{
John Fastabendc84d3242010-11-16 19:27:12 -0800660 int tc = -1;
John Fastabende5b64632011-03-08 03:44:52 +0000661 int dcb_i = netdev_get_num_tc(adapter->netdev);
Yi Zou26f23d82009-11-06 12:56:00 +0000662
John Fastabendc84d3242010-11-16 19:27:12 -0800663 /* if DCB is not enabled the queues have no TC */
664 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
665 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000666
John Fastabendc84d3242010-11-16 19:27:12 -0800667 /* check valid range */
668 if (reg_idx >= adapter->hw.mac.max_tx_queues)
669 return tc;
670
671 switch (adapter->hw.mac.type) {
672 case ixgbe_mac_82598EB:
673 tc = reg_idx >> 2;
674 break;
675 default:
676 if (dcb_i != 4 && dcb_i != 8)
PJ Waskiewicz6837e892010-01-06 17:50:29 +0000677 break;
John Fastabendc84d3242010-11-16 19:27:12 -0800678
679 /* if VMDq is enabled the lowest order bits determine TC */
680 if (adapter->flags & (IXGBE_FLAG_SRIOV_ENABLED |
681 IXGBE_FLAG_VMDQ_ENABLED)) {
682 tc = reg_idx & (dcb_i - 1);
Alexander Duyckbd508172010-11-16 19:27:03 -0800683 break;
Yi Zou26f23d82009-11-06 12:56:00 +0000684 }
John Fastabendc84d3242010-11-16 19:27:12 -0800685
686 /*
687 * Convert the reg_idx into the correct TC. This bitmask
688 * targets the last full 32 ring traffic class and assigns
689 * it a value of 1. From there the rest of the rings are
690 * based on shifting the mask further up to include the
691 * reg_idx / 16 and then reg_idx / 8. It assumes dcB_i
692 * will only ever be 8 or 4 and that reg_idx will never
693 * be greater then 128. The code without the power of 2
694 * optimizations would be:
695 * (((reg_idx % 32) + 32) * dcb_i) >> (9 - reg_idx / 32)
696 */
697 tc = ((reg_idx & 0X1F) + 0x20) * dcb_i;
698 tc >>= 9 - (reg_idx >> 5);
Yi Zou26f23d82009-11-06 12:56:00 +0000699 }
John Fastabendc84d3242010-11-16 19:27:12 -0800700
701 return tc;
Yi Zou26f23d82009-11-06 12:56:00 +0000702}
703
John Fastabendc84d3242010-11-16 19:27:12 -0800704static void ixgbe_update_xoff_received(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -0700705{
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700706 struct ixgbe_hw *hw = &adapter->hw;
John Fastabendc84d3242010-11-16 19:27:12 -0800707 struct ixgbe_hw_stats *hwstats = &adapter->stats;
708 u32 data = 0;
709 u32 xoff[8] = {0};
710 int i;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700711
John Fastabendc84d3242010-11-16 19:27:12 -0800712 if ((hw->fc.current_mode == ixgbe_fc_full) ||
713 (hw->fc.current_mode == ixgbe_fc_rx_pause)) {
714 switch (hw->mac.type) {
715 case ixgbe_mac_82598EB:
716 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXC);
717 break;
718 default:
719 data = IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT);
720 }
721 hwstats->lxoffrxc += data;
722
723 /* refill credits (no tx hang) if we received xoff */
724 if (!data)
725 return;
726
727 for (i = 0; i < adapter->num_tx_queues; i++)
728 clear_bit(__IXGBE_HANG_CHECK_ARMED,
729 &adapter->tx_ring[i]->state);
730 return;
731 } else if (!(adapter->dcb_cfg.pfc_mode_enable))
732 return;
733
734 /* update stats for each tc, only valid with PFC enabled */
735 for (i = 0; i < MAX_TX_PACKET_BUFFERS; i++) {
736 switch (hw->mac.type) {
737 case ixgbe_mac_82598EB:
738 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXC(i));
739 break;
740 default:
741 xoff[i] = IXGBE_READ_REG(hw, IXGBE_PXOFFRXCNT(i));
742 }
743 hwstats->pxoffrxc[i] += xoff[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700744 }
745
John Fastabendc84d3242010-11-16 19:27:12 -0800746 /* disarm tx queues that have received xoff frames */
747 for (i = 0; i < adapter->num_tx_queues; i++) {
748 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
749 u32 tc = ixgbe_dcb_txq_to_tc(adapter, tx_ring->reg_idx);
750
751 if (xoff[tc])
752 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
753 }
754}
755
756static u64 ixgbe_get_tx_completed(struct ixgbe_ring *ring)
757{
758 return ring->tx_stats.completed;
759}
760
761static u64 ixgbe_get_tx_pending(struct ixgbe_ring *ring)
762{
763 struct ixgbe_adapter *adapter = netdev_priv(ring->netdev);
764 struct ixgbe_hw *hw = &adapter->hw;
765
766 u32 head = IXGBE_READ_REG(hw, IXGBE_TDH(ring->reg_idx));
767 u32 tail = IXGBE_READ_REG(hw, IXGBE_TDT(ring->reg_idx));
768
769 if (head != tail)
770 return (head < tail) ?
771 tail - head : (tail + ring->count - head);
772
773 return 0;
774}
775
776static inline bool ixgbe_check_tx_hang(struct ixgbe_ring *tx_ring)
777{
778 u32 tx_done = ixgbe_get_tx_completed(tx_ring);
779 u32 tx_done_old = tx_ring->tx_stats.tx_done_old;
780 u32 tx_pending = ixgbe_get_tx_pending(tx_ring);
781 bool ret = false;
782
783 clear_check_for_tx_hang(tx_ring);
784
785 /*
786 * Check for a hung queue, but be thorough. This verifies
787 * that a transmit has been completed since the previous
788 * check AND there is at least one packet pending. The
789 * ARMED bit is set to indicate a potential hang. The
790 * bit is cleared if a pause frame is received to remove
791 * false hang detection due to PFC or 802.3x frames. By
792 * requiring this to fail twice we avoid races with
793 * pfc clearing the ARMED bit and conditions where we
794 * run the check_tx_hang logic with a transmit completion
795 * pending but without time to complete it yet.
796 */
797 if ((tx_done_old == tx_done) && tx_pending) {
798 /* make sure it is true for two checks in a row */
799 ret = test_and_set_bit(__IXGBE_HANG_CHECK_ARMED,
800 &tx_ring->state);
801 } else {
802 /* update completed stats and continue */
803 tx_ring->tx_stats.tx_done_old = tx_done;
804 /* reset the countdown */
805 clear_bit(__IXGBE_HANG_CHECK_ARMED, &tx_ring->state);
806 }
807
808 return ret;
Auke Kok9a799d72007-09-15 14:07:45 -0700809}
810
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700811#define IXGBE_MAX_TXD_PWR 14
812#define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800813
814/* Tx Descriptors needed, worst case */
815#define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \
816 (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0))
817#define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \
Peter P Waskiewiczb4617242008-09-11 20:04:46 -0700818 MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800819
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700820static void ixgbe_tx_timeout(struct net_device *netdev);
821
Auke Kok9a799d72007-09-15 14:07:45 -0700822/**
823 * ixgbe_clean_tx_irq - Reclaim resources after transmit completes
Alexander Duyckfe49f042009-06-04 16:00:09 +0000824 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700825 * @tx_ring: tx ring to clean
Auke Kok9a799d72007-09-15 14:07:45 -0700826 **/
Alexander Duyckfe49f042009-06-04 16:00:09 +0000827static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +0000828 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -0700829{
Alexander Duyckfe49f042009-06-04 16:00:09 +0000830 struct ixgbe_adapter *adapter = q_vector->adapter;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800831 union ixgbe_adv_tx_desc *tx_desc, *eop_desc;
832 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -0700833 unsigned int total_bytes = 0, total_packets = 0;
Alexander Duyckb9537992010-11-16 19:26:58 -0800834 u16 i, eop, count = 0;
Auke Kok9a799d72007-09-15 14:07:45 -0700835
836 i = tx_ring->next_to_clean;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800837 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000838 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800839
840 while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) &&
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +0000841 (count < tx_ring->work_limit)) {
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800842 bool cleaned = false;
Jeff Kirsher2d0bb1c2010-08-08 16:02:31 +0000843 rmb(); /* read buffer_info after eop_desc */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800844 for ( ; !cleaned; count++) {
Alexander Duyck31f05a22010-08-19 13:40:31 +0000845 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -0700846 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Auke Kok9a799d72007-09-15 14:07:45 -0700847
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800848 tx_desc->wb.status = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800849 cleaned = (i == eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800850
Auke Kok9a799d72007-09-15 14:07:45 -0700851 i++;
852 if (i == tx_ring->count)
853 i = 0;
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800854
855 if (cleaned && tx_buffer_info->skb) {
856 total_bytes += tx_buffer_info->bytecount;
857 total_packets += tx_buffer_info->gso_segs;
858 }
859
Alexander Duyckb6ec8952010-11-16 19:26:49 -0800860 ixgbe_unmap_and_free_tx_resource(tx_ring,
Alexander Duyck8ad494b2010-11-16 19:26:47 -0800861 tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -0700862 }
863
John Fastabendc84d3242010-11-16 19:27:12 -0800864 tx_ring->tx_stats.completed++;
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800865 eop = tx_ring->tx_buffer_info[i].next_to_watch;
Alexander Duyck31f05a22010-08-19 13:40:31 +0000866 eop_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -0800867 }
868
Auke Kok9a799d72007-09-15 14:07:45 -0700869 tx_ring->next_to_clean = i;
Alexander Duyckb9537992010-11-16 19:26:58 -0800870 tx_ring->total_bytes += total_bytes;
871 tx_ring->total_packets += total_packets;
872 u64_stats_update_begin(&tx_ring->syncp);
873 tx_ring->stats.packets += total_packets;
874 tx_ring->stats.bytes += total_bytes;
875 u64_stats_update_end(&tx_ring->syncp);
876
John Fastabendc84d3242010-11-16 19:27:12 -0800877 if (check_for_tx_hang(tx_ring) && ixgbe_check_tx_hang(tx_ring)) {
Alexander Duyckb9537992010-11-16 19:26:58 -0800878 /* schedule immediate reset if we believe we hung */
John Fastabendc84d3242010-11-16 19:27:12 -0800879 struct ixgbe_hw *hw = &adapter->hw;
880 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, eop);
881 e_err(drv, "Detected Tx Unit Hang\n"
882 " Tx Queue <%d>\n"
883 " TDH, TDT <%x>, <%x>\n"
884 " next_to_use <%x>\n"
885 " next_to_clean <%x>\n"
886 "tx_buffer_info[next_to_clean]\n"
887 " time_stamp <%lx>\n"
888 " jiffies <%lx>\n",
889 tx_ring->queue_index,
890 IXGBE_READ_REG(hw, IXGBE_TDH(tx_ring->reg_idx)),
891 IXGBE_READ_REG(hw, IXGBE_TDT(tx_ring->reg_idx)),
892 tx_ring->next_to_use, eop,
893 tx_ring->tx_buffer_info[eop].time_stamp, jiffies);
894
895 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
896
897 e_info(probe,
898 "tx hang %d detected on queue %d, resetting adapter\n",
899 adapter->tx_timeout_count + 1, tx_ring->queue_index);
900
901 /* schedule immediate reset if we believe we hung */
Alexander Duyckb9537992010-11-16 19:26:58 -0800902 ixgbe_tx_timeout(adapter->netdev);
903
904 /* the adapter is about to reset, no point in enabling stuff */
905 return true;
906 }
Auke Kok9a799d72007-09-15 14:07:45 -0700907
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800908#define TX_WAKE_THRESHOLD (DESC_NEEDED * 2)
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800909 if (unlikely(count && netif_carrier_ok(tx_ring->netdev) &&
Joe Perchese8e9f692010-09-07 21:34:53 +0000910 (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) {
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800911 /* Make sure that anybody stopping the queue after this
912 * sees the new next_to_clean.
913 */
914 smp_mb();
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800915 if (__netif_subqueue_stopped(tx_ring->netdev, tx_ring->queue_index) &&
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800916 !test_bit(__IXGBE_DOWN, &adapter->state)) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -0800917 netif_wake_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -0800918 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -0800919 }
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -0800920 }
Auke Kok9a799d72007-09-15 14:07:45 -0700921
Eric Dumazet807540b2010-09-23 05:40:09 +0000922 return count < tx_ring->work_limit;
Auke Kok9a799d72007-09-15 14:07:45 -0700923}
924
Jeff Garzik5dd2d332008-10-16 05:09:31 -0400925#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800926static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800927 struct ixgbe_ring *rx_ring,
928 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800929{
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800930 struct ixgbe_hw *hw = &adapter->hw;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800931 u32 rxctrl;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800932 u8 reg_idx = rx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800933
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800934 rxctrl = IXGBE_READ_REG(hw, IXGBE_DCA_RXCTRL(reg_idx));
935 switch (hw->mac.type) {
936 case ixgbe_mac_82598EB:
937 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK;
938 rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
939 break;
940 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800941 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800942 rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599;
943 rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
944 IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599);
945 break;
946 default:
947 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800948 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800949 rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN;
950 rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN;
951 rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN);
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800952 IXGBE_WRITE_REG(hw, IXGBE_DCA_RXCTRL(reg_idx), rxctrl);
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800953}
954
955static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter,
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800956 struct ixgbe_ring *tx_ring,
957 int cpu)
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800958{
Don Skidmoreee5f7842009-11-06 12:56:20 +0000959 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800960 u32 txctrl;
961 u8 reg_idx = tx_ring->reg_idx;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800962
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800963 switch (hw->mac.type) {
964 case ixgbe_mac_82598EB:
965 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(reg_idx));
966 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK;
967 txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu);
968 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800969 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(reg_idx), txctrl);
970 break;
971 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -0800972 case ixgbe_mac_X540:
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800973 txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx));
974 txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599;
975 txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) <<
976 IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599);
977 txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN;
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800978 IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(reg_idx), txctrl);
979 break;
980 default:
981 break;
Jeb Cramerbd0362d2008-03-03 15:04:02 -0800982 }
Alexander Duyck33cf09c2010-11-16 19:26:55 -0800983}
984
985static void ixgbe_update_dca(struct ixgbe_q_vector *q_vector)
986{
987 struct ixgbe_adapter *adapter = q_vector->adapter;
988 int cpu = get_cpu();
989 long r_idx;
990 int i;
991
992 if (q_vector->cpu == cpu)
993 goto out_no_update;
994
995 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
996 for (i = 0; i < q_vector->txr_count; i++) {
997 ixgbe_update_tx_dca(adapter, adapter->tx_ring[r_idx], cpu);
998 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
999 r_idx + 1);
1000 }
1001
1002 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1003 for (i = 0; i < q_vector->rxr_count; i++) {
1004 ixgbe_update_rx_dca(adapter, adapter->rx_ring[r_idx], cpu);
1005 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
1006 r_idx + 1);
1007 }
1008
1009 q_vector->cpu = cpu;
1010out_no_update:
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001011 put_cpu();
1012}
1013
1014static void ixgbe_setup_dca(struct ixgbe_adapter *adapter)
1015{
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001016 int num_q_vectors;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001017 int i;
1018
1019 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1020 return;
1021
Alexander Duycke35ec122009-05-21 13:07:12 +00001022 /* always use CB2 mode, difference is masked in the CB driver */
1023 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2);
1024
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001025 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
1026 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1027 else
1028 num_q_vectors = 1;
1029
1030 for (i = 0; i < num_q_vectors; i++) {
1031 adapter->q_vector[i]->cpu = -1;
1032 ixgbe_update_dca(adapter->q_vector[i]);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001033 }
1034}
1035
1036static int __ixgbe_notify_dca(struct device *dev, void *data)
1037{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08001038 struct ixgbe_adapter *adapter = dev_get_drvdata(dev);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001039 unsigned long event = *(unsigned long *)data;
1040
Alexander Duyck33cf09c2010-11-16 19:26:55 -08001041 if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED))
1042 return 0;
1043
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001044 switch (event) {
1045 case DCA_PROVIDER_ADD:
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001046 /* if we're already enabled, don't do it again */
1047 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
1048 break;
Denis V. Lunev652f0932008-03-27 14:39:17 +03001049 if (dca_add_requester(dev) == 0) {
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07001050 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001051 ixgbe_setup_dca(adapter);
1052 break;
1053 }
1054 /* Fall Through since DCA is disabled. */
1055 case DCA_PROVIDER_REMOVE:
1056 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
1057 dca_remove_requester(dev);
1058 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
1059 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
1060 }
1061 break;
1062 }
1063
Denis V. Lunev652f0932008-03-27 14:39:17 +03001064 return 0;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08001065}
Jeff Garzik5dd2d332008-10-16 05:09:31 -04001066#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001067
1068static inline void ixgbe_rx_hash(union ixgbe_adv_rx_desc *rx_desc,
1069 struct sk_buff *skb)
1070{
1071 skb->rxhash = le32_to_cpu(rx_desc->wb.lower.hi_dword.rss);
1072}
1073
Auke Kok9a799d72007-09-15 14:07:45 -07001074/**
1075 * ixgbe_receive_skb - Send a completed packet up the stack
1076 * @adapter: board private structure
1077 * @skb: packet to send up
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001078 * @status: hardware indication of status of receive
1079 * @rx_ring: rx descriptor ring (for a specific queue) to setup
1080 * @rx_desc: rx descriptor
Auke Kok9a799d72007-09-15 14:07:45 -07001081 **/
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001082static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001083 struct sk_buff *skb, u8 status,
1084 struct ixgbe_ring *ring,
1085 union ixgbe_adv_rx_desc *rx_desc)
Auke Kok9a799d72007-09-15 14:07:45 -07001086{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001087 struct ixgbe_adapter *adapter = q_vector->adapter;
1088 struct napi_struct *napi = &q_vector->napi;
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001089 bool is_vlan = (status & IXGBE_RXD_STAT_VP);
1090 u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan);
Auke Kok9a799d72007-09-15 14:07:45 -07001091
Jesse Grossf62bbb52010-10-20 13:56:10 +00001092 if (is_vlan && (tag & VLAN_VID_MASK))
1093 __vlan_hwaccel_put_tag(skb, tag);
1094
1095 if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL))
1096 napi_gro_receive(napi, skb);
1097 else
1098 netif_rx(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001099}
1100
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001101/**
1102 * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum
1103 * @adapter: address of board private structure
1104 * @status_err: hardware indication of status of receive
1105 * @skb: skb currently being received and modified
1106 **/
Auke Kok9a799d72007-09-15 14:07:45 -07001107static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter,
Don Skidmore8bae1b22009-07-23 18:00:39 +00001108 union ixgbe_adv_rx_desc *rx_desc,
1109 struct sk_buff *skb)
Auke Kok9a799d72007-09-15 14:07:45 -07001110{
Don Skidmore8bae1b22009-07-23 18:00:39 +00001111 u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error);
1112
Eric Dumazetbc8acf22010-09-02 13:07:41 -07001113 skb_checksum_none_assert(skb);
Auke Kok9a799d72007-09-15 14:07:45 -07001114
Jesse Brandeburg712744b2008-08-26 04:26:56 -07001115 /* Rx csum disabled */
1116 if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07001117 return;
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001118
1119 /* if IP and error */
1120 if ((status_err & IXGBE_RXD_STAT_IPCS) &&
1121 (status_err & IXGBE_RXDADV_ERR_IPE)) {
Auke Kok9a799d72007-09-15 14:07:45 -07001122 adapter->hw_csum_rx_error++;
1123 return;
1124 }
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001125
1126 if (!(status_err & IXGBE_RXD_STAT_L4CS))
1127 return;
1128
1129 if (status_err & IXGBE_RXDADV_ERR_TCPE) {
Don Skidmore8bae1b22009-07-23 18:00:39 +00001130 u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info;
1131
1132 /*
1133 * 82599 errata, UDP frames with a 0 checksum can be marked as
1134 * checksum errors.
1135 */
1136 if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) &&
1137 (adapter->hw.mac.type == ixgbe_mac_82599EB))
1138 return;
1139
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001140 adapter->hw_csum_rx_error++;
1141 return;
1142 }
1143
Auke Kok9a799d72007-09-15 14:07:45 -07001144 /* It must be a TCP or UDP packet with a valid checksum */
Ayyappan Veeraiyane59bd252008-02-01 15:59:09 -08001145 skb->ip_summed = CHECKSUM_UNNECESSARY;
Auke Kok9a799d72007-09-15 14:07:45 -07001146}
1147
Alexander Duyck84ea2592010-11-16 19:26:49 -08001148static inline void ixgbe_release_rx_desc(struct ixgbe_ring *rx_ring, u32 val)
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001149{
1150 /*
1151 * Force memory writes to complete before letting h/w
1152 * know there are new descriptors to fetch. (Only
1153 * applicable for weak-ordered memory model archs,
1154 * such as IA-64).
1155 */
1156 wmb();
Alexander Duyck84ea2592010-11-16 19:26:49 -08001157 writel(val, rx_ring->tail);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001158}
1159
Auke Kok9a799d72007-09-15 14:07:45 -07001160/**
1161 * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001162 * @rx_ring: ring to place buffers on
1163 * @cleaned_count: number of buffers to replace
Auke Kok9a799d72007-09-15 14:07:45 -07001164 **/
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001165void ixgbe_alloc_rx_buffers(struct ixgbe_ring *rx_ring, u16 cleaned_count)
Auke Kok9a799d72007-09-15 14:07:45 -07001166{
Auke Kok9a799d72007-09-15 14:07:45 -07001167 union ixgbe_adv_rx_desc *rx_desc;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001168 struct ixgbe_rx_buffer *bi;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001169 struct sk_buff *skb;
1170 u16 i = rx_ring->next_to_use;
Auke Kok9a799d72007-09-15 14:07:45 -07001171
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001172 /* do nothing if no valid netdev defined */
1173 if (!rx_ring->netdev)
1174 return;
1175
Auke Kok9a799d72007-09-15 14:07:45 -07001176 while (cleaned_count--) {
Alexander Duyck31f05a22010-08-19 13:40:31 +00001177 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001178 bi = &rx_ring->rx_buffer_info[i];
1179 skb = bi->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001180
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001181 if (!skb) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001182 skb = netdev_alloc_skb_ip_align(rx_ring->netdev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001183 rx_ring->rx_buf_len);
Auke Kok9a799d72007-09-15 14:07:45 -07001184 if (!skb) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001185 rx_ring->rx_stats.alloc_rx_buff_failed++;
Auke Kok9a799d72007-09-15 14:07:45 -07001186 goto no_buffers;
1187 }
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001188 /* initialize queue mapping */
1189 skb_record_rx_queue(skb, rx_ring->queue_index);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001190 bi->skb = skb;
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001191 }
Auke Kok9a799d72007-09-15 14:07:45 -07001192
Alexander Duyckd716a7d2010-08-19 13:33:41 +00001193 if (!bi->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001194 bi->dma = dma_map_single(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001195 skb->data,
Joe Perchese8e9f692010-09-07 21:34:53 +00001196 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00001197 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001198 if (dma_mapping_error(rx_ring->dev, bi->dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001199 rx_ring->rx_stats.alloc_rx_buff_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001200 bi->dma = 0;
1201 goto no_buffers;
1202 }
Auke Kok9a799d72007-09-15 14:07:45 -07001203 }
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001204
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001205 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001206 if (!bi->page) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001207 bi->page = netdev_alloc_page(rx_ring->netdev);
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001208 if (!bi->page) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001209 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001210 goto no_buffers;
1211 }
1212 }
1213
1214 if (!bi->page_dma) {
1215 /* use a half page if we're re-using */
1216 bi->page_offset ^= PAGE_SIZE / 2;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001217 bi->page_dma = dma_map_page(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001218 bi->page,
1219 bi->page_offset,
1220 PAGE_SIZE / 2,
1221 DMA_FROM_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001222 if (dma_mapping_error(rx_ring->dev,
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001223 bi->page_dma)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08001224 rx_ring->rx_stats.alloc_rx_page_failed++;
Alexander Duyckd5f398e2010-11-16 19:26:48 -08001225 bi->page_dma = 0;
1226 goto no_buffers;
1227 }
1228 }
1229
1230 /* Refresh the desc even if buffer_addrs didn't change
1231 * because each write-back erases this info. */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001232 rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma);
1233 rx_desc->read.hdr_addr = cpu_to_le64(bi->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07001234 } else {
Jesse Brandeburg3a581072008-08-26 04:27:08 -07001235 rx_desc->read.pkt_addr = cpu_to_le64(bi->dma);
Alexander Duyck84418e32010-08-19 13:40:54 +00001236 rx_desc->read.hdr_addr = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001237 }
1238
1239 i++;
1240 if (i == rx_ring->count)
1241 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001242 }
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001243
Auke Kok9a799d72007-09-15 14:07:45 -07001244no_buffers:
1245 if (rx_ring->next_to_use != i) {
1246 rx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08001247 ixgbe_release_rx_desc(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001248 }
1249}
1250
Alexander Duyckc267fc12010-11-16 19:27:00 -08001251static inline u16 ixgbe_get_hlen(union ixgbe_adv_rx_desc *rx_desc)
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001252{
Alexander Duyckc267fc12010-11-16 19:27:00 -08001253 /* HW will not DMA in data larger than the given buffer, even if it
1254 * parses the (NFS, of course) header to be larger. In that case, it
1255 * fills the header buffer and spills the rest into the page.
1256 */
1257 u16 hdr_info = le16_to_cpu(rx_desc->wb.lower.lo_dword.hs_rss.hdr_info);
1258 u16 hlen = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >>
1259 IXGBE_RXDADV_HDRBUFLEN_SHIFT;
1260 if (hlen > IXGBE_RX_HDR_SIZE)
1261 hlen = IXGBE_RX_HDR_SIZE;
1262 return hlen;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001263}
1264
Alexander Duyckf8212f92009-04-27 22:42:37 +00001265/**
1266 * ixgbe_transform_rsc_queue - change rsc queue into a full packet
1267 * @skb: pointer to the last skb in the rsc queue
1268 *
1269 * This function changes a queue full of hw rsc buffers into a completed
1270 * packet. It uses the ->prev pointers to find the first packet and then
1271 * turns it into the frag list owner.
1272 **/
Alexander Duyckaa801752010-11-16 19:27:02 -08001273static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb)
Alexander Duyckf8212f92009-04-27 22:42:37 +00001274{
1275 unsigned int frag_list_size = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001276 unsigned int skb_cnt = 1;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001277
1278 while (skb->prev) {
1279 struct sk_buff *prev = skb->prev;
1280 frag_list_size += skb->len;
1281 skb->prev = NULL;
1282 skb = prev;
Alexander Duyckaa801752010-11-16 19:27:02 -08001283 skb_cnt++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001284 }
1285
1286 skb_shinfo(skb)->frag_list = skb->next;
1287 skb->next = NULL;
1288 skb->len += frag_list_size;
1289 skb->data_len += frag_list_size;
1290 skb->truesize += frag_list_size;
Alexander Duyckaa801752010-11-16 19:27:02 -08001291 IXGBE_RSC_CB(skb)->skb_cnt = skb_cnt;
1292
Alexander Duyckf8212f92009-04-27 22:42:37 +00001293 return skb;
1294}
1295
Alexander Duyckaa801752010-11-16 19:27:02 -08001296static inline bool ixgbe_get_rsc_state(union ixgbe_adv_rx_desc *rx_desc)
1297{
1298 return !!(le32_to_cpu(rx_desc->wb.lower.lo_dword.data) &
1299 IXGBE_RXDADV_RSCCNT_MASK);
1300}
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001301
Alexander Duyckc267fc12010-11-16 19:27:00 -08001302static void ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00001303 struct ixgbe_ring *rx_ring,
1304 int *work_done, int work_to_do)
Auke Kok9a799d72007-09-15 14:07:45 -07001305{
Herbert Xu78b6f4c2009-01-18 21:49:45 -08001306 struct ixgbe_adapter *adapter = q_vector->adapter;
Auke Kok9a799d72007-09-15 14:07:45 -07001307 union ixgbe_adv_rx_desc *rx_desc, *next_rxd;
1308 struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer;
1309 struct sk_buff *skb;
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001310 unsigned int total_rx_bytes = 0, total_rx_packets = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001311 const int current_node = numa_node_id();
Yi Zou3d8fd382009-06-08 14:38:44 +00001312#ifdef IXGBE_FCOE
1313 int ddp_bytes = 0;
1314#endif /* IXGBE_FCOE */
Alexander Duyckc267fc12010-11-16 19:27:00 -08001315 u32 staterr;
1316 u16 i;
1317 u16 cleaned_count = 0;
Alexander Duyckaa801752010-11-16 19:27:02 -08001318 bool pkt_is_rsc = false;
Auke Kok9a799d72007-09-15 14:07:45 -07001319
1320 i = rx_ring->next_to_clean;
Alexander Duyck31f05a22010-08-19 13:40:31 +00001321 rx_desc = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001322 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Auke Kok9a799d72007-09-15 14:07:45 -07001323
1324 while (staterr & IXGBE_RXD_STAT_DD) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07001325 u32 upper_len = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001326
Milton Miller3c945e52010-02-19 17:44:42 +00001327 rmb(); /* read descriptor and rx_buffer_info after status DD */
Auke Kok9a799d72007-09-15 14:07:45 -07001328
Alexander Duyckc267fc12010-11-16 19:27:00 -08001329 rx_buffer_info = &rx_ring->rx_buffer_info[i];
1330
Auke Kok9a799d72007-09-15 14:07:45 -07001331 skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001332 rx_buffer_info->skb = NULL;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001333 prefetch(skb->data);
Auke Kok9a799d72007-09-15 14:07:45 -07001334
Alexander Duyckc267fc12010-11-16 19:27:00 -08001335 if (ring_is_rsc_enabled(rx_ring))
Alexander Duyckaa801752010-11-16 19:27:02 -08001336 pkt_is_rsc = ixgbe_get_rsc_state(rx_desc);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001337
1338 /* if this is a skb from previous receive DMA will be 0 */
Alexander Duyck21fa4e62009-06-04 15:59:49 +00001339 if (rx_buffer_info->dma) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001340 u16 hlen;
Alexander Duyckaa801752010-11-16 19:27:02 -08001341 if (pkt_is_rsc &&
Alexander Duyckc267fc12010-11-16 19:27:00 -08001342 !(staterr & IXGBE_RXD_STAT_EOP) &&
1343 !skb->prev) {
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001344 /*
1345 * When HWRSC is enabled, delay unmapping
1346 * of the first packet. It carries the
1347 * header information, HW may still
1348 * access the header after the writeback.
1349 * Only unmap it when EOP is reached
1350 */
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001351 IXGBE_RSC_CB(skb)->delay_unmap = true;
Mallikarjuna R Chilakala43634e82010-02-25 23:14:37 +00001352 IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001353 } else {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001354 dma_unmap_single(rx_ring->dev,
Joe Perchese8e9f692010-09-07 21:34:53 +00001355 rx_buffer_info->dma,
1356 rx_ring->rx_buf_len,
1357 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00001358 }
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00001359 rx_buffer_info->dma = 0;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001360
1361 if (ring_is_ps_enabled(rx_ring)) {
1362 hlen = ixgbe_get_hlen(rx_desc);
1363 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
1364 } else {
1365 hlen = le16_to_cpu(rx_desc->wb.upper.length);
1366 }
1367
1368 skb_put(skb, hlen);
1369 } else {
1370 /* assume packet split since header is unmapped */
1371 upper_len = le16_to_cpu(rx_desc->wb.upper.length);
Auke Kok9a799d72007-09-15 14:07:45 -07001372 }
1373
1374 if (upper_len) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08001375 dma_unmap_page(rx_ring->dev,
1376 rx_buffer_info->page_dma,
1377 PAGE_SIZE / 2,
1378 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07001379 rx_buffer_info->page_dma = 0;
1380 skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags,
Joe Perchese8e9f692010-09-07 21:34:53 +00001381 rx_buffer_info->page,
1382 rx_buffer_info->page_offset,
1383 upper_len);
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001384
Alexander Duyckc267fc12010-11-16 19:27:00 -08001385 if ((page_count(rx_buffer_info->page) == 1) &&
1386 (page_to_nid(rx_buffer_info->page) == current_node))
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07001387 get_page(rx_buffer_info->page);
Alexander Duyckc267fc12010-11-16 19:27:00 -08001388 else
1389 rx_buffer_info->page = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07001390
1391 skb->len += upper_len;
1392 skb->data_len += upper_len;
1393 skb->truesize += upper_len;
1394 }
1395
1396 i++;
1397 if (i == rx_ring->count)
1398 i = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07001399
Alexander Duyck31f05a22010-08-19 13:40:31 +00001400 next_rxd = IXGBE_RX_DESC_ADV(rx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07001401 prefetch(next_rxd);
Auke Kok9a799d72007-09-15 14:07:45 -07001402 cleaned_count++;
Alexander Duyckf8212f92009-04-27 22:42:37 +00001403
Alexander Duyckaa801752010-11-16 19:27:02 -08001404 if (pkt_is_rsc) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001405 u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >>
1406 IXGBE_RXDADV_NEXTP_SHIFT;
1407 next_buffer = &rx_ring->rx_buffer_info[nextp];
Alexander Duyckf8212f92009-04-27 22:42:37 +00001408 } else {
1409 next_buffer = &rx_ring->rx_buffer_info[i];
1410 }
1411
Alexander Duyckc267fc12010-11-16 19:27:00 -08001412 if (!(staterr & IXGBE_RXD_STAT_EOP)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001413 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00001414 rx_buffer_info->skb = next_buffer->skb;
1415 rx_buffer_info->dma = next_buffer->dma;
1416 next_buffer->skb = skb;
1417 next_buffer->dma = 0;
1418 } else {
1419 skb->next = next_buffer->skb;
1420 skb->next->prev = skb;
1421 }
Alexander Duyck5b7da512010-11-16 19:26:50 -08001422 rx_ring->rx_stats.non_eop_descs++;
Auke Kok9a799d72007-09-15 14:07:45 -07001423 goto next_desc;
1424 }
1425
Alexander Duyckaa801752010-11-16 19:27:02 -08001426 if (skb->prev) {
1427 skb = ixgbe_transform_rsc_queue(skb);
1428 /* if we got here without RSC the packet is invalid */
1429 if (!pkt_is_rsc) {
1430 __pskb_trim(skb, 0);
1431 rx_buffer_info->skb = skb;
1432 goto next_desc;
1433 }
1434 }
Alexander Duyckc267fc12010-11-16 19:27:00 -08001435
1436 if (ring_is_rsc_enabled(rx_ring)) {
1437 if (IXGBE_RSC_CB(skb)->delay_unmap) {
1438 dma_unmap_single(rx_ring->dev,
1439 IXGBE_RSC_CB(skb)->dma,
1440 rx_ring->rx_buf_len,
1441 DMA_FROM_DEVICE);
1442 IXGBE_RSC_CB(skb)->dma = 0;
1443 IXGBE_RSC_CB(skb)->delay_unmap = false;
1444 }
Alexander Duyckaa801752010-11-16 19:27:02 -08001445 }
1446 if (pkt_is_rsc) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001447 if (ring_is_ps_enabled(rx_ring))
1448 rx_ring->rx_stats.rsc_count +=
Alexander Duyckaa801752010-11-16 19:27:02 -08001449 skb_shinfo(skb)->nr_frags;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001450 else
Alexander Duyckaa801752010-11-16 19:27:02 -08001451 rx_ring->rx_stats.rsc_count +=
1452 IXGBE_RSC_CB(skb)->skb_cnt;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001453 rx_ring->rx_stats.rsc_flush++;
1454 }
1455
1456 /* ERR_MASK will only have valid bits if EOP set */
Auke Kok9a799d72007-09-15 14:07:45 -07001457 if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) {
Alexander Duyckc267fc12010-11-16 19:27:00 -08001458 /* trim packet back to size 0 and recycle it */
1459 __pskb_trim(skb, 0);
1460 rx_buffer_info->skb = skb;
Auke Kok9a799d72007-09-15 14:07:45 -07001461 goto next_desc;
1462 }
1463
Don Skidmore8bae1b22009-07-23 18:00:39 +00001464 ixgbe_rx_checksum(adapter, rx_desc, skb);
Emil Tantilov67a74ee2011-04-23 04:50:40 +00001465 if (adapter->netdev->features & NETIF_F_RXHASH)
1466 ixgbe_rx_hash(rx_desc, skb);
Ayyappan Veeraiyand2f4fbe2008-02-01 15:59:19 -08001467
1468 /* probably a little skewed due to removing CRC */
1469 total_rx_bytes += skb->len;
1470 total_rx_packets++;
1471
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001472 skb->protocol = eth_type_trans(skb, rx_ring->netdev);
Yi Zou332d4a72009-05-13 13:11:53 +00001473#ifdef IXGBE_FCOE
1474 /* if ddp, not passing to ULD unless for FCP_RSP or error */
Yi Zou3d8fd382009-06-08 14:38:44 +00001475 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) {
1476 ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb);
1477 if (!ddp_bytes)
Yi Zou332d4a72009-05-13 13:11:53 +00001478 goto next_desc;
Yi Zou3d8fd382009-06-08 14:38:44 +00001479 }
Yi Zou332d4a72009-05-13 13:11:53 +00001480#endif /* IXGBE_FCOE */
Alexander Duyckfdaff1c2009-05-06 10:43:47 +00001481 ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc);
Auke Kok9a799d72007-09-15 14:07:45 -07001482
1483next_desc:
1484 rx_desc->wb.upper.status_error = 0;
1485
Alexander Duyckc267fc12010-11-16 19:27:00 -08001486 (*work_done)++;
1487 if (*work_done >= work_to_do)
1488 break;
1489
Auke Kok9a799d72007-09-15 14:07:45 -07001490 /* return some buffers to hardware, one at a time is too slow */
1491 if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) {
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001492 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001493 cleaned_count = 0;
1494 }
1495
1496 /* use prefetched values */
1497 rx_desc = next_rxd;
Auke Kok9a799d72007-09-15 14:07:45 -07001498 staterr = le32_to_cpu(rx_desc->wb.upper.status_error);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07001499 }
1500
Auke Kok9a799d72007-09-15 14:07:45 -07001501 rx_ring->next_to_clean = i;
1502 cleaned_count = IXGBE_DESC_UNUSED(rx_ring);
1503
1504 if (cleaned_count)
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001505 ixgbe_alloc_rx_buffers(rx_ring, cleaned_count);
Auke Kok9a799d72007-09-15 14:07:45 -07001506
Yi Zou3d8fd382009-06-08 14:38:44 +00001507#ifdef IXGBE_FCOE
1508 /* include DDPed FCoE data */
1509 if (ddp_bytes > 0) {
1510 unsigned int mss;
1511
Alexander Duyckfc77dc32010-11-16 19:26:51 -08001512 mss = rx_ring->netdev->mtu - sizeof(struct fcoe_hdr) -
Yi Zou3d8fd382009-06-08 14:38:44 +00001513 sizeof(struct fc_frame_header) -
1514 sizeof(struct fcoe_crc_eof);
1515 if (mss > 512)
1516 mss &= ~511;
1517 total_rx_bytes += ddp_bytes;
1518 total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss);
1519 }
1520#endif /* IXGBE_FCOE */
1521
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001522 rx_ring->total_packets += total_rx_packets;
1523 rx_ring->total_bytes += total_rx_bytes;
Alexander Duyckc267fc12010-11-16 19:27:00 -08001524 u64_stats_update_begin(&rx_ring->syncp);
1525 rx_ring->stats.packets += total_rx_packets;
1526 rx_ring->stats.bytes += total_rx_bytes;
1527 u64_stats_update_end(&rx_ring->syncp);
Auke Kok9a799d72007-09-15 14:07:45 -07001528}
1529
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001530static int ixgbe_clean_rxonly(struct napi_struct *, int);
Auke Kok9a799d72007-09-15 14:07:45 -07001531/**
1532 * ixgbe_configure_msix - Configure MSI-X hardware
1533 * @adapter: board private structure
1534 *
1535 * ixgbe_configure_msix sets up the hardware to properly generate MSI-X
1536 * interrupts.
1537 **/
1538static void ixgbe_configure_msix(struct ixgbe_adapter *adapter)
1539{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001540 struct ixgbe_q_vector *q_vector;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001541 int i, q_vectors, v_idx, r_idx;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001542 u32 mask;
Auke Kok9a799d72007-09-15 14:07:45 -07001543
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001544 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
1545
Jesse Brandeburg4df10462009-03-13 22:15:31 +00001546 /*
1547 * Populate the IVAR table and set the ITR values to the
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001548 * corresponding register.
1549 */
1550 for (v_idx = 0; v_idx < q_vectors; v_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00001551 q_vector = adapter->q_vector[v_idx];
Akinobu Mita984b3f52010-03-05 13:41:37 -08001552 /* XXX for_each_set_bit(...) */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001553 r_idx = find_first_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001554 adapter->num_rx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001555
1556 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001557 u8 reg_idx = adapter->rx_ring[r_idx]->reg_idx;
1558 ixgbe_set_ivar(adapter, 0, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001559 r_idx = find_next_bit(q_vector->rxr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001560 adapter->num_rx_queues,
1561 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001562 }
1563 r_idx = find_first_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001564 adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001565
1566 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08001567 u8 reg_idx = adapter->tx_ring[r_idx]->reg_idx;
1568 ixgbe_set_ivar(adapter, 1, reg_idx, v_idx);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001569 r_idx = find_next_bit(q_vector->txr_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00001570 adapter->num_tx_queues,
1571 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001572 }
1573
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001574 if (q_vector->txr_count && !q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001575 /* tx only */
1576 q_vector->eitr = adapter->tx_eitr_param;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001577 else if (q_vector->rxr_count)
Nelson, Shannonf7554a22009-09-18 09:46:06 +00001578 /* rx or mixed */
1579 q_vector->eitr = adapter->rx_eitr_param;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001580
Alexander Duyckfe49f042009-06-04 16:00:09 +00001581 ixgbe_write_eitr(q_vector);
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00001582 /* If Flow Director is enabled, set interrupt affinity */
1583 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
1584 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
1585 /*
1586 * Allocate the affinity_hint cpumask, assign the mask
1587 * for this vector, and set our affinity_hint for
1588 * this irq.
1589 */
1590 if (!alloc_cpumask_var(&q_vector->affinity_mask,
1591 GFP_KERNEL))
1592 return;
1593 cpumask_set_cpu(v_idx, q_vector->affinity_mask);
1594 irq_set_affinity_hint(adapter->msix_entries[v_idx].vector,
1595 q_vector->affinity_mask);
1596 }
Auke Kok9a799d72007-09-15 14:07:45 -07001597 }
1598
Alexander Duyckbd508172010-11-16 19:27:03 -08001599 switch (adapter->hw.mac.type) {
1600 case ixgbe_mac_82598EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001601 ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX,
Joe Perchese8e9f692010-09-07 21:34:53 +00001602 v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001603 break;
1604 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001605 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001606 ixgbe_set_ivar(adapter, -1, 1, v_idx);
Alexander Duyckbd508172010-11-16 19:27:03 -08001607 break;
1608
1609 default:
1610 break;
1611 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001612 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950);
Auke Kok9a799d72007-09-15 14:07:45 -07001613
Jesse Brandeburg41fb9242008-09-11 19:55:58 -07001614 /* set up to autoclear timer, and the vectors */
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001615 mask = IXGBE_EIMS_ENABLE_MASK;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001616 if (adapter->num_vfs)
1617 mask &= ~(IXGBE_EIMS_OTHER |
1618 IXGBE_EIMS_MAILBOX |
1619 IXGBE_EIMS_LSC);
1620 else
1621 mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08001622 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask);
Auke Kok9a799d72007-09-15 14:07:45 -07001623}
1624
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001625enum latency_range {
1626 lowest_latency = 0,
1627 low_latency = 1,
1628 bulk_latency = 2,
1629 latency_invalid = 255
1630};
1631
1632/**
1633 * ixgbe_update_itr - update the dynamic ITR value based on statistics
1634 * @adapter: pointer to adapter
1635 * @eitr: eitr setting (ints per sec) to give last timeslice
1636 * @itr_setting: current throttle rate in ints/second
1637 * @packets: the number of packets during this measurement interval
1638 * @bytes: the number of bytes during this measurement interval
1639 *
1640 * Stores a new ITR value based on packets and byte
1641 * counts during the last interrupt. The advantage of per interrupt
1642 * computation is faster updates and more accurate ITR for the current
1643 * traffic pattern. Constants in this function were computed
1644 * based on theoretical maximum wire speed and thresholds were set based
1645 * on testing data as well as attempting to minimize response time
1646 * while increasing bulk throughput.
1647 * this functionality is controlled by the InterruptThrottleRate module
1648 * parameter (see ixgbe_param.c)
1649 **/
1650static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001651 u32 eitr, u8 itr_setting,
1652 int packets, int bytes)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001653{
1654 unsigned int retval = itr_setting;
1655 u32 timepassed_us;
1656 u64 bytes_perint;
1657
1658 if (packets == 0)
1659 goto update_itr_done;
1660
1661
1662 /* simple throttlerate management
1663 * 0-20MB/s lowest (100000 ints/s)
1664 * 20-100MB/s low (20000 ints/s)
1665 * 100-1249MB/s bulk (8000 ints/s)
1666 */
1667 /* what was last interrupt timeslice? */
1668 timepassed_us = 1000000/eitr;
1669 bytes_perint = bytes / timepassed_us; /* bytes/usec */
1670
1671 switch (itr_setting) {
1672 case lowest_latency:
1673 if (bytes_perint > adapter->eitr_low)
1674 retval = low_latency;
1675 break;
1676 case low_latency:
1677 if (bytes_perint > adapter->eitr_high)
1678 retval = bulk_latency;
1679 else if (bytes_perint <= adapter->eitr_low)
1680 retval = lowest_latency;
1681 break;
1682 case bulk_latency:
1683 if (bytes_perint <= adapter->eitr_high)
1684 retval = low_latency;
1685 break;
1686 }
1687
1688update_itr_done:
1689 return retval;
1690}
1691
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001692/**
1693 * ixgbe_write_eitr - write EITR register in hardware specific way
Alexander Duyckfe49f042009-06-04 16:00:09 +00001694 * @q_vector: structure containing interrupt and ring information
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001695 *
1696 * This function is made to be called by ethtool and by the driver
1697 * when it needs to update EITR registers at runtime. Hardware
1698 * specific quirks/differences are taken care of here.
1699 */
Alexander Duyckfe49f042009-06-04 16:00:09 +00001700void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector)
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001701{
Alexander Duyckfe49f042009-06-04 16:00:09 +00001702 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001703 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001704 int v_idx = q_vector->v_idx;
1705 u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr);
1706
Alexander Duyckbd508172010-11-16 19:27:03 -08001707 switch (adapter->hw.mac.type) {
1708 case ixgbe_mac_82598EB:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001709 /* must write high and low 16 bits to reset counter */
1710 itr_reg |= (itr_reg << 16);
Alexander Duyckbd508172010-11-16 19:27:03 -08001711 break;
1712 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001713 case ixgbe_mac_X540:
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001714 /*
Don Skidmoreb93a2222010-11-16 19:27:17 -08001715 * 82599 and X540 can support a value of zero, so allow it for
Jesse Brandeburgf8d1dca2010-04-27 01:37:20 +00001716 * max interrupt rate, but there is an errata where it can
1717 * not be zero with RSC
1718 */
1719 if (itr_reg == 8 &&
1720 !(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED))
1721 itr_reg = 0;
1722
1723 /*
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001724 * set the WDIS bit to not clear the timer bits and cause an
1725 * immediate assertion of the interrupt
1726 */
1727 itr_reg |= IXGBE_EITR_CNT_WDIS;
Alexander Duyckbd508172010-11-16 19:27:03 -08001728 break;
1729 default:
1730 break;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001731 }
1732 IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg);
1733}
1734
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001735static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector)
1736{
1737 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck125601b2010-11-16 19:27:08 -08001738 int i, r_idx;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001739 u32 new_itr;
1740 u8 current_itr, ret_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001741
1742 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
1743 for (i = 0; i < q_vector->txr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001744 struct ixgbe_ring *tx_ring = adapter->tx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001745 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001746 q_vector->tx_itr,
1747 tx_ring->total_packets,
1748 tx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001749 /* if the result for this queue would decrease interrupt
1750 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001751 q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001752 q_vector->tx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001753 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001754 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001755 }
1756
1757 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
1758 for (i = 0; i < q_vector->rxr_count; i++) {
Alexander Duyck125601b2010-11-16 19:27:08 -08001759 struct ixgbe_ring *rx_ring = adapter->rx_ring[r_idx];
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001760 ret_itr = ixgbe_update_itr(adapter, q_vector->eitr,
Joe Perchese8e9f692010-09-07 21:34:53 +00001761 q_vector->rx_itr,
1762 rx_ring->total_packets,
1763 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001764 /* if the result for this queue would decrease interrupt
1765 * rate for this vector then use that result */
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001766 q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ?
Joe Perchese8e9f692010-09-07 21:34:53 +00001767 q_vector->rx_itr - 1 : ret_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001768 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00001769 r_idx + 1);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001770 }
1771
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07001772 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001773
1774 switch (current_itr) {
1775 /* counts and packets in update_itr are dependent on these numbers */
1776 case lowest_latency:
1777 new_itr = 100000;
1778 break;
1779 case low_latency:
1780 new_itr = 20000; /* aka hwitr = ~200 */
1781 break;
1782 case bulk_latency:
1783 default:
1784 new_itr = 8000;
1785 break;
1786 }
1787
1788 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00001789 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08001790 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00001791
1792 /* save the algorithm value here, not the smoothed one */
1793 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001794
1795 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001796 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08001797}
1798
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001799/**
1800 * ixgbe_check_overtemp_task - worker thread to check over tempurature
1801 * @work: pointer to work_struct containing our data
1802 **/
1803static void ixgbe_check_overtemp_task(struct work_struct *work)
1804{
1805 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00001806 struct ixgbe_adapter,
1807 check_overtemp_task);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001808 struct ixgbe_hw *hw = &adapter->hw;
1809 u32 eicr = adapter->interrupt_event;
1810
Joe Perches7ca647b2010-09-07 21:35:40 +00001811 if (!(adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE))
1812 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001813
Joe Perches7ca647b2010-09-07 21:35:40 +00001814 switch (hw->device_id) {
1815 case IXGBE_DEV_ID_82599_T3_LOM: {
1816 u32 autoneg;
1817 bool link_up = false;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001818
Joe Perches7ca647b2010-09-07 21:35:40 +00001819 if (hw->mac.ops.check_link)
1820 hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
1821
1822 if (((eicr & IXGBE_EICR_GPI_SDP0) && (!link_up)) ||
1823 (eicr & IXGBE_EICR_LSC))
1824 /* Check if this is due to overtemp */
1825 if (hw->phy.ops.check_overtemp(hw) == IXGBE_ERR_OVERTEMP)
1826 break;
1827 return;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001828 }
Joe Perches7ca647b2010-09-07 21:35:40 +00001829 default:
1830 if (!(eicr & IXGBE_EICR_GPI_SDP0))
1831 return;
1832 break;
1833 }
1834 e_crit(drv,
1835 "Network adapter has been stopped because it has over heated. "
1836 "Restart the computer. If the problem persists, "
1837 "power off the system and replace the adapter\n");
1838 /* write to clear the interrupt */
1839 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP0);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07001840}
1841
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001842static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr)
1843{
1844 struct ixgbe_hw *hw = &adapter->hw;
1845
1846 if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) &&
1847 (eicr & IXGBE_EICR_GPI_SDP1)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00001848 e_crit(probe, "Fan has stopped, replace the adapter\n");
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07001849 /* write to clear the interrupt */
1850 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
1851 }
1852}
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001853
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001854static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr)
1855{
1856 struct ixgbe_hw *hw = &adapter->hw;
1857
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001858 if (eicr & IXGBE_EICR_GPI_SDP2) {
1859 /* Clear the interrupt */
1860 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2);
1861 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1862 schedule_work(&adapter->sfp_config_module_task);
1863 }
1864
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001865 if (eicr & IXGBE_EICR_GPI_SDP1) {
1866 /* Clear the interrupt */
1867 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1);
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08001868 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1869 schedule_work(&adapter->multispeed_fiber_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00001870 }
1871}
1872
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001873static void ixgbe_check_lsc(struct ixgbe_adapter *adapter)
1874{
1875 struct ixgbe_hw *hw = &adapter->hw;
1876
1877 adapter->lsc_int++;
1878 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
1879 adapter->link_check_timeout = jiffies;
1880 if (!test_bit(__IXGBE_DOWN, &adapter->state)) {
1881 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC);
Nelson, Shannon8a0717f2009-11-12 18:47:11 +00001882 IXGBE_WRITE_FLUSH(hw);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001883 schedule_work(&adapter->watchdog_task);
1884 }
1885}
1886
Auke Kok9a799d72007-09-15 14:07:45 -07001887static irqreturn_t ixgbe_msix_lsc(int irq, void *data)
1888{
1889 struct net_device *netdev = data;
1890 struct ixgbe_adapter *adapter = netdev_priv(netdev);
1891 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore54037502009-02-21 15:42:56 -08001892 u32 eicr;
1893
1894 /*
1895 * Workaround for Silicon errata. Use clear-by-write instead
1896 * of clear-by-read. Reading with EICS will return the
1897 * interrupt causes without clearing, which later be done
1898 * with the write to EICR.
1899 */
1900 eicr = IXGBE_READ_REG(hw, IXGBE_EICS);
1901 IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr);
Auke Kok9a799d72007-09-15 14:07:45 -07001902
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07001903 if (eicr & IXGBE_EICR_LSC)
1904 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001905
Greg Rose1cdd1ec2010-01-09 02:26:46 +00001906 if (eicr & IXGBE_EICR_MAILBOX)
1907 ixgbe_msg_task(adapter);
1908
Alexander Duyckbd508172010-11-16 19:27:03 -08001909 switch (hw->mac.type) {
1910 case ixgbe_mac_82599EB:
Don Skidmored9946532010-12-09 06:55:19 +00001911 ixgbe_check_sfp_event(adapter, eicr);
1912 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
1913 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
1914 adapter->interrupt_event = eicr;
1915 schedule_work(&adapter->check_overtemp_task);
1916 }
1917 /* now fallthrough to handle Flow Director */
Don Skidmoreb93a2222010-11-16 19:27:17 -08001918 case ixgbe_mac_X540:
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001919 /* Handle Flow Director Full threshold interrupt */
1920 if (eicr & IXGBE_EICR_FLOW_DIR) {
1921 int i;
1922 IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR);
1923 /* Disable transmits before FDIR Re-initialization */
1924 netif_tx_stop_all_queues(netdev);
1925 for (i = 0; i < adapter->num_tx_queues; i++) {
1926 struct ixgbe_ring *tx_ring =
Joe Perchese8e9f692010-09-07 21:34:53 +00001927 adapter->tx_ring[i];
Alexander Duyck7d637bc2010-11-16 19:26:56 -08001928 if (test_and_clear_bit(__IXGBE_TX_FDIR_INIT_DONE,
1929 &tx_ring->state))
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001930 schedule_work(&adapter->fdir_reinit_task);
1931 }
1932 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001933 break;
1934 default:
1935 break;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00001936 }
Alexander Duyckbd508172010-11-16 19:27:03 -08001937
1938 ixgbe_check_fan_failure(adapter, eicr);
1939
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08001940 if (!test_bit(__IXGBE_DOWN, &adapter->state))
1941 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER);
Auke Kok9a799d72007-09-15 14:07:45 -07001942
1943 return IRQ_HANDLED;
1944}
1945
Alexander Duyckfe49f042009-06-04 16:00:09 +00001946static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter,
1947 u64 qmask)
1948{
1949 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001950 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001951
Alexander Duyckbd508172010-11-16 19:27:03 -08001952 switch (hw->mac.type) {
1953 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001954 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001955 IXGBE_WRITE_REG(hw, IXGBE_EIMS, mask);
1956 break;
1957 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001958 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001959 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001960 if (mask)
1961 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001962 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001963 if (mask)
1964 IXGBE_WRITE_REG(hw, IXGBE_EIMS_EX(1), mask);
1965 break;
1966 default:
1967 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001968 }
1969 /* skip the flush */
1970}
1971
1972static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00001973 u64 qmask)
Alexander Duyckfe49f042009-06-04 16:00:09 +00001974{
1975 u32 mask;
Alexander Duyckbd508172010-11-16 19:27:03 -08001976 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001977
Alexander Duyckbd508172010-11-16 19:27:03 -08001978 switch (hw->mac.type) {
1979 case ixgbe_mac_82598EB:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001980 mask = (IXGBE_EIMS_RTX_QUEUE & qmask);
Alexander Duyckbd508172010-11-16 19:27:03 -08001981 IXGBE_WRITE_REG(hw, IXGBE_EIMC, mask);
1982 break;
1983 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08001984 case ixgbe_mac_X540:
Alexander Duyckfe49f042009-06-04 16:00:09 +00001985 mask = (qmask & 0xFFFFFFFF);
Alexander Duyckbd508172010-11-16 19:27:03 -08001986 if (mask)
1987 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(0), mask);
Alexander Duyckfe49f042009-06-04 16:00:09 +00001988 mask = (qmask >> 32);
Alexander Duyckbd508172010-11-16 19:27:03 -08001989 if (mask)
1990 IXGBE_WRITE_REG(hw, IXGBE_EIMC_EX(1), mask);
1991 break;
1992 default:
1993 break;
Alexander Duyckfe49f042009-06-04 16:00:09 +00001994 }
1995 /* skip the flush */
1996}
1997
Auke Kok9a799d72007-09-15 14:07:45 -07001998static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data)
1999{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002000 struct ixgbe_q_vector *q_vector = data;
2001 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002002 struct ixgbe_ring *tx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002003 int i, r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002004
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002005 if (!q_vector->txr_count)
2006 return IRQ_HANDLED;
2007
2008 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2009 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002010 tx_ring = adapter->tx_ring[r_idx];
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002011 tx_ring->total_bytes = 0;
2012 tx_ring->total_packets = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002013 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002014 r_idx + 1);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002015 }
2016
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002017 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002018 napi_schedule(&q_vector->napi);
2019
Auke Kok9a799d72007-09-15 14:07:45 -07002020 return IRQ_HANDLED;
2021}
2022
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002023/**
2024 * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues)
2025 * @irq: unused
2026 * @data: pointer to our q_vector struct for this interrupt vector
2027 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002028static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data)
2029{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002030 struct ixgbe_q_vector *q_vector = data;
2031 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002032 struct ixgbe_ring *rx_ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002033 int r_idx;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002034 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07002035
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002036#ifdef CONFIG_IXGBE_DCA
2037 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2038 ixgbe_update_dca(q_vector);
2039#endif
2040
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002041 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002042 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002043 rx_ring = adapter->rx_ring[r_idx];
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002044 rx_ring->total_bytes = 0;
2045 rx_ring->total_packets = 0;
2046 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002047 r_idx + 1);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002048 }
2049
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002050 if (!q_vector->rxr_count)
2051 return IRQ_HANDLED;
2052
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002053 /* EIAM disabled interrupts (on this vector) for us */
Ben Hutchings288379f2009-01-19 16:43:59 -08002054 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002055
Auke Kok9a799d72007-09-15 14:07:45 -07002056 return IRQ_HANDLED;
2057}
2058
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002059static irqreturn_t ixgbe_msix_clean_many(int irq, void *data)
2060{
Alexander Duyck91281fd2009-06-04 16:00:27 +00002061 struct ixgbe_q_vector *q_vector = data;
2062 struct ixgbe_adapter *adapter = q_vector->adapter;
2063 struct ixgbe_ring *ring;
2064 int r_idx;
2065 int i;
2066
2067 if (!q_vector->txr_count && !q_vector->rxr_count)
2068 return IRQ_HANDLED;
2069
2070 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2071 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002072 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002073 ring->total_bytes = 0;
2074 ring->total_packets = 0;
2075 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002076 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002077 }
2078
2079 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2080 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002081 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002082 ring->total_bytes = 0;
2083 ring->total_packets = 0;
2084 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002085 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002086 }
2087
Jesse Brandeburg9b471442009-12-03 11:33:54 +00002088 /* EIAM disabled interrupts (on this vector) for us */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002089 napi_schedule(&q_vector->napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002090
2091 return IRQ_HANDLED;
2092}
2093
2094/**
2095 * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine
2096 * @napi: napi struct with our devices info in it
2097 * @budget: amount of work driver is allowed to do this pass, in packets
2098 *
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002099 * This function is optimized for cleaning one queue only on a single
2100 * q_vector!!!
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002101 **/
Auke Kok9a799d72007-09-15 14:07:45 -07002102static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget)
2103{
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002104 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002105 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002106 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002107 struct ixgbe_ring *rx_ring = NULL;
Auke Kok9a799d72007-09-15 14:07:45 -07002108 int work_done = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002109 long r_idx;
Auke Kok9a799d72007-09-15 14:07:45 -07002110
Jeff Garzik5dd2d332008-10-16 05:09:31 -04002111#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002112 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002113 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08002114#endif
Auke Kok9a799d72007-09-15 14:07:45 -07002115
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002116 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2117 rx_ring = adapter->rx_ring[r_idx];
2118
Herbert Xu78b6f4c2009-01-18 21:49:45 -08002119 ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07002120
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002121 /* If all Rx work done, exit the polling mode */
2122 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002123 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002124 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002125 ixgbe_set_itr_msix(q_vector);
Auke Kok9a799d72007-09-15 14:07:45 -07002126 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002127 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002128 ((u64)1 << q_vector->v_idx));
Auke Kok9a799d72007-09-15 14:07:45 -07002129 }
2130
2131 return work_done;
2132}
2133
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002134/**
Alexander Duyck91281fd2009-06-04 16:00:27 +00002135 * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002136 * @napi: napi struct with our devices info in it
2137 * @budget: amount of work driver is allowed to do this pass, in packets
2138 *
2139 * This function will clean more than one rx queue associated with a
2140 * q_vector.
2141 **/
Alexander Duyck91281fd2009-06-04 16:00:27 +00002142static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002143{
2144 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002145 container_of(napi, struct ixgbe_q_vector, napi);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002146 struct ixgbe_adapter *adapter = q_vector->adapter;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002147 struct ixgbe_ring *ring = NULL;
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002148 int work_done = 0, i;
2149 long r_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00002150 bool tx_clean_complete = true;
2151
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002152#ifdef CONFIG_IXGBE_DCA
2153 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
2154 ixgbe_update_dca(q_vector);
2155#endif
2156
Alexander Duyck91281fd2009-06-04 16:00:27 +00002157 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2158 for (i = 0; i < q_vector->txr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002159 ring = adapter->tx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002160 tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring);
2161 r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002162 r_idx + 1);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002163 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002164
2165 /* attempt to distribute budget to each queue fairly, but don't allow
2166 * the budget to go below 1 because we'll exit polling */
2167 budget /= (q_vector->rxr_count ?: 1);
2168 budget = max(budget, 1);
2169 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
2170 for (i = 0; i < q_vector->rxr_count; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002171 ring = adapter->rx_ring[r_idx];
Alexander Duyck91281fd2009-06-04 16:00:27 +00002172 ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002173 r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00002174 r_idx + 1);
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002175 }
2176
2177 r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002178 ring = adapter->rx_ring[r_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002179 /* If all Rx work done, exit the polling mode */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07002180 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08002181 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002182 if (adapter->rx_itr_setting & 1)
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002183 ixgbe_set_itr_msix(q_vector);
2184 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Alexander Duyckfe49f042009-06-04 16:00:09 +00002185 ixgbe_irq_enable_queues(adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002186 ((u64)1 << q_vector->v_idx));
Jesse Brandeburgf0848272008-09-11 19:59:42 -07002187 return 0;
2188 }
2189
2190 return work_done;
2191}
Alexander Duyck91281fd2009-06-04 16:00:27 +00002192
2193/**
2194 * ixgbe_clean_txonly - msix (aka one shot) tx clean routine
2195 * @napi: napi struct with our devices info in it
2196 * @budget: amount of work driver is allowed to do this pass, in packets
2197 *
2198 * This function is optimized for cleaning one queue only on a single
2199 * q_vector!!!
2200 **/
2201static int ixgbe_clean_txonly(struct napi_struct *napi, int budget)
2202{
2203 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00002204 container_of(napi, struct ixgbe_q_vector, napi);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002205 struct ixgbe_adapter *adapter = q_vector->adapter;
2206 struct ixgbe_ring *tx_ring = NULL;
2207 int work_done = 0;
2208 long r_idx;
2209
Alexander Duyck91281fd2009-06-04 16:00:27 +00002210#ifdef CONFIG_IXGBE_DCA
2211 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002212 ixgbe_update_dca(q_vector);
Alexander Duyck91281fd2009-06-04 16:00:27 +00002213#endif
2214
Alexander Duyck33cf09c2010-11-16 19:26:55 -08002215 r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues);
2216 tx_ring = adapter->tx_ring[r_idx];
2217
Alexander Duyck91281fd2009-06-04 16:00:27 +00002218 if (!ixgbe_clean_tx_irq(q_vector, tx_ring))
2219 work_done = budget;
2220
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002221 /* If all Tx work done, exit the polling mode */
Alexander Duyck91281fd2009-06-04 16:00:27 +00002222 if (work_done < budget) {
2223 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00002224 if (adapter->tx_itr_setting & 1)
Alexander Duyck91281fd2009-06-04 16:00:27 +00002225 ixgbe_set_itr_msix(q_vector);
2226 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Joe Perchese8e9f692010-09-07 21:34:53 +00002227 ixgbe_irq_enable_queues(adapter,
2228 ((u64)1 << q_vector->v_idx));
Alexander Duyck91281fd2009-06-04 16:00:27 +00002229 }
2230
2231 return work_done;
2232}
2233
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002234static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002235 int r_idx)
Auke Kok9a799d72007-09-15 14:07:45 -07002236{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002237 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002238 struct ixgbe_ring *rx_ring = a->rx_ring[r_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002239
2240 set_bit(r_idx, q_vector->rxr_idx);
2241 q_vector->rxr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002242 rx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002243}
Auke Kok9a799d72007-09-15 14:07:45 -07002244
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002245static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx,
Joe Perchese8e9f692010-09-07 21:34:53 +00002246 int t_idx)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002247{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002248 struct ixgbe_q_vector *q_vector = a->q_vector[v_idx];
Alexander Duyck22745432010-11-16 19:27:10 -08002249 struct ixgbe_ring *tx_ring = a->tx_ring[t_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00002250
2251 set_bit(t_idx, q_vector->txr_idx);
2252 q_vector->txr_count++;
Alexander Duyck22745432010-11-16 19:27:10 -08002253 tx_ring->q_vector = q_vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002254}
Auke Kok9a799d72007-09-15 14:07:45 -07002255
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002256/**
2257 * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors
2258 * @adapter: board private structure to initialize
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002259 *
2260 * This function maps descriptor rings to the queue-specific vectors
2261 * we were allotted through the MSI-X enabling code. Ideally, we'd have
2262 * one vector per ring/queue, but on a constrained vector budget, we
2263 * group the rings as "efficiently" as possible. You would add new
2264 * mapping configurations in here.
2265 **/
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002266static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002267{
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002268 int q_vectors;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002269 int v_start = 0;
2270 int rxr_idx = 0, txr_idx = 0;
2271 int rxr_remaining = adapter->num_rx_queues;
2272 int txr_remaining = adapter->num_tx_queues;
2273 int i, j;
2274 int rqpv, tqpv;
2275 int err = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07002276
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002277 /* No mapping required if MSI-X is disabled. */
2278 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
Auke Kok9a799d72007-09-15 14:07:45 -07002279 goto out;
2280
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002281 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2282
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002283 /*
2284 * The ideal configuration...
2285 * We have enough vectors to map one per queue.
2286 */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002287 if (q_vectors == adapter->num_rx_queues + adapter->num_tx_queues) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002288 for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++)
2289 map_vector_to_rxq(adapter, v_start, rxr_idx);
2290
2291 for (; txr_idx < txr_remaining; v_start++, txr_idx++)
2292 map_vector_to_txq(adapter, v_start, txr_idx);
2293
2294 goto out;
2295 }
2296
2297 /*
2298 * If we don't have enough vectors for a 1-to-1
2299 * mapping, we'll have to group them so there are
2300 * multiple queues per vector.
2301 */
2302 /* Re-adjusting *qpv takes care of the remainder. */
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002303 for (i = v_start; i < q_vectors; i++) {
2304 rqpv = DIV_ROUND_UP(rxr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002305 for (j = 0; j < rqpv; j++) {
2306 map_vector_to_rxq(adapter, i, rxr_idx);
2307 rxr_idx++;
2308 rxr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002309 }
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002310 tqpv = DIV_ROUND_UP(txr_remaining, q_vectors - i);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002311 for (j = 0; j < tqpv; j++) {
2312 map_vector_to_txq(adapter, i, txr_idx);
2313 txr_idx++;
2314 txr_remaining--;
Auke Kok9a799d72007-09-15 14:07:45 -07002315 }
Auke Kok9a799d72007-09-15 14:07:45 -07002316 }
Auke Kok9a799d72007-09-15 14:07:45 -07002317out:
Auke Kok9a799d72007-09-15 14:07:45 -07002318 return err;
2319}
2320
2321/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002322 * ixgbe_request_msix_irqs - Initialize MSI-X interrupts
2323 * @adapter: board private structure
2324 *
2325 * ixgbe_request_msix_irqs allocates MSI-X vectors and requests
2326 * interrupts from the kernel.
2327 **/
2328static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter)
2329{
2330 struct net_device *netdev = adapter->netdev;
2331 irqreturn_t (*handler)(int, void *);
2332 int i, vector, q_vectors, err;
Joe Perchese8e9f692010-09-07 21:34:53 +00002333 int ri = 0, ti = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002334
2335 /* Decrement for Other and TCP Timer vectors */
2336 q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2337
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002338 err = ixgbe_map_rings_to_vectors(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002339 if (err)
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002340 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002341
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002342#define SET_HANDLER(_v) (((_v)->rxr_count && (_v)->txr_count) \
2343 ? &ixgbe_msix_clean_many : \
2344 (_v)->rxr_count ? &ixgbe_msix_clean_rx : \
2345 (_v)->txr_count ? &ixgbe_msix_clean_tx : \
2346 NULL)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002347 for (vector = 0; vector < q_vectors; vector++) {
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002348 struct ixgbe_q_vector *q_vector = adapter->q_vector[vector];
2349 handler = SET_HANDLER(q_vector);
Robert Olssoncb13fc22008-11-25 16:43:52 -08002350
Joe Perchese8e9f692010-09-07 21:34:53 +00002351 if (handler == &ixgbe_msix_clean_rx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002352 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2353 "%s-%s-%d", netdev->name, "rx", ri++);
Joe Perchese8e9f692010-09-07 21:34:53 +00002354 } else if (handler == &ixgbe_msix_clean_tx) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002355 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2356 "%s-%s-%d", netdev->name, "tx", ti++);
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002357 } else if (handler == &ixgbe_msix_clean_many) {
Don Skidmore9fe93af2010-12-03 09:33:54 +00002358 snprintf(q_vector->name, sizeof(q_vector->name) - 1,
2359 "%s-%s-%d", netdev->name, "TxRx", ri++);
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002360 ti++;
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002361 } else {
2362 /* skip this unused q_vector */
2363 continue;
Alexander Duyck32aa77a2010-11-16 19:26:59 -08002364 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002365 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002366 handler, 0, q_vector->name,
2367 q_vector);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002368 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002369 e_err(probe, "request_irq failed for MSIX interrupt "
Emil Tantilov849c4542010-06-03 16:53:41 +00002370 "Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002371 goto free_queue_irqs;
2372 }
2373 }
2374
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002375 sprintf(adapter->lsc_int_name, "%s:lsc", netdev->name);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002376 err = request_irq(adapter->msix_entries[vector].vector,
Alexander Duyckd0759eb2010-11-16 19:27:09 -08002377 ixgbe_msix_lsc, 0, adapter->lsc_int_name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002378 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00002379 e_err(probe, "request_irq for msix_lsc failed: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002380 goto free_queue_irqs;
2381 }
2382
2383 return 0;
2384
2385free_queue_irqs:
2386 for (i = vector - 1; i >= 0; i--)
2387 free_irq(adapter->msix_entries[--vector].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002388 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002389 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
2390 pci_disable_msix(adapter->pdev);
2391 kfree(adapter->msix_entries);
2392 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002393 return err;
2394}
2395
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002396static void ixgbe_set_itr(struct ixgbe_adapter *adapter)
2397{
Alexander Duyck7a921c92009-05-06 10:43:28 +00002398 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002399 struct ixgbe_ring *rx_ring = adapter->rx_ring[0];
2400 struct ixgbe_ring *tx_ring = adapter->tx_ring[0];
Alexander Duyck125601b2010-11-16 19:27:08 -08002401 u32 new_itr = q_vector->eitr;
2402 u8 current_itr;
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002403
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002404 q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002405 q_vector->tx_itr,
2406 tx_ring->total_packets,
2407 tx_ring->total_bytes);
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002408 q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr,
Joe Perchese8e9f692010-09-07 21:34:53 +00002409 q_vector->rx_itr,
2410 rx_ring->total_packets,
2411 rx_ring->total_bytes);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002412
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07002413 current_itr = max(q_vector->rx_itr, q_vector->tx_itr);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002414
2415 switch (current_itr) {
2416 /* counts and packets in update_itr are dependent on these numbers */
2417 case lowest_latency:
2418 new_itr = 100000;
2419 break;
2420 case low_latency:
2421 new_itr = 20000; /* aka hwitr = ~200 */
2422 break;
2423 case bulk_latency:
2424 new_itr = 8000;
2425 break;
2426 default:
2427 break;
2428 }
2429
2430 if (new_itr != q_vector->eitr) {
Alexander Duyckfe49f042009-06-04 16:00:09 +00002431 /* do an exponential smoothing */
Alexander Duyck125601b2010-11-16 19:27:08 -08002432 new_itr = ((q_vector->eitr * 9) + new_itr)/10;
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002433
Alexander Duyck125601b2010-11-16 19:27:08 -08002434 /* save the algorithm value here */
Jesse Brandeburg509ee932009-03-13 22:13:28 +00002435 q_vector->eitr = new_itr;
Alexander Duyckfe49f042009-06-04 16:00:09 +00002436
2437 ixgbe_write_eitr(q_vector);
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002438 }
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08002439}
2440
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002441/**
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002442 * ixgbe_irq_enable - Enable default interrupt generation settings
2443 * @adapter: board private structure
2444 **/
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002445static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter, bool queues,
2446 bool flush)
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002447{
2448 u32 mask;
Nelson, Shannon835462f2009-04-27 22:42:54 +00002449
2450 mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07002451 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
2452 mask |= IXGBE_EIMS_GPI_SDP0;
David S. Miller6ab33d52008-11-20 16:44:00 -08002453 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
2454 mask |= IXGBE_EIMS_GPI_SDP1;
Alexander Duyckbd508172010-11-16 19:27:03 -08002455 switch (adapter->hw.mac.type) {
2456 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002457 case ixgbe_mac_X540:
Jesse Brandeburg2a41ff82009-03-13 22:14:30 +00002458 mask |= IXGBE_EIMS_ECC;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002459 mask |= IXGBE_EIMS_GPI_SDP1;
2460 mask |= IXGBE_EIMS_GPI_SDP2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002461 if (adapter->num_vfs)
2462 mask |= IXGBE_EIMS_MAILBOX;
Alexander Duyckbd508172010-11-16 19:27:03 -08002463 break;
2464 default:
2465 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002466 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00002467 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
2468 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
2469 mask |= IXGBE_EIMS_FLOW_DIR;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002470
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002471 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002472 if (queues)
2473 ixgbe_irq_enable_queues(adapter, ~0);
2474 if (flush)
2475 IXGBE_WRITE_FLUSH(&adapter->hw);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002476
2477 if (adapter->num_vfs > 32) {
2478 u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1;
2479 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel);
2480 }
Alexey Dobriyan79aefa42008-11-19 14:17:02 -08002481}
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002482
2483/**
2484 * ixgbe_intr - legacy mode Interrupt Handler
Auke Kok9a799d72007-09-15 14:07:45 -07002485 * @irq: interrupt number
2486 * @data: pointer to a network interface device structure
Auke Kok9a799d72007-09-15 14:07:45 -07002487 **/
2488static irqreturn_t ixgbe_intr(int irq, void *data)
2489{
2490 struct net_device *netdev = data;
2491 struct ixgbe_adapter *adapter = netdev_priv(netdev);
2492 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck7a921c92009-05-06 10:43:28 +00002493 struct ixgbe_q_vector *q_vector = adapter->q_vector[0];
Auke Kok9a799d72007-09-15 14:07:45 -07002494 u32 eicr;
2495
Don Skidmore54037502009-02-21 15:42:56 -08002496 /*
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002497 * Workaround for silicon errata on 82598. Mask the interrupts
Don Skidmore54037502009-02-21 15:42:56 -08002498 * before the read of EICR.
2499 */
2500 IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK);
2501
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002502 /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read
2503 * therefore no explict interrupt disable is necessary */
2504 eicr = IXGBE_READ_REG(hw, IXGBE_EICR);
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002505 if (!eicr) {
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002506 /*
2507 * shared interrupt alert!
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002508 * make sure interrupts are enabled because the read will
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002509 * have disabled interrupts due to EIAM
2510 * finish the workaround of silicon errata on 82598. Unmask
2511 * the interrupt that we masked before the EICR read.
2512 */
2513 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2514 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07002515 return IRQ_NONE; /* Not our interrupt */
Jesse Brandeburgf47cf662008-09-11 19:56:14 -07002516 }
Auke Kok9a799d72007-09-15 14:07:45 -07002517
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07002518 if (eicr & IXGBE_EICR_LSC)
2519 ixgbe_check_lsc(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002520
Alexander Duyckbd508172010-11-16 19:27:03 -08002521 switch (hw->mac.type) {
2522 case ixgbe_mac_82599EB:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002523 ixgbe_check_sfp_event(adapter, eicr);
Alexander Duyckbd508172010-11-16 19:27:03 -08002524 if ((adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE) &&
2525 ((eicr & IXGBE_EICR_GPI_SDP0) || (eicr & IXGBE_EICR_LSC))) {
2526 adapter->interrupt_event = eicr;
2527 schedule_work(&adapter->check_overtemp_task);
2528 }
2529 break;
2530 default:
2531 break;
2532 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002533
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07002534 ixgbe_check_fan_failure(adapter, eicr);
2535
Alexander Duyck7a921c92009-05-06 10:43:28 +00002536 if (napi_schedule_prep(&(q_vector->napi))) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00002537 adapter->tx_ring[0]->total_packets = 0;
2538 adapter->tx_ring[0]->total_bytes = 0;
2539 adapter->rx_ring[0]->total_packets = 0;
2540 adapter->rx_ring[0]->total_bytes = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002541 /* would disable interrupts here but EIAM disabled it */
Alexander Duyck7a921c92009-05-06 10:43:28 +00002542 __napi_schedule(&(q_vector->napi));
Auke Kok9a799d72007-09-15 14:07:45 -07002543 }
2544
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00002545 /*
2546 * re-enable link(maybe) and non-queue interrupts, no flush.
2547 * ixgbe_poll will re-enable the queue interrupts
2548 */
2549
2550 if (!test_bit(__IXGBE_DOWN, &adapter->state))
2551 ixgbe_irq_enable(adapter, false, false);
2552
Auke Kok9a799d72007-09-15 14:07:45 -07002553 return IRQ_HANDLED;
2554}
2555
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002556static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter)
2557{
2558 int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
2559
2560 for (i = 0; i < q_vectors; i++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00002561 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002562 bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES);
2563 bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES);
2564 q_vector->rxr_count = 0;
2565 q_vector->txr_count = 0;
2566 }
2567}
2568
Auke Kok9a799d72007-09-15 14:07:45 -07002569/**
2570 * ixgbe_request_irq - initialize interrupts
2571 * @adapter: board private structure
2572 *
2573 * Attempts to configure interrupts using the best available
2574 * capabilities of the hardware and kernel.
2575 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002576static int ixgbe_request_irq(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07002577{
2578 struct net_device *netdev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002579 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07002580
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002581 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2582 err = ixgbe_request_msix_irqs(adapter);
2583 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002584 err = request_irq(adapter->pdev->irq, ixgbe_intr, 0,
Joe Perchese8e9f692010-09-07 21:34:53 +00002585 netdev->name, netdev);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002586 } else {
Joe Perchesa0607fd2009-11-18 23:29:17 -08002587 err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED,
Joe Perchese8e9f692010-09-07 21:34:53 +00002588 netdev->name, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002589 }
2590
Auke Kok9a799d72007-09-15 14:07:45 -07002591 if (err)
Emil Tantilov396e7992010-07-01 20:05:12 +00002592 e_err(probe, "request_irq failed, Error %d\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07002593
Auke Kok9a799d72007-09-15 14:07:45 -07002594 return err;
2595}
2596
2597static void ixgbe_free_irq(struct ixgbe_adapter *adapter)
2598{
2599 struct net_device *netdev = adapter->netdev;
2600
2601 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002602 int i, q_vectors;
Auke Kok9a799d72007-09-15 14:07:45 -07002603
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002604 q_vectors = adapter->num_msix_vectors;
2605
2606 i = q_vectors - 1;
Auke Kok9a799d72007-09-15 14:07:45 -07002607 free_irq(adapter->msix_entries[i].vector, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002608
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002609 i--;
2610 for (; i >= 0; i--) {
Alexander Duyck894ff7c2011-02-15 02:12:05 +00002611 /* free only the irqs that were actually requested */
2612 if (!adapter->q_vector[i]->rxr_count &&
2613 !adapter->q_vector[i]->txr_count)
2614 continue;
2615
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002616 free_irq(adapter->msix_entries[i].vector,
Joe Perchese8e9f692010-09-07 21:34:53 +00002617 adapter->q_vector[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002618 }
2619
2620 ixgbe_reset_q_vectors(adapter);
2621 } else {
2622 free_irq(adapter->pdev->irq, netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07002623 }
2624}
2625
2626/**
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002627 * ixgbe_irq_disable - Mask off interrupt generation on the NIC
2628 * @adapter: board private structure
2629 **/
2630static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter)
2631{
Alexander Duyckbd508172010-11-16 19:27:03 -08002632 switch (adapter->hw.mac.type) {
2633 case ixgbe_mac_82598EB:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002634 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002635 break;
2636 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002637 case ixgbe_mac_X540:
Nelson, Shannon835462f2009-04-27 22:42:54 +00002638 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000);
2639 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0);
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002640 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002641 if (adapter->num_vfs > 32)
2642 IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0);
Alexander Duyckbd508172010-11-16 19:27:03 -08002643 break;
2644 default:
2645 break;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002646 }
2647 IXGBE_WRITE_FLUSH(&adapter->hw);
2648 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
2649 int i;
2650 for (i = 0; i < adapter->num_msix_vectors; i++)
2651 synchronize_irq(adapter->msix_entries[i].vector);
2652 } else {
2653 synchronize_irq(adapter->pdev->irq);
2654 }
2655}
2656
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00002657/**
Auke Kok9a799d72007-09-15 14:07:45 -07002658 * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts
2659 *
2660 **/
2661static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter)
2662{
Auke Kok9a799d72007-09-15 14:07:45 -07002663 struct ixgbe_hw *hw = &adapter->hw;
2664
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002665 IXGBE_WRITE_REG(hw, IXGBE_EITR(0),
Joe Perchese8e9f692010-09-07 21:34:53 +00002666 EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param));
Auke Kok9a799d72007-09-15 14:07:45 -07002667
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002668 ixgbe_set_ivar(adapter, 0, 0, 0);
2669 ixgbe_set_ivar(adapter, 1, 0, 0);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08002670
2671 map_vector_to_rxq(adapter, 0, 0);
2672 map_vector_to_txq(adapter, 0, 0);
2673
Emil Tantilov396e7992010-07-01 20:05:12 +00002674 e_info(hw, "Legacy interrupt IVAR setup done\n");
Auke Kok9a799d72007-09-15 14:07:45 -07002675}
2676
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002677/**
2678 * ixgbe_configure_tx_ring - Configure 8259x Tx ring after Reset
2679 * @adapter: board private structure
2680 * @ring: structure containing ring specific data
2681 *
2682 * Configure the Tx descriptor ring after a reset.
2683 **/
Alexander Duyck84418e32010-08-19 13:40:54 +00002684void ixgbe_configure_tx_ring(struct ixgbe_adapter *adapter,
2685 struct ixgbe_ring *ring)
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002686{
2687 struct ixgbe_hw *hw = &adapter->hw;
2688 u64 tdba = ring->dma;
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002689 int wait_loop = 10;
2690 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002691 u8 reg_idx = ring->reg_idx;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002692
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002693 /* disable queue to avoid issues while updating state */
2694 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2695 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
2696 txdctl & ~IXGBE_TXDCTL_ENABLE);
2697 IXGBE_WRITE_FLUSH(hw);
2698
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002699 IXGBE_WRITE_REG(hw, IXGBE_TDBAL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00002700 (tdba & DMA_BIT_MASK(32)));
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002701 IXGBE_WRITE_REG(hw, IXGBE_TDBAH(reg_idx), (tdba >> 32));
2702 IXGBE_WRITE_REG(hw, IXGBE_TDLEN(reg_idx),
2703 ring->count * sizeof(union ixgbe_adv_tx_desc));
2704 IXGBE_WRITE_REG(hw, IXGBE_TDH(reg_idx), 0);
2705 IXGBE_WRITE_REG(hw, IXGBE_TDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08002706 ring->tail = hw->hw_addr + IXGBE_TDT(reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002707
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002708 /* configure fetching thresholds */
2709 if (adapter->rx_itr_setting == 0) {
2710 /* cannot set wthresh when itr==0 */
2711 txdctl &= ~0x007F0000;
2712 } else {
2713 /* enable WTHRESH=8 descriptors, to encourage burst writeback */
2714 txdctl |= (8 << 16);
2715 }
2716 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
2717 /* PThresh workaround for Tx hang with DFP enabled. */
2718 txdctl |= 32;
2719 }
2720
2721 /* reinitialize flowdirector state */
Alexander Duyckee9e0f02010-11-16 19:27:01 -08002722 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) &&
2723 adapter->atr_sample_rate) {
2724 ring->atr_sample_rate = adapter->atr_sample_rate;
2725 ring->atr_count = 0;
2726 set_bit(__IXGBE_TX_FDIR_INIT_DONE, &ring->state);
2727 } else {
2728 ring->atr_sample_rate = 0;
2729 }
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002730
John Fastabendc84d3242010-11-16 19:27:12 -08002731 clear_bit(__IXGBE_HANG_CHECK_ARMED, &ring->state);
2732
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002733 /* enable queue */
2734 txdctl |= IXGBE_TXDCTL_ENABLE;
2735 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx), txdctl);
2736
2737 /* TXDCTL.EN will return 0 on 82598 if link is down, so skip it */
2738 if (hw->mac.type == ixgbe_mac_82598EB &&
2739 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
2740 return;
2741
2742 /* poll to verify queue is enabled */
2743 do {
Don Skidmore032b4322011-03-18 09:32:53 +00002744 usleep_range(1000, 2000);
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002745 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
2746 } while (--wait_loop && !(txdctl & IXGBE_TXDCTL_ENABLE));
2747 if (!wait_loop)
2748 e_err(drv, "Could not enable Tx Queue %d\n", reg_idx);
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002749}
2750
Alexander Duyck120ff942010-08-19 13:34:50 +00002751static void ixgbe_setup_mtqc(struct ixgbe_adapter *adapter)
2752{
2753 struct ixgbe_hw *hw = &adapter->hw;
2754 u32 rttdcs;
2755 u32 mask;
2756
2757 if (hw->mac.type == ixgbe_mac_82598EB)
2758 return;
2759
2760 /* disable the arbiter while setting MTQC */
2761 rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS);
2762 rttdcs |= IXGBE_RTTDCS_ARBDIS;
2763 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2764
2765 /* set transmit pool layout */
2766 mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED);
2767 switch (adapter->flags & mask) {
2768
2769 case (IXGBE_FLAG_SRIOV_ENABLED):
2770 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2771 (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF));
2772 break;
2773
2774 case (IXGBE_FLAG_DCB_ENABLED):
2775 /* We enable 8 traffic classes, DCB only */
2776 IXGBE_WRITE_REG(hw, IXGBE_MTQC,
2777 (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ));
2778 break;
2779
2780 default:
2781 IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB);
2782 break;
2783 }
2784
2785 /* re-enable the arbiter */
2786 rttdcs &= ~IXGBE_RTTDCS_ARBDIS;
2787 IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs);
2788}
2789
Auke Kok9a799d72007-09-15 14:07:45 -07002790/**
Jesse Brandeburg3a581072008-08-26 04:27:08 -07002791 * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset
Auke Kok9a799d72007-09-15 14:07:45 -07002792 * @adapter: board private structure
2793 *
2794 * Configure the Tx unit of the MAC after a reset.
2795 **/
2796static void ixgbe_configure_tx(struct ixgbe_adapter *adapter)
2797{
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002798 struct ixgbe_hw *hw = &adapter->hw;
2799 u32 dmatxctl;
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002800 u32 i;
Auke Kok9a799d72007-09-15 14:07:45 -07002801
Alexander Duyck2f1860b2010-08-19 13:39:43 +00002802 ixgbe_setup_mtqc(adapter);
2803
2804 if (hw->mac.type != ixgbe_mac_82598EB) {
2805 /* DMATXCTL.EN must be before Tx queues are enabled */
2806 dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL);
2807 dmatxctl |= IXGBE_DMATXCTL_TE;
2808 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl);
2809 }
2810
Auke Kok9a799d72007-09-15 14:07:45 -07002811 /* Setup the HW Tx Head and Tail descriptor pointers */
Alexander Duyck43e69bf2010-08-19 13:35:12 +00002812 for (i = 0; i < adapter->num_tx_queues; i++)
2813 ixgbe_configure_tx_ring(adapter, adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07002814}
2815
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002816#define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2
Auke Kok9a799d72007-09-15 14:07:45 -07002817
Yi Zoua6616b42009-08-06 13:05:23 +00002818static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00002819 struct ixgbe_ring *rx_ring)
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002820{
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002821 u32 srrctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002822 u8 reg_idx = rx_ring->reg_idx;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002823
Alexander Duyckbd508172010-11-16 19:27:03 -08002824 switch (adapter->hw.mac.type) {
2825 case ixgbe_mac_82598EB: {
2826 struct ixgbe_ring_feature *feature = adapter->ring_feature;
2827 const int mask = feature[RING_F_RSS].mask;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002828 reg_idx = reg_idx & mask;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002829 }
Alexander Duyckbd508172010-11-16 19:27:03 -08002830 break;
2831 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08002832 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08002833 default:
2834 break;
2835 }
2836
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002837 srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx));
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002838
2839 srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK;
2840 srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK;
Alexander Duyck9e10e042010-08-19 13:40:06 +00002841 if (adapter->num_vfs)
2842 srrctl |= IXGBE_SRRCTL_DROP_EN;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002843
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002844 srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) &
2845 IXGBE_SRRCTL_BSIZEHDR_MASK;
2846
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002847 if (ring_is_ps_enabled(rx_ring)) {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002848#if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER
2849 srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2850#else
2851 srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT;
2852#endif
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002853 srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002854 } else {
Alexander Duyckafafd5b2009-05-07 10:38:56 +00002855 srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >>
2856 IXGBE_SRRCTL_BSIZEPKT_SHIFT;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002857 srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002858 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00002859
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002860 IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(reg_idx), srrctl);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07002861}
2862
Alexander Duyck05abb122010-08-19 13:35:41 +00002863static void ixgbe_setup_mrqc(struct ixgbe_adapter *adapter)
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002864{
Alexander Duyck05abb122010-08-19 13:35:41 +00002865 struct ixgbe_hw *hw = &adapter->hw;
2866 static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D,
Joe Perchese8e9f692010-09-07 21:34:53 +00002867 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE,
2868 0x6A3E67EA, 0x14364D17, 0x3BED200D};
Alexander Duyck05abb122010-08-19 13:35:41 +00002869 u32 mrqc = 0, reta = 0;
2870 u32 rxcsum;
2871 int i, j;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002872 int mask;
2873
Alexander Duyck05abb122010-08-19 13:35:41 +00002874 /* Fill out hash function seeds */
2875 for (i = 0; i < 10; i++)
2876 IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002877
Alexander Duyck05abb122010-08-19 13:35:41 +00002878 /* Fill out redirection table */
2879 for (i = 0, j = 0; i < 128; i++, j++) {
2880 if (j == adapter->ring_feature[RING_F_RSS].indices)
2881 j = 0;
2882 /* reta = 4-byte sliding window of
2883 * 0x00..(indices-1)(indices-1)00..etc. */
2884 reta = (reta << 8) | (j * 0x11);
2885 if ((i & 3) == 3)
2886 IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta);
2887 }
2888
2889 /* Disable indicating checksum in descriptor, enables RSS hash */
2890 rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM);
2891 rxcsum |= IXGBE_RXCSUM_PCSD;
2892 IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum);
2893
2894 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
2895 mask = adapter->flags & IXGBE_FLAG_RSS_ENABLED;
2896 else
2897 mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002898#ifdef CONFIG_IXGBE_DCB
Alexander Duyck05abb122010-08-19 13:35:41 +00002899 | IXGBE_FLAG_DCB_ENABLED
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002900#endif
Alexander Duyck05abb122010-08-19 13:35:41 +00002901 | IXGBE_FLAG_SRIOV_ENABLED
2902 );
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002903
2904 switch (mask) {
John Fastabend8187cd42011-02-23 05:58:08 +00002905#ifdef CONFIG_IXGBE_DCB
2906 case (IXGBE_FLAG_DCB_ENABLED | IXGBE_FLAG_RSS_ENABLED):
2907 mrqc = IXGBE_MRQC_RTRSS8TCEN;
2908 break;
2909 case (IXGBE_FLAG_DCB_ENABLED):
2910 mrqc = IXGBE_MRQC_RT8TCEN;
2911 break;
2912#endif /* CONFIG_IXGBE_DCB */
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002913 case (IXGBE_FLAG_RSS_ENABLED):
2914 mrqc = IXGBE_MRQC_RSSEN;
2915 break;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00002916 case (IXGBE_FLAG_SRIOV_ENABLED):
2917 mrqc = IXGBE_MRQC_VMDQEN;
2918 break;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002919 default:
2920 break;
2921 }
2922
Alexander Duyck05abb122010-08-19 13:35:41 +00002923 /* Perform hash on these packet types */
2924 mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4
2925 | IXGBE_MRQC_RSS_FIELD_IPV4_TCP
2926 | IXGBE_MRQC_RSS_FIELD_IPV6
2927 | IXGBE_MRQC_RSS_FIELD_IPV6_TCP;
2928
2929 IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc);
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00002930}
2931
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07002932/**
Don Skidmoreb93a2222010-11-16 19:27:17 -08002933 * ixgbe_clear_rscctl - disable RSC for the indicated ring
2934 * @adapter: address of board private structure
2935 * @ring: structure containing ring specific data
2936 **/
2937void ixgbe_clear_rscctl(struct ixgbe_adapter *adapter,
2938 struct ixgbe_ring *ring)
2939{
2940 struct ixgbe_hw *hw = &adapter->hw;
2941 u32 rscctrl;
2942 u8 reg_idx = ring->reg_idx;
2943
2944 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
2945 rscctrl &= ~IXGBE_RSCCTL_RSCEN;
2946 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
2947}
2948
2949/**
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002950 * ixgbe_configure_rscctl - enable RSC for the indicated ring
2951 * @adapter: address of board private structure
2952 * @index: index of ring to set
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002953 **/
Don Skidmoreb93a2222010-11-16 19:27:17 -08002954void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter,
Alexander Duyck73670962010-08-19 13:38:34 +00002955 struct ixgbe_ring *ring)
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002956{
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002957 struct ixgbe_hw *hw = &adapter->hw;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002958 u32 rscctrl;
Mallikarjuna R Chilakalaedd2ea52009-11-23 10:45:11 -08002959 int rx_buf_len;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08002960 u8 reg_idx = ring->reg_idx;
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002961
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002962 if (!ring_is_rsc_enabled(ring))
Alexander Duyck73670962010-08-19 13:38:34 +00002963 return;
2964
2965 rx_buf_len = ring->rx_buf_len;
2966 rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(reg_idx));
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002967 rscctrl |= IXGBE_RSCCTL_RSCEN;
2968 /*
2969 * we must limit the number of descriptors so that the
2970 * total size of max desc * buf_len is not greater
2971 * than 65535
2972 */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08002973 if (ring_is_ps_enabled(ring)) {
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002974#if (MAX_SKB_FRAGS > 16)
2975 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2976#elif (MAX_SKB_FRAGS > 8)
2977 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2978#elif (MAX_SKB_FRAGS > 4)
2979 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2980#else
2981 rscctrl |= IXGBE_RSCCTL_MAXDESC_1;
2982#endif
2983 } else {
2984 if (rx_buf_len < IXGBE_RXBUFFER_4096)
2985 rscctrl |= IXGBE_RSCCTL_MAXDESC_16;
2986 else if (rx_buf_len < IXGBE_RXBUFFER_8192)
2987 rscctrl |= IXGBE_RSCCTL_MAXDESC_8;
2988 else
2989 rscctrl |= IXGBE_RSCCTL_MAXDESC_4;
2990 }
Alexander Duyck73670962010-08-19 13:38:34 +00002991 IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(reg_idx), rscctrl);
Nelson, Shannonbb5a9ad2009-09-18 09:46:27 +00002992}
2993
Alexander Duyck9e10e042010-08-19 13:40:06 +00002994/**
2995 * ixgbe_set_uta - Set unicast filter table address
2996 * @adapter: board private structure
2997 *
2998 * The unicast table address is a register array of 32-bit registers.
2999 * The table is meant to be used in a way similar to how the MTA is used
3000 * however due to certain limitations in the hardware it is necessary to
3001 * set all the hash bits to 1 and use the VMOLR ROPE bit as a promiscuous
3002 * enable bit to allow vlan tag stripping when promiscuous mode is enabled
3003 **/
3004static void ixgbe_set_uta(struct ixgbe_adapter *adapter)
3005{
3006 struct ixgbe_hw *hw = &adapter->hw;
3007 int i;
3008
3009 /* The UTA table only exists on 82599 hardware and newer */
3010 if (hw->mac.type < ixgbe_mac_82599EB)
3011 return;
3012
3013 /* we only need to do this if VMDq is enabled */
3014 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3015 return;
3016
3017 for (i = 0; i < 128; i++)
3018 IXGBE_WRITE_REG(hw, IXGBE_UTA(i), ~0);
3019}
3020
3021#define IXGBE_MAX_RX_DESC_POLL 10
3022static void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter,
3023 struct ixgbe_ring *ring)
3024{
3025 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003026 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3027 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003028 u8 reg_idx = ring->reg_idx;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003029
3030 /* RXDCTL.EN will return 0 on 82598 if link is down, so skip it */
3031 if (hw->mac.type == ixgbe_mac_82598EB &&
3032 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3033 return;
3034
3035 do {
Don Skidmore032b4322011-03-18 09:32:53 +00003036 usleep_range(1000, 2000);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003037 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3038 } while (--wait_loop && !(rxdctl & IXGBE_RXDCTL_ENABLE));
3039
3040 if (!wait_loop) {
3041 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not set within "
3042 "the polling period\n", reg_idx);
3043 }
3044}
3045
Yi Zou2d39d572011-01-06 14:29:56 +00003046void ixgbe_disable_rx_queue(struct ixgbe_adapter *adapter,
3047 struct ixgbe_ring *ring)
3048{
3049 struct ixgbe_hw *hw = &adapter->hw;
3050 int wait_loop = IXGBE_MAX_RX_DESC_POLL;
3051 u32 rxdctl;
3052 u8 reg_idx = ring->reg_idx;
3053
3054 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3055 rxdctl &= ~IXGBE_RXDCTL_ENABLE;
3056
3057 /* write value back with RXDCTL.ENABLE bit cleared */
3058 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3059
3060 if (hw->mac.type == ixgbe_mac_82598EB &&
3061 !(IXGBE_READ_REG(hw, IXGBE_LINKS) & IXGBE_LINKS_UP))
3062 return;
3063
3064 /* the hardware may take up to 100us to really disable the rx queue */
3065 do {
3066 udelay(10);
3067 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
3068 } while (--wait_loop && (rxdctl & IXGBE_RXDCTL_ENABLE));
3069
3070 if (!wait_loop) {
3071 e_err(drv, "RXDCTL.ENABLE on Rx queue %d not cleared within "
3072 "the polling period\n", reg_idx);
3073 }
3074}
3075
Alexander Duyck84418e32010-08-19 13:40:54 +00003076void ixgbe_configure_rx_ring(struct ixgbe_adapter *adapter,
3077 struct ixgbe_ring *ring)
Alexander Duyckacd37172010-08-19 13:36:05 +00003078{
3079 struct ixgbe_hw *hw = &adapter->hw;
3080 u64 rdba = ring->dma;
Alexander Duyck9e10e042010-08-19 13:40:06 +00003081 u32 rxdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08003082 u8 reg_idx = ring->reg_idx;
Alexander Duyckacd37172010-08-19 13:36:05 +00003083
Alexander Duyck9e10e042010-08-19 13:40:06 +00003084 /* disable queue to avoid issues while updating state */
3085 rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(reg_idx));
Yi Zou2d39d572011-01-06 14:29:56 +00003086 ixgbe_disable_rx_queue(adapter, ring);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003087
Alexander Duyckacd37172010-08-19 13:36:05 +00003088 IXGBE_WRITE_REG(hw, IXGBE_RDBAL(reg_idx), (rdba & DMA_BIT_MASK(32)));
3089 IXGBE_WRITE_REG(hw, IXGBE_RDBAH(reg_idx), (rdba >> 32));
3090 IXGBE_WRITE_REG(hw, IXGBE_RDLEN(reg_idx),
3091 ring->count * sizeof(union ixgbe_adv_rx_desc));
3092 IXGBE_WRITE_REG(hw, IXGBE_RDH(reg_idx), 0);
3093 IXGBE_WRITE_REG(hw, IXGBE_RDT(reg_idx), 0);
Alexander Duyck84ea2592010-11-16 19:26:49 -08003094 ring->tail = hw->hw_addr + IXGBE_RDT(reg_idx);
Alexander Duyck9e10e042010-08-19 13:40:06 +00003095
3096 ixgbe_configure_srrctl(adapter, ring);
3097 ixgbe_configure_rscctl(adapter, ring);
3098
Greg Rosee9f98072011-01-26 01:06:07 +00003099 /* If operating in IOV mode set RLPML for X540 */
3100 if ((adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) &&
3101 hw->mac.type == ixgbe_mac_X540) {
3102 rxdctl &= ~IXGBE_RXDCTL_RLPMLMASK;
3103 rxdctl |= ((ring->netdev->mtu + ETH_HLEN +
3104 ETH_FCS_LEN + VLAN_HLEN) | IXGBE_RXDCTL_RLPML_EN);
3105 }
3106
Alexander Duyck9e10e042010-08-19 13:40:06 +00003107 if (hw->mac.type == ixgbe_mac_82598EB) {
3108 /*
3109 * enable cache line friendly hardware writes:
3110 * PTHRESH=32 descriptors (half the internal cache),
3111 * this also removes ugly rx_no_buffer_count increment
3112 * HTHRESH=4 descriptors (to minimize latency on fetch)
3113 * WTHRESH=8 burst writeback up to two cache lines
3114 */
3115 rxdctl &= ~0x3FFFFF;
3116 rxdctl |= 0x080420;
3117 }
3118
3119 /* enable receive descriptor ring */
3120 rxdctl |= IXGBE_RXDCTL_ENABLE;
3121 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(reg_idx), rxdctl);
3122
3123 ixgbe_rx_desc_queue_enable(adapter, ring);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08003124 ixgbe_alloc_rx_buffers(ring, IXGBE_DESC_UNUSED(ring));
Alexander Duyckacd37172010-08-19 13:36:05 +00003125}
3126
Alexander Duyck48654522010-08-19 13:36:27 +00003127static void ixgbe_setup_psrtype(struct ixgbe_adapter *adapter)
3128{
3129 struct ixgbe_hw *hw = &adapter->hw;
3130 int p;
3131
3132 /* PSRTYPE must be initialized in non 82598 adapters */
3133 u32 psrtype = IXGBE_PSRTYPE_TCPHDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003134 IXGBE_PSRTYPE_UDPHDR |
3135 IXGBE_PSRTYPE_IPV4HDR |
Alexander Duyck48654522010-08-19 13:36:27 +00003136 IXGBE_PSRTYPE_L2HDR |
Joe Perchese8e9f692010-09-07 21:34:53 +00003137 IXGBE_PSRTYPE_IPV6HDR;
Alexander Duyck48654522010-08-19 13:36:27 +00003138
3139 if (hw->mac.type == ixgbe_mac_82598EB)
3140 return;
3141
3142 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED)
3143 psrtype |= (adapter->num_rx_queues_per_pool << 29);
3144
3145 for (p = 0; p < adapter->num_rx_pools; p++)
3146 IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(adapter->num_vfs + p),
3147 psrtype);
3148}
3149
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003150static void ixgbe_configure_virtualization(struct ixgbe_adapter *adapter)
3151{
3152 struct ixgbe_hw *hw = &adapter->hw;
3153 u32 gcr_ext;
3154 u32 vt_reg_bits;
3155 u32 reg_offset, vf_shift;
3156 u32 vmdctl;
3157
3158 if (!(adapter->flags & IXGBE_FLAG_SRIOV_ENABLED))
3159 return;
3160
3161 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL);
3162 vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN | IXGBE_VT_CTL_REPLEN;
3163 vt_reg_bits |= (adapter->num_vfs << IXGBE_VT_CTL_POOL_SHIFT);
3164 IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits);
3165
3166 vf_shift = adapter->num_vfs % 32;
3167 reg_offset = (adapter->num_vfs > 32) ? 1 : 0;
3168
3169 /* Enable only the PF's pool for Tx/Rx */
3170 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift));
3171 IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset ^ 1), 0);
3172 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift));
3173 IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset ^ 1), 0);
3174 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
3175
3176 /* Map PF MAC address in RAR Entry 0 to first pool following VFs */
3177 hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs);
3178
3179 /*
3180 * Set up VF register offsets for selected VT Mode,
3181 * i.e. 32 or 64 VFs for SR-IOV
3182 */
3183 gcr_ext = IXGBE_READ_REG(hw, IXGBE_GCR_EXT);
3184 gcr_ext |= IXGBE_GCR_EXT_MSIX_EN;
3185 gcr_ext |= IXGBE_GCR_EXT_VT_MODE_64;
3186 IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr_ext);
3187
3188 /* enable Tx loopback for VF/PF communication */
3189 IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN);
Greg Rosea985b6c32010-11-18 03:02:52 +00003190 /* Enable MAC Anti-Spoofing */
Greg Rosea1cbb152011-05-13 01:33:48 +00003191 hw->mac.ops.set_mac_anti_spoofing(hw,
3192 (adapter->antispoofing_enabled =
3193 (adapter->num_vfs != 0)),
Greg Rosea985b6c32010-11-18 03:02:52 +00003194 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003195}
3196
Alexander Duyck477de6e2010-08-19 13:38:11 +00003197static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003198{
Auke Kok9a799d72007-09-15 14:07:45 -07003199 struct ixgbe_hw *hw = &adapter->hw;
3200 struct net_device *netdev = adapter->netdev;
3201 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003202 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003203 struct ixgbe_ring *rx_ring;
3204 int i;
3205 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003206
Auke Kok9a799d72007-09-15 14:07:45 -07003207 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003208 /* On by default */
3209 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3210
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003211 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003212 if (adapter->num_vfs)
3213 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3214
3215 /* Disable packet split due to 82599 erratum #45 */
3216 if (hw->mac.type == ixgbe_mac_82599EB)
3217 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003218
3219 /* Set the RX buffer length according to the mode */
3220 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003221 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003222 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003223 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003224 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003225 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003226 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003227 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3228 }
3229
3230#ifdef IXGBE_FCOE
3231 /* adjust max frame to be able to do baby jumbo for FCoE */
3232 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3233 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3234 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3235
3236#endif /* IXGBE_FCOE */
3237 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3238 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3239 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3240 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3241
3242 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003243 }
3244
Auke Kok9a799d72007-09-15 14:07:45 -07003245 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003246 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3247 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003248 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3249
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003250 /*
3251 * Setup the HW Rx Head and Tail Descriptor Pointers and
3252 * the Base and Length of the Rx Descriptor Ring
3253 */
Auke Kok9a799d72007-09-15 14:07:45 -07003254 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003255 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003256 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003257
Yi Zou6e455b892009-08-06 13:05:44 +00003258 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003259 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003260 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003261 clear_ring_ps_enabled(rx_ring);
3262
3263 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3264 set_ring_rsc_enabled(rx_ring);
3265 else
3266 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003267
Yi Zou63f39bd2009-05-17 12:34:35 +00003268#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003269 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003270 struct ixgbe_ring_feature *f;
3271 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003272 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003273 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003274 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3275 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003276 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003277 } else if (!ring_is_rsc_enabled(rx_ring) &&
3278 !ring_is_ps_enabled(rx_ring)) {
3279 rx_ring->rx_buf_len =
3280 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003281 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003282 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003283#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003284 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003285}
3286
Alexander Duyck73670962010-08-19 13:38:34 +00003287static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3288{
3289 struct ixgbe_hw *hw = &adapter->hw;
3290 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3291
3292 switch (hw->mac.type) {
3293 case ixgbe_mac_82598EB:
3294 /*
3295 * For VMDq support of different descriptor types or
3296 * buffer sizes through the use of multiple SRRCTL
3297 * registers, RDRXCTL.MVMEN must be set to 1
3298 *
3299 * also, the manual doesn't mention it clearly but DCA hints
3300 * will only use queue 0's tags unless this bit is set. Side
3301 * effects of setting this bit are only that SRRCTL must be
3302 * fully programmed [0..15]
3303 */
3304 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3305 break;
3306 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003307 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003308 /* Disable RSC for ACK packets */
3309 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3310 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3311 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3312 /* hardware requires some bits to be set by default */
3313 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3314 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3315 break;
3316 default:
3317 /* We should do nothing since we don't know this hardware */
3318 return;
3319 }
3320
3321 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3322}
3323
Alexander Duyck477de6e2010-08-19 13:38:11 +00003324/**
3325 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3326 * @adapter: board private structure
3327 *
3328 * Configure the Rx unit of the MAC after a reset.
3329 **/
3330static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3331{
3332 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003333 int i;
3334 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003335
3336 /* disable receives while setting up the descriptors */
3337 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3338 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3339
3340 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003341 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003342
Alexander Duyck9e10e042010-08-19 13:40:06 +00003343 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003344 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003345
Alexander Duyck9e10e042010-08-19 13:40:06 +00003346 ixgbe_set_uta(adapter);
3347
Alexander Duyck477de6e2010-08-19 13:38:11 +00003348 /* set_rx_buffer_len must be called before ring initialization */
3349 ixgbe_set_rx_buffer_len(adapter);
3350
3351 /*
3352 * Setup the HW Rx Head and Tail Descriptor Pointers and
3353 * the Base and Length of the Rx Descriptor Ring
3354 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003355 for (i = 0; i < adapter->num_rx_queues; i++)
3356 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003357
Alexander Duyck9e10e042010-08-19 13:40:06 +00003358 /* disable drop enable for 82598 parts */
3359 if (hw->mac.type == ixgbe_mac_82598EB)
3360 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3361
3362 /* enable all receives */
3363 rxctrl |= IXGBE_RXCTRL_RXEN;
3364 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003365}
3366
Auke Kok9a799d72007-09-15 14:07:45 -07003367static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3368{
3369 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003370 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003371 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003372
3373 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003374 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003375 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003376}
3377
3378static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3379{
3380 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003381 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003382 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003383
Auke Kok9a799d72007-09-15 14:07:45 -07003384 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003385 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003386 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003387}
3388
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003389/**
3390 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3391 * @adapter: driver data
3392 */
3393static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3394{
3395 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003396 u32 vlnctrl;
3397
3398 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3399 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3400 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3401}
3402
3403/**
3404 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3405 * @adapter: driver data
3406 */
3407static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3408{
3409 struct ixgbe_hw *hw = &adapter->hw;
3410 u32 vlnctrl;
3411
3412 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3413 vlnctrl |= IXGBE_VLNCTRL_VFE;
3414 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3415 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3416}
3417
3418/**
3419 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3420 * @adapter: driver data
3421 */
3422static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3423{
3424 struct ixgbe_hw *hw = &adapter->hw;
3425 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003426 int i, j;
3427
3428 switch (hw->mac.type) {
3429 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003430 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3431 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003432 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3433 break;
3434 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003435 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003436 for (i = 0; i < adapter->num_rx_queues; i++) {
3437 j = adapter->rx_ring[i]->reg_idx;
3438 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3439 vlnctrl &= ~IXGBE_RXDCTL_VME;
3440 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3441 }
3442 break;
3443 default:
3444 break;
3445 }
3446}
3447
3448/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003449 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003450 * @adapter: driver data
3451 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003452static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003453{
3454 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003455 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003456 int i, j;
3457
3458 switch (hw->mac.type) {
3459 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003460 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3461 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003462 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3463 break;
3464 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003465 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003466 for (i = 0; i < adapter->num_rx_queues; i++) {
3467 j = adapter->rx_ring[i]->reg_idx;
3468 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3469 vlnctrl |= IXGBE_RXDCTL_VME;
3470 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3471 }
3472 break;
3473 default:
3474 break;
3475 }
3476}
3477
Auke Kok9a799d72007-09-15 14:07:45 -07003478static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3479{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003480 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003481
Jesse Grossf62bbb52010-10-20 13:56:10 +00003482 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3483
3484 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3485 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003486}
3487
3488/**
Alexander Duyck28500622010-06-15 09:25:48 +00003489 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3490 * @netdev: network interface device structure
3491 *
3492 * Writes unicast address list to the RAR table.
3493 * Returns: -ENOMEM on failure/insufficient address space
3494 * 0 on no addresses written
3495 * X on writing X addresses to the RAR table
3496 **/
3497static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3498{
3499 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3500 struct ixgbe_hw *hw = &adapter->hw;
3501 unsigned int vfn = adapter->num_vfs;
Greg Rosea1cbb152011-05-13 01:33:48 +00003502 unsigned int rar_entries = IXGBE_MAX_PF_MACVLANS;
Alexander Duyck28500622010-06-15 09:25:48 +00003503 int count = 0;
3504
3505 /* return ENOMEM indicating insufficient memory for addresses */
3506 if (netdev_uc_count(netdev) > rar_entries)
3507 return -ENOMEM;
3508
3509 if (!netdev_uc_empty(netdev) && rar_entries) {
3510 struct netdev_hw_addr *ha;
3511 /* return error if we do not support writing to RAR table */
3512 if (!hw->mac.ops.set_rar)
3513 return -ENOMEM;
3514
3515 netdev_for_each_uc_addr(ha, netdev) {
3516 if (!rar_entries)
3517 break;
3518 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3519 vfn, IXGBE_RAH_AV);
3520 count++;
3521 }
3522 }
3523 /* write the addresses in reverse order to avoid write combining */
3524 for (; rar_entries > 0 ; rar_entries--)
3525 hw->mac.ops.clear_rar(hw, rar_entries);
3526
3527 return count;
3528}
3529
3530/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003531 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003532 * @netdev: network interface device structure
3533 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003534 * The set_rx_method entry point is called whenever the unicast/multicast
3535 * address list or the network interface flags are updated. This routine is
3536 * responsible for configuring the hardware for proper unicast, multicast and
3537 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003538 **/
Greg Rose7f870472010-01-09 02:25:29 +00003539void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003540{
3541 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3542 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003543 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3544 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003545
3546 /* Check for Promiscuous and All Multicast modes */
3547
3548 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3549
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003550 /* set all bits that we expect to always be set */
3551 fctrl |= IXGBE_FCTRL_BAM;
3552 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3553 fctrl |= IXGBE_FCTRL_PMCF;
3554
Alexander Duyck28500622010-06-15 09:25:48 +00003555 /* clear the bits we are changing the status of */
3556 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3557
Auke Kok9a799d72007-09-15 14:07:45 -07003558 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003559 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003560 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003561 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003562 /* don't hardware filter vlans in promisc mode */
3563 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003564 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003565 if (netdev->flags & IFF_ALLMULTI) {
3566 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003567 vmolr |= IXGBE_VMOLR_MPE;
3568 } else {
3569 /*
3570 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003571 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003572 * that we can at least receive multicast traffic
3573 */
3574 hw->mac.ops.update_mc_addr_list(hw, netdev);
3575 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003576 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003577 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003578 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003579 /*
3580 * Write addresses to available RAR registers, if there is not
3581 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003582 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003583 */
3584 count = ixgbe_write_uc_addr_list(netdev);
3585 if (count < 0) {
3586 fctrl |= IXGBE_FCTRL_UPE;
3587 vmolr |= IXGBE_VMOLR_ROPE;
3588 }
3589 }
3590
3591 if (adapter->num_vfs) {
3592 ixgbe_restore_vf_multicasts(adapter);
3593 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3594 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3595 IXGBE_VMOLR_ROPE);
3596 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003597 }
3598
3599 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003600
3601 if (netdev->features & NETIF_F_HW_VLAN_RX)
3602 ixgbe_vlan_strip_enable(adapter);
3603 else
3604 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003605}
3606
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003607static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3608{
3609 int q_idx;
3610 struct ixgbe_q_vector *q_vector;
3611 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3612
3613 /* legacy and MSI only use one vector */
3614 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3615 q_vectors = 1;
3616
3617 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003618 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003619 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003620 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003621 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3622 if (!q_vector->rxr_count || !q_vector->txr_count) {
3623 if (q_vector->txr_count == 1)
3624 napi->poll = &ixgbe_clean_txonly;
3625 else if (q_vector->rxr_count == 1)
3626 napi->poll = &ixgbe_clean_rxonly;
3627 }
3628 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003629
3630 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003631 }
3632}
3633
3634static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3635{
3636 int q_idx;
3637 struct ixgbe_q_vector *q_vector;
3638 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3639
3640 /* legacy and MSI only use one vector */
3641 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3642 q_vectors = 1;
3643
3644 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003645 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003646 napi_disable(&q_vector->napi);
3647 }
3648}
3649
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003650#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003651/*
3652 * ixgbe_configure_dcb - Configure DCB hardware
3653 * @adapter: ixgbe adapter struct
3654 *
3655 * This is called by the driver on open to configure the DCB hardware.
3656 * This is also called by the gennetlink interface when reconfiguring
3657 * the DCB state.
3658 */
3659static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3660{
3661 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003662 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003663
Alexander Duyck67ebd792010-08-19 13:34:04 +00003664 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3665 if (hw->mac.type == ixgbe_mac_82598EB)
3666 netif_set_gso_max_size(adapter->netdev, 65536);
3667 return;
3668 }
3669
3670 if (hw->mac.type == ixgbe_mac_82598EB)
3671 netif_set_gso_max_size(adapter->netdev, 32768);
3672
Alexander Duyck2f90b862008-11-20 20:52:10 -08003673
Alexander Duyck2f90b862008-11-20 20:52:10 -08003674 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003675 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003676
Alexander Duyck2f90b862008-11-20 20:52:10 -08003677 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003678
3679 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003680 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3681#ifdef CONFIG_FCOE
3682 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3683 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3684#endif
3685 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3686 DCB_TX_CONFIG);
3687 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3688 DCB_RX_CONFIG);
3689 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3690 } else {
3691 struct net_device *dev = adapter->netdev;
3692
3693 if (adapter->ixgbe_ieee_ets)
3694 dev->dcbnl_ops->ieee_setets(dev,
3695 adapter->ixgbe_ieee_ets);
3696 if (adapter->ixgbe_ieee_pfc)
3697 dev->dcbnl_ops->ieee_setpfc(dev,
3698 adapter->ixgbe_ieee_pfc);
3699 }
John Fastabend8187cd42011-02-23 05:58:08 +00003700
3701 /* Enable RSS Hash per TC */
3702 if (hw->mac.type != ixgbe_mac_82598EB) {
3703 int i;
3704 u32 reg = 0;
3705
3706 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3707 u8 msb = 0;
3708 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3709
3710 while (cnt >>= 1)
3711 msb++;
3712
3713 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3714 }
3715 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3716 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003717}
3718
3719#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003720static void ixgbe_configure(struct ixgbe_adapter *adapter)
3721{
3722 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003723 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003724 int i;
3725
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003726#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003727 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003728#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003729
Jesse Grossf62bbb52010-10-20 13:56:10 +00003730 ixgbe_set_rx_mode(netdev);
3731 ixgbe_restore_vlan(adapter);
3732
Yi Zoueacd73f2009-05-13 13:11:06 +00003733#ifdef IXGBE_FCOE
3734 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3735 ixgbe_configure_fcoe(adapter);
3736
3737#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003738 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3739 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003740 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003741 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003742 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3743 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3744 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3745 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003746 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003747
Auke Kok9a799d72007-09-15 14:07:45 -07003748 ixgbe_configure_tx(adapter);
3749 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003750}
3751
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003752static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3753{
3754 switch (hw->phy.type) {
3755 case ixgbe_phy_sfp_avago:
3756 case ixgbe_phy_sfp_ftl:
3757 case ixgbe_phy_sfp_intel:
3758 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003759 case ixgbe_phy_sfp_passive_tyco:
3760 case ixgbe_phy_sfp_passive_unknown:
3761 case ixgbe_phy_sfp_active_unknown:
3762 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003763 return true;
3764 default:
3765 return false;
3766 }
3767}
3768
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003769/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003770 * ixgbe_sfp_link_config - set up SFP+ link
3771 * @adapter: pointer to private adapter struct
3772 **/
3773static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3774{
3775 struct ixgbe_hw *hw = &adapter->hw;
3776
3777 if (hw->phy.multispeed_fiber) {
3778 /*
3779 * In multispeed fiber setups, the device may not have
3780 * had a physical connection when the driver loaded.
3781 * If that's the case, the initial link configuration
3782 * couldn't get the MAC into 10G or 1G mode, so we'll
3783 * never have a link status change interrupt fire.
3784 * We need to try and force an autonegotiation
3785 * session, then bring up link.
3786 */
Andy Gospodarek4c7e6042011-02-17 01:13:13 -08003787 if (hw->mac.ops.setup_sfp)
3788 hw->mac.ops.setup_sfp(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003789 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
3790 schedule_work(&adapter->multispeed_fiber_task);
3791 } else {
3792 /*
3793 * Direct Attach Cu and non-multispeed fiber modules
3794 * still need to be configured properly prior to
3795 * attempting link.
3796 */
3797 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
3798 schedule_work(&adapter->sfp_config_module_task);
3799 }
3800}
3801
3802/**
3803 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003804 * @hw: pointer to private hardware struct
3805 *
3806 * Returns 0 on success, negative on failure
3807 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003808static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003809{
3810 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003811 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003812 u32 ret = IXGBE_ERR_LINK_SETUP;
3813
3814 if (hw->mac.ops.check_link)
3815 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3816
3817 if (ret)
3818 goto link_cfg_out;
3819
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003820 autoneg = hw->phy.autoneg_advertised;
3821 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003822 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3823 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003824 if (ret)
3825 goto link_cfg_out;
3826
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003827 if (hw->mac.ops.setup_link)
3828 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003829link_cfg_out:
3830 return ret;
3831}
3832
Alexander Duycka34bcff2010-08-19 13:39:20 +00003833static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003834{
Auke Kok9a799d72007-09-15 14:07:45 -07003835 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003836 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003837
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003838 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003839 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3840 IXGBE_GPIE_OCD;
3841 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003842 /*
3843 * use EIAM to auto-mask when MSI-X interrupt is asserted
3844 * this saves a register write for every interrupt
3845 */
3846 switch (hw->mac.type) {
3847 case ixgbe_mac_82598EB:
3848 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3849 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003850 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003851 case ixgbe_mac_X540:
3852 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003853 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3854 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3855 break;
3856 }
3857 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003858 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3859 * specifically only auto mask tx and rx interrupts */
3860 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003861 }
3862
Alexander Duycka34bcff2010-08-19 13:39:20 +00003863 /* XXX: to interrupt immediately for EICS writes, enable this */
3864 /* gpie |= IXGBE_GPIE_EIMEN; */
3865
3866 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3867 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3868 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003869 }
3870
Alexander Duycka34bcff2010-08-19 13:39:20 +00003871 /* Enable fan failure interrupt */
3872 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003873 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003874
Don Skidmore2698b202011-04-13 07:01:52 +00003875 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003876 gpie |= IXGBE_SDP1_GPIEN;
3877 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003878 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003879
3880 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3881}
3882
3883static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3884{
3885 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003886 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003887 u32 ctrl_ext;
3888
3889 ixgbe_get_hw_control(adapter);
3890 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003891
Auke Kok9a799d72007-09-15 14:07:45 -07003892 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3893 ixgbe_configure_msix(adapter);
3894 else
3895 ixgbe_configure_msi_and_legacy(adapter);
3896
Don Skidmorec6ecf392010-12-03 03:31:51 +00003897 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3898 if (hw->mac.ops.enable_tx_laser &&
3899 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003900 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003901 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003902 hw->mac.ops.enable_tx_laser(hw);
3903
Auke Kok9a799d72007-09-15 14:07:45 -07003904 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003905 ixgbe_napi_enable_all(adapter);
3906
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003907 if (ixgbe_is_sfp(hw)) {
3908 ixgbe_sfp_link_config(adapter);
3909 } else {
3910 err = ixgbe_non_sfp_link_config(hw);
3911 if (err)
3912 e_err(probe, "link_config FAILED %d\n", err);
3913 }
3914
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003915 /* clear any pending interrupts, may auto mask */
3916 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003917 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003918
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003919 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003920 * If this adapter has a fan, check to see if we had a failure
3921 * before we enabled the interrupt.
3922 */
3923 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3924 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3925 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003926 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003927 }
3928
3929 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003930 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00003931 * arrived before interrupts were enabled but after probe. Such
3932 * devices wouldn't have their type identified yet. We need to
3933 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003934 * If we're not hot-pluggable SFP+, we just need to configure link
3935 * and bring it up.
3936 */
Emil Tantilov21cc5b42011-02-12 10:52:07 +00003937 if (hw->phy.type == ixgbe_phy_none)
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003938 schedule_work(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003939
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003940 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003941 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003942
Auke Kok9a799d72007-09-15 14:07:45 -07003943 /* bring the link up in the watchdog, this could race with our first
3944 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003945 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3946 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07003947 mod_timer(&adapter->watchdog_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003948
3949 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3950 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3951 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3952 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3953
Auke Kok9a799d72007-09-15 14:07:45 -07003954 return 0;
3955}
3956
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003957void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3958{
3959 WARN_ON(in_interrupt());
3960 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
3988 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003989 switch (err) {
3990 case 0:
3991 case IXGBE_ERR_SFP_NOT_PRESENT:
3992 break;
3993 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003994 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003995 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003996 case IXGBE_ERR_EEPROM_VERSION:
3997 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003998 e_dev_warn("This device is a pre-production adapter/LOM. "
3999 "Please be aware there may be issuesassociated with "
4000 "your hardware. If you are experiencing problems "
4001 "please contact your Intel or hardware "
4002 "representative who provided you with this "
4003 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004004 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004005 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004006 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004007 }
Auke Kok9a799d72007-09-15 14:07:45 -07004008
4009 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004010 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4011 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004012}
4013
Auke Kok9a799d72007-09-15 14:07:45 -07004014/**
4015 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004016 * @rx_ring: ring to free buffers from
4017 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004018static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004019{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004020 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004021 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004022 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004023
Alexander Duyck84418e32010-08-19 13:40:54 +00004024 /* ring already cleared, nothing to do */
4025 if (!rx_ring->rx_buffer_info)
4026 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004027
Alexander Duyck84418e32010-08-19 13:40:54 +00004028 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004029 for (i = 0; i < rx_ring->count; i++) {
4030 struct ixgbe_rx_buffer *rx_buffer_info;
4031
4032 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4033 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004034 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004035 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004036 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004037 rx_buffer_info->dma = 0;
4038 }
4039 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004040 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004041 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004042 do {
4043 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004044 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004045 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004046 IXGBE_RSC_CB(this)->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);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004049 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004050 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004051 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004052 skb = skb->prev;
4053 dev_kfree_skb(this);
4054 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004055 }
4056 if (!rx_buffer_info->page)
4057 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004058 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004059 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004060 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004061 rx_buffer_info->page_dma = 0;
4062 }
Auke Kok9a799d72007-09-15 14:07:45 -07004063 put_page(rx_buffer_info->page);
4064 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004065 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004066 }
4067
4068 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4069 memset(rx_ring->rx_buffer_info, 0, size);
4070
4071 /* Zero out the descriptor ring */
4072 memset(rx_ring->desc, 0, rx_ring->size);
4073
4074 rx_ring->next_to_clean = 0;
4075 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004076}
4077
4078/**
4079 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004080 * @tx_ring: ring to be cleaned
4081 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004082static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004083{
4084 struct ixgbe_tx_buffer *tx_buffer_info;
4085 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004086 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004087
Alexander Duyck84418e32010-08-19 13:40:54 +00004088 /* ring already cleared, nothing to do */
4089 if (!tx_ring->tx_buffer_info)
4090 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004091
Alexander Duyck84418e32010-08-19 13:40:54 +00004092 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004093 for (i = 0; i < tx_ring->count; i++) {
4094 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004095 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004096 }
4097
4098 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4099 memset(tx_ring->tx_buffer_info, 0, size);
4100
4101 /* Zero out the descriptor ring */
4102 memset(tx_ring->desc, 0, tx_ring->size);
4103
4104 tx_ring->next_to_use = 0;
4105 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004106}
4107
4108/**
Auke Kok9a799d72007-09-15 14:07:45 -07004109 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4110 * @adapter: board private structure
4111 **/
4112static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4113{
4114 int i;
4115
4116 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004117 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004118}
4119
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004120/**
4121 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4122 * @adapter: board private structure
4123 **/
4124static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4125{
4126 int i;
4127
4128 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004129 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004130}
4131
Auke Kok9a799d72007-09-15 14:07:45 -07004132void ixgbe_down(struct ixgbe_adapter *adapter)
4133{
4134 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004135 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004136 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004137 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004138 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004139 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004140
4141 /* signal that we are down to the interrupt handler */
4142 set_bit(__IXGBE_DOWN, &adapter->state);
4143
Greg Rose767081a2010-01-22 22:46:40 +00004144 /* disable receive for all VFs and wait one second */
4145 if (adapter->num_vfs) {
Greg Rose767081a2010-01-22 22:46:40 +00004146 /* ping all the active vfs to let them know we are going down */
4147 ixgbe_ping_all_vfs(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004148
Greg Rose767081a2010-01-22 22:46:40 +00004149 /* Disable all VFTE/VFRE TX/RX */
4150 ixgbe_disable_tx_rx(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004151
4152 /* Mark all the VFs as inactive */
4153 for (i = 0 ; i < adapter->num_vfs; i++)
4154 adapter->vfinfo[i].clear_to_send = 0;
Greg Rose767081a2010-01-22 22:46:40 +00004155 }
4156
Auke Kok9a799d72007-09-15 14:07:45 -07004157 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004158 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4159 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004160
Yi Zou2d39d572011-01-06 14:29:56 +00004161 /* disable all enabled rx queues */
4162 for (i = 0; i < adapter->num_rx_queues; i++)
4163 /* this call also flushes the previous write */
4164 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4165
Don Skidmore032b4322011-03-18 09:32:53 +00004166 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004167
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004168 netif_tx_stop_all_queues(netdev);
4169
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004170 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4171 del_timer_sync(&adapter->sfp_timer);
Auke Kok9a799d72007-09-15 14:07:45 -07004172 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004173 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004174
John Fastabendc0dfb902010-04-27 02:13:39 +00004175 netif_carrier_off(netdev);
4176 netif_tx_disable(netdev);
4177
4178 ixgbe_irq_disable(adapter);
4179
4180 ixgbe_napi_disable_all(adapter);
4181
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004182 /* Cleanup the affinity_hint CPU mask memory and callback */
4183 for (i = 0; i < num_q_vectors; i++) {
4184 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4185 /* clear the affinity_mask in the IRQ descriptor */
4186 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4187 /* release the CPU mask memory */
4188 free_cpumask_var(q_vector->affinity_mask);
4189 }
4190
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004191 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4192 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
4193 cancel_work_sync(&adapter->fdir_reinit_task);
4194
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004195 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
4196 cancel_work_sync(&adapter->check_overtemp_task);
4197
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004198 /* disable transmits in the hardware now that interrupts are off */
4199 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004200 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4201 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
4202 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00004203 (txdctl & ~IXGBE_TXDCTL_ENABLE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004204 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00004205 /* Disable the Tx DMA engine on 82599 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004206 switch (hw->mac.type) {
4207 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004208 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004209 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004210 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4211 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004212 break;
4213 default:
4214 break;
4215 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004216
Paul Larson6f4a0e42008-06-24 17:00:56 -07004217 if (!pci_channel_offline(adapter->pdev))
4218 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004219
4220 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4221 if (hw->mac.ops.disable_tx_laser &&
4222 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004223 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004224 (hw->mac.type == ixgbe_mac_82599EB))))
4225 hw->mac.ops.disable_tx_laser(hw);
4226
Auke Kok9a799d72007-09-15 14:07:45 -07004227 ixgbe_clean_all_tx_rings(adapter);
4228 ixgbe_clean_all_rx_rings(adapter);
4229
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004230#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004231 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004232 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004233#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004234}
4235
Auke Kok9a799d72007-09-15 14:07:45 -07004236/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004237 * ixgbe_poll - NAPI Rx polling callback
4238 * @napi: structure for representing this polling device
4239 * @budget: how many packets driver is allowed to clean
4240 *
4241 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004242 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004243static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004244{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004245 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004246 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004247 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004248 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004249
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004250#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004251 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4252 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004253#endif
4254
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004255 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4256 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004257
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004258 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004259 work_done = budget;
4260
David S. Miller53e52c72008-01-07 21:06:12 -08004261 /* If budget not fully consumed, exit the polling mode */
4262 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004263 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004264 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004265 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004266 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004267 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004268 }
Auke Kok9a799d72007-09-15 14:07:45 -07004269 return work_done;
4270}
4271
4272/**
4273 * ixgbe_tx_timeout - Respond to a Tx Hang
4274 * @netdev: network interface device structure
4275 **/
4276static void ixgbe_tx_timeout(struct net_device *netdev)
4277{
4278 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4279
John Fastabendc84d3242010-11-16 19:27:12 -08004280 adapter->tx_timeout_count++;
4281
Auke Kok9a799d72007-09-15 14:07:45 -07004282 /* Do the reset outside of interrupt context */
4283 schedule_work(&adapter->reset_task);
4284}
4285
4286static void ixgbe_reset_task(struct work_struct *work)
4287{
4288 struct ixgbe_adapter *adapter;
4289 adapter = container_of(work, struct ixgbe_adapter, reset_task);
4290
Alexander Duyck2f90b862008-11-20 20:52:10 -08004291 /* If we're already down or resetting, just bail */
4292 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4293 test_bit(__IXGBE_RESETTING, &adapter->state))
4294 return;
4295
Taku Izumidcd79ae2010-04-27 14:39:53 +00004296 ixgbe_dump(adapter);
4297 netdev_err(adapter->netdev, "Reset adapter\n");
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004298 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004299}
4300
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004301/**
4302 * ixgbe_set_rss_queues: Allocate queues for RSS
4303 * @adapter: board private structure to initialize
4304 *
4305 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4306 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4307 *
4308 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004309static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4310{
4311 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004312 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004313
4314 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004315 f->mask = 0xF;
4316 adapter->num_rx_queues = f->indices;
4317 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004318 ret = true;
4319 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004320 ret = false;
4321 }
4322
4323 return ret;
4324}
4325
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004326/**
4327 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4328 * @adapter: board private structure to initialize
4329 *
4330 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4331 * to the original CPU that initiated the Tx session. This runs in addition
4332 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4333 * Rx load across CPUs using RSS.
4334 *
4335 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004336static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004337{
4338 bool ret = false;
4339 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4340
4341 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4342 f_fdir->mask = 0;
4343
4344 /* Flow Director must have RSS enabled */
4345 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4346 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4347 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4348 adapter->num_tx_queues = f_fdir->indices;
4349 adapter->num_rx_queues = f_fdir->indices;
4350 ret = true;
4351 } else {
4352 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4353 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4354 }
4355 return ret;
4356}
4357
Yi Zou0331a832009-05-17 12:33:52 +00004358#ifdef IXGBE_FCOE
4359/**
4360 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4361 * @adapter: board private structure to initialize
4362 *
4363 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4364 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4365 * rx queues out of the max number of rx queues, instead, it is used as the
4366 * index of the first rx queue used by FCoE.
4367 *
4368 **/
4369static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4370{
Yi Zou0331a832009-05-17 12:33:52 +00004371 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4372
John Fastabende5b64632011-03-08 03:44:52 +00004373 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4374 return false;
4375
4376 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4377#ifdef CONFIG_IXGBE_DCB
4378 int tc;
4379 struct net_device *dev = adapter->netdev;
4380
4381 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4382 f->indices = dev->tc_to_txq[tc].count;
4383 f->mask = dev->tc_to_txq[tc].offset;
4384#endif
4385 } else {
4386 f->indices = min((int)num_online_cpus(), f->indices);
4387
Yi Zou8de8b2e2009-09-03 14:55:50 +00004388 adapter->num_rx_queues = 1;
4389 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004390
Yi Zou0331a832009-05-17 12:33:52 +00004391 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004392 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004393 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4394 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4395 ixgbe_set_fdir_queues(adapter);
4396 else
4397 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004398 }
4399 /* adding FCoE rx rings to the end */
4400 f->mask = adapter->num_rx_queues;
4401 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004402 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004403 }
4404
John Fastabende5b64632011-03-08 03:44:52 +00004405 return true;
4406}
4407#endif /* IXGBE_FCOE */
4408
4409#ifdef CONFIG_IXGBE_DCB
4410static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4411{
4412 bool ret = false;
4413 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4414 int i, q;
4415
4416 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4417 return ret;
4418
4419 f->indices = 0;
4420 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4421 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4422 f->indices += q;
4423 }
4424
4425 f->mask = 0x7 << 3;
4426 adapter->num_rx_queues = f->indices;
4427 adapter->num_tx_queues = f->indices;
4428 ret = true;
4429
4430#ifdef IXGBE_FCOE
4431 /* FCoE enabled queues require special configuration done through
4432 * configure_fcoe() and others. Here we map FCoE indices onto the
4433 * DCB queue pairs allowing FCoE to own configuration later.
4434 */
4435 ixgbe_set_fcoe_queues(adapter);
4436#endif
4437
Yi Zou0331a832009-05-17 12:33:52 +00004438 return ret;
4439}
John Fastabende5b64632011-03-08 03:44:52 +00004440#endif
Yi Zou0331a832009-05-17 12:33:52 +00004441
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004442/**
4443 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4444 * @adapter: board private structure to initialize
4445 *
4446 * IOV doesn't actually use anything, so just NAK the
4447 * request for now and let the other queue routines
4448 * figure out what to do.
4449 */
4450static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4451{
4452 return false;
4453}
4454
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004455/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004456 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004457 * @adapter: board private structure to initialize
4458 *
4459 * This is the top level queue allocation routine. The order here is very
4460 * important, starting with the "most" number of features turned on at once,
4461 * and ending with the smallest set of features. This way large combinations
4462 * can be allocated if they're turned on, and smaller combinations are the
4463 * fallthrough conditions.
4464 *
4465 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004466static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004467{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004468 /* Start with base case */
4469 adapter->num_rx_queues = 1;
4470 adapter->num_tx_queues = 1;
4471 adapter->num_rx_pools = adapter->num_rx_queues;
4472 adapter->num_rx_queues_per_pool = 1;
4473
4474 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004475 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004476
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004477#ifdef CONFIG_IXGBE_DCB
4478 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004479 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004480
4481#endif
John Fastabende5b64632011-03-08 03:44:52 +00004482#ifdef IXGBE_FCOE
4483 if (ixgbe_set_fcoe_queues(adapter))
4484 goto done;
4485
4486#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004487 if (ixgbe_set_fdir_queues(adapter))
4488 goto done;
4489
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004490 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004491 goto done;
4492
4493 /* fallback to base case */
4494 adapter->num_rx_queues = 1;
4495 adapter->num_tx_queues = 1;
4496
4497done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004498 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004499 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004500 return netif_set_real_num_rx_queues(adapter->netdev,
4501 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004502}
4503
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004504static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004505 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004506{
4507 int err, vector_threshold;
4508
4509 /* We'll want at least 3 (vector_threshold):
4510 * 1) TxQ[0] Cleanup
4511 * 2) RxQ[0] Cleanup
4512 * 3) Other (Link Status Change, etc.)
4513 * 4) TCP Timer (optional)
4514 */
4515 vector_threshold = MIN_MSIX_COUNT;
4516
4517 /* The more we get, the more we will assign to Tx/Rx Cleanup
4518 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4519 * Right now, we simply care about how many we'll get; we'll
4520 * set them up later while requesting irq's.
4521 */
4522 while (vectors >= vector_threshold) {
4523 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004524 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004525 if (!err) /* Success in acquiring all requested vectors. */
4526 break;
4527 else if (err < 0)
4528 vectors = 0; /* Nasty failure, quit now */
4529 else /* err == number of vectors we should try again with */
4530 vectors = err;
4531 }
4532
4533 if (vectors < vector_threshold) {
4534 /* Can't allocate enough MSI-X interrupts? Oh well.
4535 * This just means we'll go with either a single MSI
4536 * vector or fall back to legacy interrupts.
4537 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004538 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4539 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004540 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4541 kfree(adapter->msix_entries);
4542 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004543 } else {
4544 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004545 /*
4546 * Adjust for only the vectors we'll use, which is minimum
4547 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4548 * vectors we were allocated.
4549 */
4550 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004551 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004552 }
4553}
4554
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004555/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004556 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004557 * @adapter: board private structure to initialize
4558 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004559 * Cache the descriptor ring offsets for RSS to the assigned rings.
4560 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004561 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004562static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004563{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004564 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004565
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004566 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4567 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004568
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004569 for (i = 0; i < adapter->num_rx_queues; i++)
4570 adapter->rx_ring[i]->reg_idx = i;
4571 for (i = 0; i < adapter->num_tx_queues; i++)
4572 adapter->tx_ring[i]->reg_idx = i;
4573
4574 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004575}
4576
4577#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004578
4579/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004580static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4581 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004582{
4583 struct net_device *dev = adapter->netdev;
4584 struct ixgbe_hw *hw = &adapter->hw;
4585 u8 num_tcs = netdev_get_num_tc(dev);
4586
4587 *tx = 0;
4588 *rx = 0;
4589
4590 switch (hw->mac.type) {
4591 case ixgbe_mac_82598EB:
4592 *tx = tc << 3;
4593 *rx = tc << 2;
4594 break;
4595 case ixgbe_mac_82599EB:
4596 case ixgbe_mac_X540:
4597 if (num_tcs == 8) {
4598 if (tc < 3) {
4599 *tx = tc << 5;
4600 *rx = tc << 4;
4601 } else if (tc < 5) {
4602 *tx = ((tc + 2) << 4);
4603 *rx = tc << 4;
4604 } else if (tc < num_tcs) {
4605 *tx = ((tc + 8) << 3);
4606 *rx = tc << 4;
4607 }
4608 } else if (num_tcs == 4) {
4609 *rx = tc << 5;
4610 switch (tc) {
4611 case 0:
4612 *tx = 0;
4613 break;
4614 case 1:
4615 *tx = 64;
4616 break;
4617 case 2:
4618 *tx = 96;
4619 break;
4620 case 3:
4621 *tx = 112;
4622 break;
4623 default:
4624 break;
4625 }
4626 }
4627 break;
4628 default:
4629 break;
4630 }
4631}
4632
4633#define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4634
4635/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4636 * classes.
4637 *
4638 * @netdev: net device to configure
4639 * @tc: number of traffic classes to enable
4640 */
4641int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4642{
4643 int i;
4644 unsigned int q, offset = 0;
4645
4646 if (!tc) {
4647 netdev_reset_tc(dev);
4648 } else {
John Fastabend24095aa2011-02-23 05:58:03 +00004649 struct ixgbe_adapter *adapter = netdev_priv(dev);
4650
4651 /* Hardware supports up to 8 traffic classes */
4652 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
John Fastabende5b64632011-03-08 03:44:52 +00004653 return -EINVAL;
4654
4655 /* Partition Tx queues evenly amongst traffic classes */
4656 for (i = 0; i < tc; i++) {
4657 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4658 netdev_set_prio_tc_map(dev, i, i);
4659 netdev_set_tc_queue(dev, i, q, offset);
4660 offset += q;
4661 }
John Fastabend24095aa2011-02-23 05:58:03 +00004662
4663 /* This enables multiple traffic class support in the hardware
4664 * which defaults to strict priority transmission by default.
4665 * If traffic classes are already enabled perhaps through DCB
4666 * code path then existing configuration will be used.
4667 */
4668 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4669 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4670 struct ieee_ets ets = {
4671 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4672 };
4673 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4674
4675 dev->dcbnl_ops->setdcbx(dev, mode);
4676 dev->dcbnl_ops->ieee_setets(dev, &ets);
4677 }
John Fastabende5b64632011-03-08 03:44:52 +00004678 }
4679 return 0;
4680}
4681
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004682/**
4683 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4684 * @adapter: board private structure to initialize
4685 *
4686 * Cache the descriptor ring offsets for DCB to the assigned rings.
4687 *
4688 **/
4689static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4690{
John Fastabende5b64632011-03-08 03:44:52 +00004691 struct net_device *dev = adapter->netdev;
4692 int i, j, k;
4693 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004694
Alexander Duyckbd508172010-11-16 19:27:03 -08004695 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4696 return false;
4697
John Fastabende5b64632011-03-08 03:44:52 +00004698 for (i = 0, k = 0; i < num_tcs; i++) {
4699 unsigned int tx_s, rx_s;
4700 u16 count = dev->tc_to_txq[i].count;
4701
4702 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4703 for (j = 0; j < count; j++, k++) {
4704 adapter->tx_ring[k]->reg_idx = tx_s + j;
4705 adapter->rx_ring[k]->reg_idx = rx_s + j;
4706 adapter->tx_ring[k]->dcb_tc = i;
4707 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004708 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004709 }
John Fastabende5b64632011-03-08 03:44:52 +00004710
4711 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004712}
4713#endif
4714
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004715/**
4716 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4717 * @adapter: board private structure to initialize
4718 *
4719 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4720 *
4721 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004722static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004723{
4724 int i;
4725 bool ret = false;
4726
4727 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4728 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4729 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4730 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004731 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004732 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004733 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004734 ret = true;
4735 }
4736
4737 return ret;
4738}
4739
Yi Zou0331a832009-05-17 12:33:52 +00004740#ifdef IXGBE_FCOE
4741/**
4742 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4743 * @adapter: board private structure to initialize
4744 *
4745 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4746 *
4747 */
4748static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4749{
Yi Zou0331a832009-05-17 12:33:52 +00004750 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004751 int i;
4752 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004753
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004754 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4755 return false;
4756
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004757 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4758 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4759 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4760 ixgbe_cache_ring_fdir(adapter);
4761 else
4762 ixgbe_cache_ring_rss(adapter);
4763
4764 fcoe_rx_i = f->mask;
4765 fcoe_tx_i = f->mask;
4766 }
4767 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4768 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4769 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4770 }
4771 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004772}
4773
4774#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004775/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004776 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4777 * @adapter: board private structure to initialize
4778 *
4779 * SR-IOV doesn't use any descriptor rings but changes the default if
4780 * no other mapping is used.
4781 *
4782 */
4783static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4784{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004785 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4786 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004787 if (adapter->num_vfs)
4788 return true;
4789 else
4790 return false;
4791}
4792
4793/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004794 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4795 * @adapter: board private structure to initialize
4796 *
4797 * Once we know the feature-set enabled for the device, we'll cache
4798 * the register offset the descriptor ring is assigned to.
4799 *
4800 * Note, the order the various feature calls is important. It must start with
4801 * the "most" features enabled at the same time, then trickle down to the
4802 * least amount of features turned on at once.
4803 **/
4804static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4805{
4806 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004807 adapter->rx_ring[0]->reg_idx = 0;
4808 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004809
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004810 if (ixgbe_cache_ring_sriov(adapter))
4811 return;
4812
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004813#ifdef CONFIG_IXGBE_DCB
4814 if (ixgbe_cache_ring_dcb(adapter))
4815 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004816#endif
John Fastabende5b64632011-03-08 03:44:52 +00004817
4818#ifdef IXGBE_FCOE
4819 if (ixgbe_cache_ring_fcoe(adapter))
4820 return;
4821#endif /* IXGBE_FCOE */
4822
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004823 if (ixgbe_cache_ring_fdir(adapter))
4824 return;
4825
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004826 if (ixgbe_cache_ring_rss(adapter))
4827 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004828}
4829
Auke Kok9a799d72007-09-15 14:07:45 -07004830/**
4831 * ixgbe_alloc_queues - Allocate memory for all rings
4832 * @adapter: board private structure to initialize
4833 *
4834 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004835 * number of queues at compile-time. The polling_netdev array is
4836 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004837 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004838static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004839{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004841
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004842 if (nid < 0 || !node_online(nid))
4843 nid = first_online_node;
4844
4845 for (; tx < adapter->num_tx_queues; tx++) {
4846 struct ixgbe_ring *ring;
4847
4848 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004849 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004850 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004851 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004852 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004853 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004854 ring->queue_index = tx;
4855 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004856 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004857 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004858
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004859 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004860 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004861
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004862 for (; rx < adapter->num_rx_queues; rx++) {
4863 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004864
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004865 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004866 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004867 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004868 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004869 goto err_allocation;
4870 ring->count = adapter->rx_ring_count;
4871 ring->queue_index = rx;
4872 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004873 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004874 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004875
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004876 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004877 }
4878
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004879 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004880
4881 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004882
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004883err_allocation:
4884 while (tx)
4885 kfree(adapter->tx_ring[--tx]);
4886
4887 while (rx)
4888 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004889 return -ENOMEM;
4890}
4891
4892/**
4893 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4894 * @adapter: board private structure to initialize
4895 *
4896 * Attempt to configure the interrupts using the best available
4897 * capabilities of the hardware and the kernel.
4898 **/
Al Virofeea6a52008-11-27 15:34:07 -08004899static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004900{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004901 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004902 int err = 0;
4903 int vector, v_budget;
4904
4905 /*
4906 * It's easy to be greedy for MSI-X vectors, but it really
4907 * doesn't do us much good if we have a lot more vectors
4908 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004909 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004910 */
4911 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004912 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004913
4914 /*
4915 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004916 * hw.mac->max_msix_vectors vectors. With features
4917 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4918 * descriptor queues supported by our device. Thus, we cap it off in
4919 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004920 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004921 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004922
4923 /* A failure in MSI-X entry allocation isn't fatal, but it does
4924 * mean we disable MSI-X capabilities of the adapter. */
4925 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004926 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004927 if (adapter->msix_entries) {
4928 for (vector = 0; vector < v_budget; vector++)
4929 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004930
Alexander Duyck7a921c92009-05-06 10:43:28 +00004931 ixgbe_acquire_msix_vectors(adapter, v_budget);
4932
4933 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4934 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004935 }
David S. Miller26d27842010-05-03 15:18:22 -07004936
Alexander Duyck7a921c92009-05-06 10:43:28 +00004937 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4938 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004939 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4940 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4941 e_err(probe,
4942 "Flow Director is not supported while multiple "
4943 "queues are disabled. Disabling Flow Director\n");
4944 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004945 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4946 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4947 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004948 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4949 ixgbe_disable_sriov(adapter);
4950
Ben Hutchings847f53f2010-09-27 08:28:56 +00004951 err = ixgbe_set_num_queues(adapter);
4952 if (err)
4953 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004954
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004955 err = pci_enable_msi(adapter->pdev);
4956 if (!err) {
4957 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4958 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004959 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4960 "Unable to allocate MSI interrupt, "
4961 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004962 /* reset err */
4963 err = 0;
4964 }
4965
4966out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004967 return err;
4968}
4969
Alexander Duyck7a921c92009-05-06 10:43:28 +00004970/**
4971 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4972 * @adapter: board private structure to initialize
4973 *
4974 * We allocate one q_vector per queue interrupt. If allocation fails we
4975 * return -ENOMEM.
4976 **/
4977static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4978{
4979 int q_idx, num_q_vectors;
4980 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004981 int (*poll)(struct napi_struct *, int);
4982
4983 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4984 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004985 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004986 } else {
4987 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004988 poll = &ixgbe_poll;
4989 }
4990
4991 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004992 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004993 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004994 if (!q_vector)
4995 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004996 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004997 if (!q_vector)
4998 goto err_out;
4999 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005000 if (q_vector->txr_count && !q_vector->rxr_count)
5001 q_vector->eitr = adapter->tx_eitr_param;
5002 else
5003 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005004 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005005 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005006 adapter->q_vector[q_idx] = q_vector;
5007 }
5008
5009 return 0;
5010
5011err_out:
5012 while (q_idx) {
5013 q_idx--;
5014 q_vector = adapter->q_vector[q_idx];
5015 netif_napi_del(&q_vector->napi);
5016 kfree(q_vector);
5017 adapter->q_vector[q_idx] = NULL;
5018 }
5019 return -ENOMEM;
5020}
5021
5022/**
5023 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5024 * @adapter: board private structure to initialize
5025 *
5026 * This function frees the memory allocated to the q_vectors. In addition if
5027 * NAPI is enabled it will delete any references to the NAPI struct prior
5028 * to freeing the q_vector.
5029 **/
5030static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5031{
5032 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005033
Alexander Duyck91281fd2009-06-04 16:00:27 +00005034 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005035 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005036 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005037 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005038
5039 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5040 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005042 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005043 kfree(q_vector);
5044 }
5045}
5046
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005047static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005048{
5049 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5050 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5051 pci_disable_msix(adapter->pdev);
5052 kfree(adapter->msix_entries);
5053 adapter->msix_entries = NULL;
5054 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5055 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5056 pci_disable_msi(adapter->pdev);
5057 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005058}
5059
5060/**
5061 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5062 * @adapter: board private structure to initialize
5063 *
5064 * We determine which interrupt scheme to use based on...
5065 * - Kernel support (MSI, MSI-X)
5066 * - which can be user-defined (via MODULE_PARAM)
5067 * - Hardware queue count (num_*_queues)
5068 * - defined by miscellaneous hardware support/features (RSS, etc.)
5069 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005070int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005071{
5072 int err;
5073
5074 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005075 err = ixgbe_set_num_queues(adapter);
5076 if (err)
5077 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005078
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005079 err = ixgbe_set_interrupt_capability(adapter);
5080 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005081 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005082 goto err_set_interrupt;
5083 }
5084
Alexander Duyck7a921c92009-05-06 10:43:28 +00005085 err = ixgbe_alloc_q_vectors(adapter);
5086 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005087 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005088 goto err_alloc_q_vectors;
5089 }
5090
5091 err = ixgbe_alloc_queues(adapter);
5092 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005093 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005094 goto err_alloc_queues;
5095 }
5096
Emil Tantilov849c4542010-06-03 16:53:41 +00005097 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005098 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5099 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005100
5101 set_bit(__IXGBE_DOWN, &adapter->state);
5102
5103 return 0;
5104
Alexander Duyck7a921c92009-05-06 10:43:28 +00005105err_alloc_queues:
5106 ixgbe_free_q_vectors(adapter);
5107err_alloc_q_vectors:
5108 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005109err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005110 return err;
5111}
5112
Eric Dumazet1a515022010-11-16 19:26:42 -08005113static void ring_free_rcu(struct rcu_head *head)
5114{
5115 kfree(container_of(head, struct ixgbe_ring, rcu));
5116}
5117
Alexander Duyck7a921c92009-05-06 10:43:28 +00005118/**
5119 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5120 * @adapter: board private structure to clear interrupt scheme on
5121 *
5122 * We go through and clear interrupt specific resources and reset the structure
5123 * to pre-load conditions
5124 **/
5125void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5126{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005127 int i;
5128
5129 for (i = 0; i < adapter->num_tx_queues; i++) {
5130 kfree(adapter->tx_ring[i]);
5131 adapter->tx_ring[i] = NULL;
5132 }
5133 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005134 struct ixgbe_ring *ring = adapter->rx_ring[i];
5135
5136 /* ixgbe_get_stats64() might access this ring, we must wait
5137 * a grace period before freeing it.
5138 */
5139 call_rcu(&ring->rcu, ring_free_rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005140 adapter->rx_ring[i] = NULL;
5141 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005142
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005143 adapter->num_tx_queues = 0;
5144 adapter->num_rx_queues = 0;
5145
Alexander Duyck7a921c92009-05-06 10:43:28 +00005146 ixgbe_free_q_vectors(adapter);
5147 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005148}
5149
5150/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08005151 * ixgbe_sfp_timer - worker thread to find a missing module
5152 * @data: pointer to our adapter struct
5153 **/
5154static void ixgbe_sfp_timer(unsigned long data)
5155{
5156 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5157
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005158 /*
5159 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08005160 * delays that sfp+ detection requires
5161 */
5162 schedule_work(&adapter->sfp_task);
5163}
5164
5165/**
5166 * ixgbe_sfp_task - worker thread to find a missing module
5167 * @work: pointer to work_struct containing our data
5168 **/
5169static void ixgbe_sfp_task(struct work_struct *work)
5170{
5171 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00005172 struct ixgbe_adapter,
5173 sfp_task);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005174 struct ixgbe_hw *hw = &adapter->hw;
5175
5176 if ((hw->phy.type == ixgbe_phy_nl) &&
5177 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
5178 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00005179 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08005180 goto reschedule;
5181 ret = hw->phy.ops.reset(hw);
5182 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005183 e_dev_err("failed to initialize because an unsupported "
5184 "SFP+ module type was detected.\n");
5185 e_dev_err("Reload the driver after installing a "
5186 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08005187 unregister_netdev(adapter->netdev);
5188 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005189 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005190 }
5191 /* don't need this routine any more */
5192 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5193 }
5194 return;
5195reschedule:
5196 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
5197 mod_timer(&adapter->sfp_timer,
Joe Perchese8e9f692010-09-07 21:34:53 +00005198 round_jiffies(jiffies + (2 * HZ)));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005199}
5200
5201/**
Auke Kok9a799d72007-09-15 14:07:45 -07005202 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5203 * @adapter: board private structure to initialize
5204 *
5205 * ixgbe_sw_init initializes the Adapter private data structure.
5206 * Fields are initialized based on PCI device information and
5207 * OS network device settings (MTU size).
5208 **/
5209static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5210{
5211 struct ixgbe_hw *hw = &adapter->hw;
5212 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005213 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005214 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005215#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005216 int j;
5217 struct tc_configuration *tc;
5218#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005219 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005220
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005221 /* PCI config space info */
5222
5223 hw->vendor_id = pdev->vendor;
5224 hw->device_id = pdev->device;
5225 hw->revision_id = pdev->revision;
5226 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5227 hw->subsystem_device_id = pdev->subsystem_device;
5228
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005229 /* Set capability flags */
5230 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5231 adapter->ring_feature[RING_F_RSS].indices = rss;
5232 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005233 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005234 switch (hw->mac.type) {
5235 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005236 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5237 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005238 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005239 break;
5240 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005241 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005242 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005243 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5244 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005245 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5246 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005247 /* n-tuple support exists, always init our spinlock */
5248 spin_lock_init(&adapter->fdir_perfect_lock);
5249 /* Flow Director hash filters enabled */
5250 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5251 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005252 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005253 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005254 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005255#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005256 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5257 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5258 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005259#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005260 /* Default traffic class to use for FCoE */
5261 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005262 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005263#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005264#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005265 break;
5266 default:
5267 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005268 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005269
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005270#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005271 /* Configure DCB traffic classes */
5272 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5273 tc = &adapter->dcb_cfg.tc_config[j];
5274 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5275 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5276 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5277 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5278 tc->dcb_pfc = pfc_disabled;
5279 }
5280 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5281 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5282 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005283 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005284 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005285 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005286 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005287 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005288
5289#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005290
5291 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005292 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005293 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005294#ifdef CONFIG_DCB
5295 adapter->last_lfc_mode = hw->fc.current_mode;
5296#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005297 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5298 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005299 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5300 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005301 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005302
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005303 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005304 adapter->rx_itr_setting = 1;
5305 adapter->rx_eitr_param = 20000;
5306 adapter->tx_itr_setting = 1;
5307 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005308
5309 /* set defaults for eitr in MegaBytes */
5310 adapter->eitr_low = 10;
5311 adapter->eitr_high = 20;
5312
5313 /* set default ring sizes */
5314 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5315 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5316
Auke Kok9a799d72007-09-15 14:07:45 -07005317 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005318 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005319 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005320 return -EIO;
5321 }
5322
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005323 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005324 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5325
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005326 /* get assigned NUMA node */
5327 adapter->node = dev_to_node(&pdev->dev);
5328
Auke Kok9a799d72007-09-15 14:07:45 -07005329 set_bit(__IXGBE_DOWN, &adapter->state);
5330
5331 return 0;
5332}
5333
5334/**
5335 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005336 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005337 *
5338 * Return 0 on success, negative on failure
5339 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005340int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005341{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005342 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005343 int size;
5344
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005345 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005346 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005347 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005348 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005349 if (!tx_ring->tx_buffer_info)
5350 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005351
5352 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005353 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005354 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005355
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005356 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005357 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005358 if (!tx_ring->desc)
5359 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005360
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005361 tx_ring->next_to_use = 0;
5362 tx_ring->next_to_clean = 0;
5363 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005364 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005365
5366err:
5367 vfree(tx_ring->tx_buffer_info);
5368 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005369 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005370 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005371}
5372
5373/**
Alexander Duyck69888672008-09-11 20:05:39 -07005374 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5375 * @adapter: board private structure
5376 *
5377 * If this function returns with an error, then it's possible one or
5378 * more of the rings is populated (while the rest are not). It is the
5379 * callers duty to clean those orphaned rings.
5380 *
5381 * Return 0 on success, negative on failure
5382 **/
5383static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5384{
5385 int i, err = 0;
5386
5387 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005388 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005389 if (!err)
5390 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005391 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005392 break;
5393 }
5394
5395 return err;
5396}
5397
5398/**
Auke Kok9a799d72007-09-15 14:07:45 -07005399 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005400 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005401 *
5402 * Returns 0 on success, negative on failure
5403 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005404int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005405{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005406 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005407 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005408
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005409 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005410 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005411 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005412 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005413 if (!rx_ring->rx_buffer_info)
5414 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005415
Auke Kok9a799d72007-09-15 14:07:45 -07005416 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005417 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5418 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005419
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005420 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005421 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005422
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005423 if (!rx_ring->desc)
5424 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005425
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005426 rx_ring->next_to_clean = 0;
5427 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005428
5429 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005430err:
5431 vfree(rx_ring->rx_buffer_info);
5432 rx_ring->rx_buffer_info = NULL;
5433 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005434 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005435}
5436
5437/**
Alexander Duyck69888672008-09-11 20:05:39 -07005438 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5439 * @adapter: board private structure
5440 *
5441 * If this function returns with an error, then it's possible one or
5442 * more of the rings is populated (while the rest are not). It is the
5443 * callers duty to clean those orphaned rings.
5444 *
5445 * Return 0 on success, negative on failure
5446 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005447static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5448{
5449 int i, err = 0;
5450
5451 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005452 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005453 if (!err)
5454 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005455 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005456 break;
5457 }
5458
5459 return err;
5460}
5461
5462/**
Auke Kok9a799d72007-09-15 14:07:45 -07005463 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005464 * @tx_ring: Tx descriptor ring for a specific queue
5465 *
5466 * Free all transmit software resources
5467 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005468void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005469{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005470 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005471
5472 vfree(tx_ring->tx_buffer_info);
5473 tx_ring->tx_buffer_info = NULL;
5474
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005475 /* if not set, then don't free */
5476 if (!tx_ring->desc)
5477 return;
5478
5479 dma_free_coherent(tx_ring->dev, tx_ring->size,
5480 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005481
5482 tx_ring->desc = NULL;
5483}
5484
5485/**
5486 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5487 * @adapter: board private structure
5488 *
5489 * Free all transmit software resources
5490 **/
5491static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5492{
5493 int i;
5494
5495 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005496 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005497 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005498}
5499
5500/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005501 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005502 * @rx_ring: ring to clean the resources from
5503 *
5504 * Free all receive software resources
5505 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005506void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005507{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005508 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005509
5510 vfree(rx_ring->rx_buffer_info);
5511 rx_ring->rx_buffer_info = NULL;
5512
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005513 /* if not set, then don't free */
5514 if (!rx_ring->desc)
5515 return;
5516
5517 dma_free_coherent(rx_ring->dev, rx_ring->size,
5518 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005519
5520 rx_ring->desc = NULL;
5521}
5522
5523/**
5524 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5525 * @adapter: board private structure
5526 *
5527 * Free all receive software resources
5528 **/
5529static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5530{
5531 int i;
5532
5533 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005534 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005535 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005536}
5537
5538/**
Auke Kok9a799d72007-09-15 14:07:45 -07005539 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5540 * @netdev: network interface device structure
5541 * @new_mtu: new value for maximum frame size
5542 *
5543 * Returns 0 on success, negative on failure
5544 **/
5545static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5546{
5547 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005548 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005549 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5550
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005551 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005552 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5553 hw->mac.type != ixgbe_mac_X540) {
5554 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5555 return -EINVAL;
5556 } else {
5557 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5558 return -EINVAL;
5559 }
Auke Kok9a799d72007-09-15 14:07:45 -07005560
Emil Tantilov396e7992010-07-01 20:05:12 +00005561 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005562 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005563 netdev->mtu = new_mtu;
5564
John Fastabend16b61be2010-11-16 19:26:44 -08005565 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5566 hw->fc.low_water = FC_LOW_WATER(max_frame);
5567
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005568 if (netif_running(netdev))
5569 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005570
5571 return 0;
5572}
5573
5574/**
5575 * ixgbe_open - Called when a network interface is made active
5576 * @netdev: network interface device structure
5577 *
5578 * Returns 0 on success, negative value on failure
5579 *
5580 * The open entry point is called when a network interface is made
5581 * active by the system (IFF_UP). At this point all resources needed
5582 * for transmit and receive operations are allocated, the interrupt
5583 * handler is registered with the OS, the watchdog timer is started,
5584 * and the stack is notified that the interface is ready.
5585 **/
5586static int ixgbe_open(struct net_device *netdev)
5587{
5588 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5589 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005590
Auke Kok4bebfaa2008-02-11 09:26:01 -08005591 /* disallow open during test */
5592 if (test_bit(__IXGBE_TESTING, &adapter->state))
5593 return -EBUSY;
5594
Jesse Brandeburg54386462009-04-17 20:44:27 +00005595 netif_carrier_off(netdev);
5596
Auke Kok9a799d72007-09-15 14:07:45 -07005597 /* allocate transmit descriptors */
5598 err = ixgbe_setup_all_tx_resources(adapter);
5599 if (err)
5600 goto err_setup_tx;
5601
Auke Kok9a799d72007-09-15 14:07:45 -07005602 /* allocate receive descriptors */
5603 err = ixgbe_setup_all_rx_resources(adapter);
5604 if (err)
5605 goto err_setup_rx;
5606
5607 ixgbe_configure(adapter);
5608
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005609 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005610 if (err)
5611 goto err_req_irq;
5612
Auke Kok9a799d72007-09-15 14:07:45 -07005613 err = ixgbe_up_complete(adapter);
5614 if (err)
5615 goto err_up;
5616
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005617 netif_tx_start_all_queues(netdev);
5618
Auke Kok9a799d72007-09-15 14:07:45 -07005619 return 0;
5620
5621err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005622 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005623 ixgbe_free_irq(adapter);
5624err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005625err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005626 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005627err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005628 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005629 ixgbe_reset(adapter);
5630
5631 return err;
5632}
5633
5634/**
5635 * ixgbe_close - Disables a network interface
5636 * @netdev: network interface device structure
5637 *
5638 * Returns 0, this is not allowed to fail
5639 *
5640 * The close entry point is called when an interface is de-activated
5641 * by the OS. The hardware is still under the drivers control, but
5642 * needs to be disabled. A global MAC reset is issued to stop the
5643 * hardware, and all transmit and receive resources are freed.
5644 **/
5645static int ixgbe_close(struct net_device *netdev)
5646{
5647 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005648
5649 ixgbe_down(adapter);
5650 ixgbe_free_irq(adapter);
5651
5652 ixgbe_free_all_tx_resources(adapter);
5653 ixgbe_free_all_rx_resources(adapter);
5654
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005655 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005656
5657 return 0;
5658}
5659
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005660#ifdef CONFIG_PM
5661static int ixgbe_resume(struct pci_dev *pdev)
5662{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005663 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5664 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005665 u32 err;
5666
5667 pci_set_power_state(pdev, PCI_D0);
5668 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005669 /*
5670 * pci_restore_state clears dev->state_saved so call
5671 * pci_save_state to restore it.
5672 */
5673 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005674
5675 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005676 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005677 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005678 return err;
5679 }
5680 pci_set_master(pdev);
5681
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005682 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005683
5684 err = ixgbe_init_interrupt_scheme(adapter);
5685 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005686 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005687 return err;
5688 }
5689
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005690 ixgbe_reset(adapter);
5691
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005692 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5693
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005694 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005695 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005696 if (err)
5697 return err;
5698 }
5699
5700 netif_device_attach(netdev);
5701
5702 return 0;
5703}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005704#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005705
5706static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005707{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005708 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5709 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005710 struct ixgbe_hw *hw = &adapter->hw;
5711 u32 ctrl, fctrl;
5712 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005713#ifdef CONFIG_PM
5714 int retval = 0;
5715#endif
5716
5717 netif_device_detach(netdev);
5718
5719 if (netif_running(netdev)) {
5720 ixgbe_down(adapter);
5721 ixgbe_free_irq(adapter);
5722 ixgbe_free_all_tx_resources(adapter);
5723 ixgbe_free_all_rx_resources(adapter);
5724 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005725
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005726 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005727#ifdef CONFIG_DCB
5728 kfree(adapter->ixgbe_ieee_pfc);
5729 kfree(adapter->ixgbe_ieee_ets);
5730#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005731
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005732#ifdef CONFIG_PM
5733 retval = pci_save_state(pdev);
5734 if (retval)
5735 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005736
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005737#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005738 if (wufc) {
5739 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005740
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005741 /* turn on all-multi mode if wake on multicast is enabled */
5742 if (wufc & IXGBE_WUFC_MC) {
5743 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5744 fctrl |= IXGBE_FCTRL_MPE;
5745 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5746 }
5747
5748 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5749 ctrl |= IXGBE_CTRL_GIO_DIS;
5750 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5751
5752 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5753 } else {
5754 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5755 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5756 }
5757
Alexander Duyckbd508172010-11-16 19:27:03 -08005758 switch (hw->mac.type) {
5759 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005760 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005761 break;
5762 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005763 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005764 pci_wake_from_d3(pdev, !!wufc);
5765 break;
5766 default:
5767 break;
5768 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005769
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005770 *enable_wake = !!wufc;
5771
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005772 ixgbe_release_hw_control(adapter);
5773
5774 pci_disable_device(pdev);
5775
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005776 return 0;
5777}
5778
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005779#ifdef CONFIG_PM
5780static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5781{
5782 int retval;
5783 bool wake;
5784
5785 retval = __ixgbe_shutdown(pdev, &wake);
5786 if (retval)
5787 return retval;
5788
5789 if (wake) {
5790 pci_prepare_to_sleep(pdev);
5791 } else {
5792 pci_wake_from_d3(pdev, false);
5793 pci_set_power_state(pdev, PCI_D3hot);
5794 }
5795
5796 return 0;
5797}
5798#endif /* CONFIG_PM */
5799
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005800static void ixgbe_shutdown(struct pci_dev *pdev)
5801{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005802 bool wake;
5803
5804 __ixgbe_shutdown(pdev, &wake);
5805
5806 if (system_state == SYSTEM_POWER_OFF) {
5807 pci_wake_from_d3(pdev, wake);
5808 pci_set_power_state(pdev, PCI_D3hot);
5809 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005810}
5811
5812/**
Auke Kok9a799d72007-09-15 14:07:45 -07005813 * ixgbe_update_stats - Update the board statistics counters.
5814 * @adapter: board private structure
5815 **/
5816void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5817{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005818 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005819 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005820 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005821 u64 total_mpc = 0;
5822 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005823 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5824 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5825 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005826
Don Skidmored08935c2010-06-11 13:20:29 +00005827 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5828 test_bit(__IXGBE_RESETTING, &adapter->state))
5829 return;
5830
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005831 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005832 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005833 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005834 for (i = 0; i < 16; i++)
5835 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005836 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005837 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005838 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5839 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005840 }
5841 adapter->rsc_total_count = rsc_count;
5842 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005843 }
5844
Alexander Duyck5b7da512010-11-16 19:26:50 -08005845 for (i = 0; i < adapter->num_rx_queues; i++) {
5846 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5847 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5848 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5849 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5850 bytes += rx_ring->stats.bytes;
5851 packets += rx_ring->stats.packets;
5852 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005853 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005854 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5855 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5856 netdev->stats.rx_bytes = bytes;
5857 netdev->stats.rx_packets = packets;
5858
5859 bytes = 0;
5860 packets = 0;
5861 /* gather some stats to the adapter struct that are per queue */
5862 for (i = 0; i < adapter->num_tx_queues; i++) {
5863 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5864 restart_queue += tx_ring->tx_stats.restart_queue;
5865 tx_busy += tx_ring->tx_stats.tx_busy;
5866 bytes += tx_ring->stats.bytes;
5867 packets += tx_ring->stats.packets;
5868 }
5869 adapter->restart_queue = restart_queue;
5870 adapter->tx_busy = tx_busy;
5871 netdev->stats.tx_bytes = bytes;
5872 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005873
Joe Perches7ca647b2010-09-07 21:35:40 +00005874 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005875 for (i = 0; i < 8; i++) {
5876 /* for packet buffers not used, the register should read 0 */
5877 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5878 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005879 hwstats->mpc[i] += mpc;
5880 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005881 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005882 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5883 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5884 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5885 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5886 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005887 switch (hw->mac.type) {
5888 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005889 hwstats->pxonrxc[i] +=
5890 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005891 break;
5892 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005893 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005894 hwstats->pxonrxc[i] +=
5895 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005896 break;
5897 default:
5898 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005899 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005900 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5901 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005902 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005904 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005905 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005906
John Fastabendc84d3242010-11-16 19:27:12 -08005907 ixgbe_update_xoff_received(adapter);
5908
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005909 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005910 switch (hw->mac.type) {
5911 case ixgbe_mac_82598EB:
5912 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005913 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5914 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5915 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5916 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08005917 case ixgbe_mac_X540:
Emil Tantilov58f6bcf2011-04-21 08:43:43 +00005918 /* OS2BMC stats are X540 only*/
5919 hwstats->o2bgptc += IXGBE_READ_REG(hw, IXGBE_O2BGPTC);
5920 hwstats->o2bspc += IXGBE_READ_REG(hw, IXGBE_O2BSPC);
5921 hwstats->b2ospc += IXGBE_READ_REG(hw, IXGBE_B2OSPC);
5922 hwstats->b2ogprc += IXGBE_READ_REG(hw, IXGBE_B2OGPRC);
5923 case ixgbe_mac_82599EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005925 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005926 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005927 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005928 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005929 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005930 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005931 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5932 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005933#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005934 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5935 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5936 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5937 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5938 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5939 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005940#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005941 break;
5942 default:
5943 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005944 }
Auke Kok9a799d72007-09-15 14:07:45 -07005945 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005946 hwstats->bprc += bprc;
5947 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005948 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005949 hwstats->mprc -= bprc;
5950 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5951 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5952 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5953 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5954 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5955 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5956 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5957 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005958 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005959 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005960 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005961 hwstats->lxofftxc += lxoff;
5962 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5963 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5964 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005965 /*
5966 * 82598 errata - tx of flow control packets is included in tx counters
5967 */
5968 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005969 hwstats->gptc -= xon_off_tot;
5970 hwstats->mptc -= xon_off_tot;
5971 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5972 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5973 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5974 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5975 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5976 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5977 hwstats->ptc64 -= xon_off_tot;
5978 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5979 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5980 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5981 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5982 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5983 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005984
5985 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005986 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005987
5988 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005989 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005990 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005991 netdev->stats.rx_length_errors = hwstats->rlec;
5992 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005993 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005994}
5995
5996/**
5997 * ixgbe_watchdog - Timer Call-back
5998 * @data: pointer to adapter cast into an unsigned long
5999 **/
6000static void ixgbe_watchdog(unsigned long data)
6001{
6002 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006003 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00006004 u64 eics = 0;
6005 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006006
Alexander Duyckfe49f042009-06-04 16:00:09 +00006007 /*
6008 * Do the watchdog outside of interrupt context due to the lovely
6009 * delays that some of the newer hardware requires
6010 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006011
Alexander Duyckfe49f042009-06-04 16:00:09 +00006012 if (test_bit(__IXGBE_DOWN, &adapter->state))
6013 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006014
Alexander Duyckfe49f042009-06-04 16:00:09 +00006015 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6016 /*
6017 * for legacy and MSI interrupts don't set any bits
6018 * that are enabled for EIAM, because this operation
6019 * would set *both* EIMS and EICS for any bit in EIAM
6020 */
6021 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6022 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6023 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006024 }
6025
Alexander Duyckfe49f042009-06-04 16:00:09 +00006026 /* get one bit for every active tx/rx interrupt vector */
6027 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6028 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6029 if (qv->rxr_count || qv->txr_count)
6030 eics |= ((u64)1 << i);
6031 }
6032
6033 /* Cause software interrupt to ensure rx rings are cleaned */
6034 ixgbe_irq_rearm_queues(adapter, eics);
6035
6036watchdog_reschedule:
6037 /* Reset the timer */
6038 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
6039
6040watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006041 schedule_work(&adapter->watchdog_task);
6042}
6043
6044/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006045 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
6046 * @work: pointer to work_struct containing our data
6047 **/
6048static void ixgbe_multispeed_fiber_task(struct work_struct *work)
6049{
6050 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006051 struct ixgbe_adapter,
6052 multispeed_fiber_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006053 struct ixgbe_hw *hw = &adapter->hw;
6054 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006055 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006056
6057 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00006058 autoneg = hw->phy.autoneg_advertised;
6059 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006060 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +00006061 hw->mac.autotry_restart = false;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006062 if (hw->mac.ops.setup_link)
6063 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006064 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6065 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
6066}
6067
6068/**
6069 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
6070 * @work: pointer to work_struct containing our data
6071 **/
6072static void ixgbe_sfp_config_module_task(struct work_struct *work)
6073{
6074 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006075 struct ixgbe_adapter,
6076 sfp_config_module_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006077 struct ixgbe_hw *hw = &adapter->hw;
6078 u32 err;
6079
6080 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006081
6082 /* Time for electrical oscillations to settle down */
6083 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006084 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006085
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006086 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006087 e_dev_err("failed to initialize because an unsupported SFP+ "
6088 "module type was detected.\n");
6089 e_dev_err("Reload the driver after installing a supported "
6090 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006091 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006092 return;
6093 }
Andy Gospodarek4c7e6042011-02-17 01:13:13 -08006094 if (hw->mac.ops.setup_sfp)
6095 hw->mac.ops.setup_sfp(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006096
Tony Breeds8d1c3c02009-04-09 22:29:10 +00006097 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006098 /* This will also work for DA Twinax connections */
6099 schedule_work(&adapter->multispeed_fiber_task);
6100 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
6101}
6102
6103/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006104 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
6105 * @work: pointer to work_struct containing our data
6106 **/
6107static void ixgbe_fdir_reinit_task(struct work_struct *work)
6108{
6109 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006110 struct ixgbe_adapter,
6111 fdir_reinit_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006112 struct ixgbe_hw *hw = &adapter->hw;
6113 int i;
6114
6115 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6116 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006117 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
6118 &(adapter->tx_ring[i]->state));
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006119 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006120 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006121 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006122 }
6123 /* Done FDIR Re-initialization, enable transmits */
6124 netif_tx_start_all_queues(adapter->netdev);
6125}
6126
Greg Rosea985b6c32010-11-18 03:02:52 +00006127static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6128{
6129 u32 ssvpc;
6130
6131 /* Do not perform spoof check for 82598 */
6132 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6133 return;
6134
6135 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6136
6137 /*
6138 * ssvpc register is cleared on read, if zero then no
6139 * spoofed packets in the last interval.
6140 */
6141 if (!ssvpc)
6142 return;
6143
6144 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6145}
6146
John Fastabend10eec952010-02-03 14:23:32 +00006147static DEFINE_MUTEX(ixgbe_watchdog_lock);
6148
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006149/**
Alexander Duyck69888672008-09-11 20:05:39 -07006150 * ixgbe_watchdog_task - worker thread to bring link up
6151 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006152 **/
6153static void ixgbe_watchdog_task(struct work_struct *work)
6154{
6155 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006156 struct ixgbe_adapter,
6157 watchdog_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006158 struct net_device *netdev = adapter->netdev;
6159 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend10eec952010-02-03 14:23:32 +00006160 u32 link_speed;
6161 bool link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006162 int i;
6163 struct ixgbe_ring *tx_ring;
6164 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006165
John Fastabend10eec952010-02-03 14:23:32 +00006166 mutex_lock(&ixgbe_watchdog_lock);
6167
6168 link_up = adapter->link_up;
6169 link_speed = adapter->link_speed;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006170
6171 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
6172 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006173 if (link_up) {
6174#ifdef CONFIG_DCB
6175 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6176 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006177 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006178 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006179 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006180 }
6181#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006182 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006183#endif
6184 }
6185
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006186 if (link_up ||
6187 time_after(jiffies, (adapter->link_check_timeout +
Joe Perchese8e9f692010-09-07 21:34:53 +00006188 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006189 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006190 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006191 }
6192 adapter->link_up = link_up;
6193 adapter->link_speed = link_speed;
6194 }
Auke Kok9a799d72007-09-15 14:07:45 -07006195
6196 if (link_up) {
6197 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006198 bool flow_rx, flow_tx;
6199
Alexander Duyckbd508172010-11-16 19:27:03 -08006200 switch (hw->mac.type) {
6201 case ixgbe_mac_82598EB: {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006202 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6203 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00006204 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6205 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006206 }
Alexander Duyckbd508172010-11-16 19:27:03 -08006207 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006208 case ixgbe_mac_82599EB:
6209 case ixgbe_mac_X540: {
Alexander Duyckbd508172010-11-16 19:27:03 -08006210 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6211 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6212 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6213 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6214 }
6215 break;
6216 default:
6217 flow_tx = false;
6218 flow_rx = false;
6219 break;
6220 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006221
Emil Tantilov396e7992010-07-01 20:05:12 +00006222 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
Jeff Kirshera46e5342008-11-27 00:22:21 -08006223 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
Emil Tantilov849c4542010-06-03 16:53:41 +00006224 "10 Gbps" :
6225 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +00006226 "1 Gbps" :
6227 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6228 "100 Mbps" :
6229 "unknown speed"))),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006230 ((flow_rx && flow_tx) ? "RX/TX" :
Emil Tantilov849c4542010-06-03 16:53:41 +00006231 (flow_rx ? "RX" :
6232 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07006233
6234 netif_carrier_on(netdev);
Lior Levyff4ab202011-03-11 02:03:07 +00006235 ixgbe_check_vf_rate_limit(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006236 } else {
6237 /* Force detection of hung controller */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006238 for (i = 0; i < adapter->num_tx_queues; i++) {
6239 tx_ring = adapter->tx_ring[i];
6240 set_check_for_tx_hang(tx_ring);
6241 }
Auke Kok9a799d72007-09-15 14:07:45 -07006242 }
6243 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006244 adapter->link_up = false;
6245 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006246 if (netif_carrier_ok(netdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00006247 e_info(drv, "NIC Link is Down\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006248 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006249 }
6250 }
6251
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006252 if (!netif_carrier_ok(netdev)) {
6253 for (i = 0; i < adapter->num_tx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006254 tx_ring = adapter->tx_ring[i];
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006255 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6256 some_tx_pending = 1;
6257 break;
6258 }
6259 }
6260
6261 if (some_tx_pending) {
6262 /* We've lost link, so the controller stops DMA,
6263 * but we've got queued Tx work that's never going
6264 * to get done, so reset controller to flush Tx.
6265 * (Do the reset outside of interrupt context).
6266 */
6267 schedule_work(&adapter->reset_task);
6268 }
6269 }
6270
Greg Rosea985b6c32010-11-18 03:02:52 +00006271 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006272 ixgbe_update_stats(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006273 mutex_unlock(&ixgbe_watchdog_lock);
Auke Kok9a799d72007-09-15 14:07:45 -07006274}
6275
Auke Kok9a799d72007-09-15 14:07:45 -07006276static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006277 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006278 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006279{
6280 struct ixgbe_adv_tx_context_desc *context_desc;
6281 unsigned int i;
6282 int err;
6283 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006284 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6285 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006286
6287 if (skb_is_gso(skb)) {
6288 if (skb_header_cloned(skb)) {
6289 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6290 if (err)
6291 return err;
6292 }
6293 l4len = tcp_hdrlen(skb);
6294 *hdr_len += l4len;
6295
Hao Zheng5e09a102010-11-11 13:47:59 +00006296 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006297 struct iphdr *iph = ip_hdr(skb);
6298 iph->tot_len = 0;
6299 iph->check = 0;
6300 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006301 iph->daddr, 0,
6302 IPPROTO_TCP,
6303 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006304 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006305 ipv6_hdr(skb)->payload_len = 0;
6306 tcp_hdr(skb)->check =
6307 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006308 &ipv6_hdr(skb)->daddr,
6309 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006310 }
6311
6312 i = tx_ring->next_to_use;
6313
6314 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006315 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006316
6317 /* VLAN MACLEN IPLEN */
6318 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6319 vlan_macip_lens |=
6320 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6321 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006322 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006323 *hdr_len += skb_network_offset(skb);
6324 vlan_macip_lens |=
6325 (skb_transport_header(skb) - skb_network_header(skb));
6326 *hdr_len +=
6327 (skb_transport_header(skb) - skb_network_header(skb));
6328 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6329 context_desc->seqnum_seed = 0;
6330
6331 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006332 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006333 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006334
Hao Zheng5e09a102010-11-11 13:47:59 +00006335 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006336 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6337 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6338 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6339
6340 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006341 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006342 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6343 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006344 /* use index 1 for TSO */
6345 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006346 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6347
6348 tx_buffer_info->time_stamp = jiffies;
6349 tx_buffer_info->next_to_watch = i;
6350
6351 i++;
6352 if (i == tx_ring->count)
6353 i = 0;
6354 tx_ring->next_to_use = i;
6355
6356 return true;
6357 }
6358 return false;
6359}
6360
Hao Zheng5e09a102010-11-11 13:47:59 +00006361static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6362 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006363{
6364 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006365
6366 switch (protocol) {
6367 case cpu_to_be16(ETH_P_IP):
6368 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6369 switch (ip_hdr(skb)->protocol) {
6370 case IPPROTO_TCP:
6371 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6372 break;
6373 case IPPROTO_SCTP:
6374 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6375 break;
6376 }
6377 break;
6378 case cpu_to_be16(ETH_P_IPV6):
6379 /* XXX what about other V6 headers?? */
6380 switch (ipv6_hdr(skb)->nexthdr) {
6381 case IPPROTO_TCP:
6382 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6383 break;
6384 case IPPROTO_SCTP:
6385 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6386 break;
6387 }
6388 break;
6389 default:
6390 if (unlikely(net_ratelimit()))
6391 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006392 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006393 break;
6394 }
6395
6396 return rtn;
6397}
6398
Auke Kok9a799d72007-09-15 14:07:45 -07006399static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006400 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006401 struct sk_buff *skb, u32 tx_flags,
6402 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006403{
6404 struct ixgbe_adv_tx_context_desc *context_desc;
6405 unsigned int i;
6406 struct ixgbe_tx_buffer *tx_buffer_info;
6407 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6408
6409 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6410 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6411 i = tx_ring->next_to_use;
6412 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006413 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006414
6415 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6416 vlan_macip_lens |=
6417 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6418 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006419 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006420 if (skb->ip_summed == CHECKSUM_PARTIAL)
6421 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006422 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006423
6424 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6425 context_desc->seqnum_seed = 0;
6426
6427 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006428 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006429
Joe Perches7ca647b2010-09-07 21:35:40 +00006430 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006431 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006432
6433 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006434 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006435 context_desc->mss_l4len_idx = 0;
6436
6437 tx_buffer_info->time_stamp = jiffies;
6438 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006439
Auke Kok9a799d72007-09-15 14:07:45 -07006440 i++;
6441 if (i == tx_ring->count)
6442 i = 0;
6443 tx_ring->next_to_use = i;
6444
6445 return true;
6446 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006447
Auke Kok9a799d72007-09-15 14:07:45 -07006448 return false;
6449}
6450
6451static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006452 struct ixgbe_ring *tx_ring,
6453 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006454 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006455{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006456 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006457 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006458 unsigned int len;
6459 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006460 unsigned int offset = 0, size, count = 0, i;
6461 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6462 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006463 unsigned int bytecount = skb->len;
6464 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006465
6466 i = tx_ring->next_to_use;
6467
Yi Zoueacd73f2009-05-13 13:11:06 +00006468 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6469 /* excluding fcoe_crc_eof for FCoE */
6470 total -= sizeof(struct fcoe_crc_eof);
6471
6472 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006473 while (len) {
6474 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6475 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6476
6477 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006478 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006479 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006480 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006481 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006482 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006483 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006484 tx_buffer_info->time_stamp = jiffies;
6485 tx_buffer_info->next_to_watch = i;
6486
6487 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006488 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006489 offset += size;
6490 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006491
6492 if (len) {
6493 i++;
6494 if (i == tx_ring->count)
6495 i = 0;
6496 }
Auke Kok9a799d72007-09-15 14:07:45 -07006497 }
6498
6499 for (f = 0; f < nr_frags; f++) {
6500 struct skb_frag_struct *frag;
6501
6502 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006503 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006504 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006505
6506 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006507 i++;
6508 if (i == tx_ring->count)
6509 i = 0;
6510
Auke Kok9a799d72007-09-15 14:07:45 -07006511 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6512 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6513
6514 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006515 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006516 frag->page,
6517 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006518 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006519 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006520 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006521 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006522 tx_buffer_info->time_stamp = jiffies;
6523 tx_buffer_info->next_to_watch = i;
6524
6525 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006526 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006527 offset += size;
6528 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006529 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006530 if (total == 0)
6531 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006532 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006533
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006534 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6535 gso_segs = skb_shinfo(skb)->gso_segs;
6536#ifdef IXGBE_FCOE
6537 /* adjust for FCoE Sequence Offload */
6538 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6539 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6540 skb_shinfo(skb)->gso_size);
6541#endif /* IXGBE_FCOE */
6542 bytecount += (gso_segs - 1) * hdr_len;
6543
6544 /* multiply data chunks by size of headers */
6545 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6546 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006547 tx_ring->tx_buffer_info[i].skb = skb;
6548 tx_ring->tx_buffer_info[first].next_to_watch = i;
6549
6550 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006551
6552dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006553 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006554
6555 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6556 tx_buffer_info->dma = 0;
6557 tx_buffer_info->time_stamp = 0;
6558 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006559 if (count)
6560 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006561
6562 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006563 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006564 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006565 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006566 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006567 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006568 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006569 }
6570
Anton Blancharde44d38e2010-02-03 13:12:51 +00006571 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006572}
6573
Alexander Duyck84ea2592010-11-16 19:26:49 -08006574static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006575 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006576{
6577 union ixgbe_adv_tx_desc *tx_desc = NULL;
6578 struct ixgbe_tx_buffer *tx_buffer_info;
6579 u32 olinfo_status = 0, cmd_type_len = 0;
6580 unsigned int i;
6581 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6582
6583 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6584
6585 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6586
6587 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6588 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6589
6590 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6591 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6592
6593 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006594 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006595
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006596 /* use index 1 context for tso */
6597 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006598 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6599 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006600 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006601
6602 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6603 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006604 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006605
Yi Zoueacd73f2009-05-13 13:11:06 +00006606 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6607 olinfo_status |= IXGBE_ADVTXD_CC;
6608 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6609 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6610 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6611 }
6612
Auke Kok9a799d72007-09-15 14:07:45 -07006613 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6614
6615 i = tx_ring->next_to_use;
6616 while (count--) {
6617 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006618 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006619 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6620 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006621 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006622 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006623 i++;
6624 if (i == tx_ring->count)
6625 i = 0;
6626 }
6627
6628 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6629
6630 /*
6631 * Force memory writes to complete before letting h/w
6632 * know there are new descriptors to fetch. (Only
6633 * applicable for weak-ordered memory model archs,
6634 * such as IA-64).
6635 */
6636 wmb();
6637
6638 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006639 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006640}
6641
Alexander Duyck69830522011-01-06 14:29:58 +00006642static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6643 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006644{
Alexander Duyck69830522011-01-06 14:29:58 +00006645 struct ixgbe_q_vector *q_vector = ring->q_vector;
6646 union ixgbe_atr_hash_dword input = { .dword = 0 };
6647 union ixgbe_atr_hash_dword common = { .dword = 0 };
6648 union {
6649 unsigned char *network;
6650 struct iphdr *ipv4;
6651 struct ipv6hdr *ipv6;
6652 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006653 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006654 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006655
Alexander Duyck69830522011-01-06 14:29:58 +00006656 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6657 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006658 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006659
Alexander Duyck69830522011-01-06 14:29:58 +00006660 /* do nothing if sampling is disabled */
6661 if (!ring->atr_sample_rate)
6662 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006663
Alexander Duyck69830522011-01-06 14:29:58 +00006664 ring->atr_count++;
6665
6666 /* snag network header to get L4 type and address */
6667 hdr.network = skb_network_header(skb);
6668
6669 /* Currently only IPv4/IPv6 with TCP is supported */
6670 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6671 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6672 (protocol != __constant_htons(ETH_P_IP) ||
6673 hdr.ipv4->protocol != IPPROTO_TCP))
6674 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006675
6676 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006677
Alexander Duyck69830522011-01-06 14:29:58 +00006678 /* skip this packet since the socket is closing */
6679 if (th->fin)
6680 return;
6681
6682 /* sample on all syn packets or once every atr sample count */
6683 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6684 return;
6685
6686 /* reset sample count */
6687 ring->atr_count = 0;
6688
6689 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6690
6691 /*
6692 * src and dst are inverted, think how the receiver sees them
6693 *
6694 * The input is broken into two sections, a non-compressed section
6695 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6696 * is XORed together and stored in the compressed dword.
6697 */
6698 input.formatted.vlan_id = vlan_id;
6699
6700 /*
6701 * since src port and flex bytes occupy the same word XOR them together
6702 * and write the value to source port portion of compressed dword
6703 */
6704 if (vlan_id)
6705 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6706 else
6707 common.port.src ^= th->dest ^ protocol;
6708 common.port.dst ^= th->source;
6709
6710 if (protocol == __constant_htons(ETH_P_IP)) {
6711 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6712 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6713 } else {
6714 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6715 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6716 hdr.ipv6->saddr.s6_addr32[1] ^
6717 hdr.ipv6->saddr.s6_addr32[2] ^
6718 hdr.ipv6->saddr.s6_addr32[3] ^
6719 hdr.ipv6->daddr.s6_addr32[0] ^
6720 hdr.ipv6->daddr.s6_addr32[1] ^
6721 hdr.ipv6->daddr.s6_addr32[2] ^
6722 hdr.ipv6->daddr.s6_addr32[3];
6723 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006724
6725 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006726 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6727 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006728}
6729
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006730static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006731{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006732 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006733 /* Herbert's original patch had:
6734 * smp_mb__after_netif_stop_queue();
6735 * but since that doesn't exist yet, just open code it. */
6736 smp_mb();
6737
6738 /* We need to check again in a case another CPU has just
6739 * made room available. */
6740 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6741 return -EBUSY;
6742
6743 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006744 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006745 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006746 return 0;
6747}
6748
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006749static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006750{
6751 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6752 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006753 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006754}
6755
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006756static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6757{
6758 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006759 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006760#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006761 __be16 protocol;
6762
6763 protocol = vlan_get_protocol(skb);
6764
John Fastabende5b64632011-03-08 03:44:52 +00006765 if (((protocol == htons(ETH_P_FCOE)) ||
6766 (protocol == htons(ETH_P_FIP))) &&
6767 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6768 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6769 txq += adapter->ring_feature[RING_F_FCOE].mask;
6770 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006771 }
6772#endif
6773
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006774 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6775 while (unlikely(txq >= dev->real_num_tx_queues))
6776 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006777 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006778 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006779
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006780 return skb_tx_hash(dev, skb);
6781}
6782
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006783netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006784 struct ixgbe_adapter *adapter,
6785 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006786{
Auke Kok9a799d72007-09-15 14:07:45 -07006787 unsigned int first;
6788 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006789 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006790 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006791 int count = 0;
6792 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006793 __be16 protocol;
6794
6795 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006796
Jesse Grosseab6d182010-10-20 13:56:03 +00006797 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006798 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006799 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6800 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006801 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006802 }
6803 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6804 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006805 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6806 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006807 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006808 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6809 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006810 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006811
Yi Zou09ad1cc2009-09-03 14:56:10 +00006812#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006813 /* for FCoE with DCB, we force the priority to what
6814 * was specified by the switch */
6815 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006816 (protocol == htons(ETH_P_FCOE)))
6817 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006818#endif
6819
Yi Zoueacd73f2009-05-13 13:11:06 +00006820 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006821 if (skb_is_gso(skb) ||
6822 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006823 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6824 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006825 count++;
6826
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006827 count += TXD_USE_COUNT(skb_headlen(skb));
6828 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006829 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6830
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006831 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006832 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006833 return NETDEV_TX_BUSY;
6834 }
Auke Kok9a799d72007-09-15 14:07:45 -07006835
Auke Kok9a799d72007-09-15 14:07:45 -07006836 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006837 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6838#ifdef IXGBE_FCOE
6839 /* setup tx offload for FCoE */
6840 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6841 if (tso < 0) {
6842 dev_kfree_skb_any(skb);
6843 return NETDEV_TX_OK;
6844 }
6845 if (tso)
6846 tx_flags |= IXGBE_TX_FLAGS_FSO;
6847#endif /* IXGBE_FCOE */
6848 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006849 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006850 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006851 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6852 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006853 if (tso < 0) {
6854 dev_kfree_skb_any(skb);
6855 return NETDEV_TX_OK;
6856 }
6857
6858 if (tso)
6859 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006860 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6861 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006862 (skb->ip_summed == CHECKSUM_PARTIAL))
6863 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006864 }
6865
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006866 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006867 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006868 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006869 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6870 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006871 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006872 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006873
Alexander Duyck44df32c2009-03-31 21:34:23 +00006874 } else {
6875 dev_kfree_skb_any(skb);
6876 tx_ring->tx_buffer_info[first].time_stamp = 0;
6877 tx_ring->next_to_use = first;
6878 }
Auke Kok9a799d72007-09-15 14:07:45 -07006879
6880 return NETDEV_TX_OK;
6881}
6882
Alexander Duyck84418e32010-08-19 13:40:54 +00006883static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6884{
6885 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6886 struct ixgbe_ring *tx_ring;
6887
6888 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006889 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006890}
6891
Auke Kok9a799d72007-09-15 14:07:45 -07006892/**
Auke Kok9a799d72007-09-15 14:07:45 -07006893 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6894 * @netdev: network interface device structure
6895 * @p: pointer to an address structure
6896 *
6897 * Returns 0 on success, negative on failure
6898 **/
6899static int ixgbe_set_mac(struct net_device *netdev, void *p)
6900{
6901 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006902 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006903 struct sockaddr *addr = p;
6904
6905 if (!is_valid_ether_addr(addr->sa_data))
6906 return -EADDRNOTAVAIL;
6907
6908 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006909 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006910
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006911 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6912 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006913
6914 return 0;
6915}
6916
Ben Hutchings6b73e102009-04-29 08:08:58 +00006917static int
6918ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6919{
6920 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6921 struct ixgbe_hw *hw = &adapter->hw;
6922 u16 value;
6923 int rc;
6924
6925 if (prtad != hw->phy.mdio.prtad)
6926 return -EINVAL;
6927 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6928 if (!rc)
6929 rc = value;
6930 return rc;
6931}
6932
6933static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6934 u16 addr, u16 value)
6935{
6936 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6937 struct ixgbe_hw *hw = &adapter->hw;
6938
6939 if (prtad != hw->phy.mdio.prtad)
6940 return -EINVAL;
6941 return hw->phy.ops.write_reg(hw, addr, devad, value);
6942}
6943
6944static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6945{
6946 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6947
6948 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6949}
6950
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006951/**
6952 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006953 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006954 * @netdev: network interface device structure
6955 *
6956 * Returns non-zero on failure
6957 **/
6958static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6959{
6960 int err = 0;
6961 struct ixgbe_adapter *adapter = netdev_priv(dev);
6962 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6963
6964 if (is_valid_ether_addr(mac->san_addr)) {
6965 rtnl_lock();
6966 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6967 rtnl_unlock();
6968 }
6969 return err;
6970}
6971
6972/**
6973 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006974 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006975 * @netdev: network interface device structure
6976 *
6977 * Returns non-zero on failure
6978 **/
6979static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6980{
6981 int err = 0;
6982 struct ixgbe_adapter *adapter = netdev_priv(dev);
6983 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6984
6985 if (is_valid_ether_addr(mac->san_addr)) {
6986 rtnl_lock();
6987 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6988 rtnl_unlock();
6989 }
6990 return err;
6991}
6992
Auke Kok9a799d72007-09-15 14:07:45 -07006993#ifdef CONFIG_NET_POLL_CONTROLLER
6994/*
6995 * Polling 'interrupt' - used by things like netconsole to send skbs
6996 * without having to re-enable interrupts. It's not called while
6997 * the interrupt routine is executing.
6998 */
6999static void ixgbe_netpoll(struct net_device *netdev)
7000{
7001 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007002 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07007003
Alexander Duyck1a647bd2010-01-13 01:49:13 +00007004 /* if interface is down do nothing */
7005 if (test_bit(__IXGBE_DOWN, &adapter->state))
7006 return;
7007
Auke Kok9a799d72007-09-15 14:07:45 -07007008 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007009 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7010 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7011 for (i = 0; i < num_q_vectors; i++) {
7012 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7013 ixgbe_msix_clean_many(0, q_vector);
7014 }
7015 } else {
7016 ixgbe_intr(adapter->pdev->irq, netdev);
7017 }
Auke Kok9a799d72007-09-15 14:07:45 -07007018 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007019}
7020#endif
7021
Eric Dumazetde1036b2010-10-20 23:00:04 +00007022static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7023 struct rtnl_link_stats64 *stats)
7024{
7025 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7026 int i;
7027
Eric Dumazet1a515022010-11-16 19:26:42 -08007028 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007029 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007030 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007031 u64 bytes, packets;
7032 unsigned int start;
7033
Eric Dumazet1a515022010-11-16 19:26:42 -08007034 if (ring) {
7035 do {
7036 start = u64_stats_fetch_begin_bh(&ring->syncp);
7037 packets = ring->stats.packets;
7038 bytes = ring->stats.bytes;
7039 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7040 stats->rx_packets += packets;
7041 stats->rx_bytes += bytes;
7042 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007043 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007044
7045 for (i = 0; i < adapter->num_tx_queues; i++) {
7046 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7047 u64 bytes, packets;
7048 unsigned int start;
7049
7050 if (ring) {
7051 do {
7052 start = u64_stats_fetch_begin_bh(&ring->syncp);
7053 packets = ring->stats.packets;
7054 bytes = ring->stats.bytes;
7055 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7056 stats->tx_packets += packets;
7057 stats->tx_bytes += bytes;
7058 }
7059 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007060 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007061 /* following stats updated by ixgbe_watchdog_task() */
7062 stats->multicast = netdev->stats.multicast;
7063 stats->rx_errors = netdev->stats.rx_errors;
7064 stats->rx_length_errors = netdev->stats.rx_length_errors;
7065 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7066 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7067 return stats;
7068}
7069
7070
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007071static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007072 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007073 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007074 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007075 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007076 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007077 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7078 .ndo_validate_addr = eth_validate_addr,
7079 .ndo_set_mac_address = ixgbe_set_mac,
7080 .ndo_change_mtu = ixgbe_change_mtu,
7081 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007082 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7083 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007084 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007085 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7086 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7087 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7088 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007089 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007090#ifdef CONFIG_IXGBE_DCB
7091 .ndo_setup_tc = ixgbe_setup_tc,
7092#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007093#ifdef CONFIG_NET_POLL_CONTROLLER
7094 .ndo_poll_controller = ixgbe_netpoll,
7095#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007096#ifdef IXGBE_FCOE
7097 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007098 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007099 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007100 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7101 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007102 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007103#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007104};
7105
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007106static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7107 const struct ixgbe_info *ii)
7108{
7109#ifdef CONFIG_PCI_IOV
7110 struct ixgbe_hw *hw = &adapter->hw;
7111 int err;
Greg Rosea1cbb152011-05-13 01:33:48 +00007112 int num_vf_macvlans, i;
7113 struct vf_macvlans *mv_list;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007114
Greg Rose3377eba2010-12-07 08:16:45 +00007115 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007116 return;
7117
7118 /* The 82599 supports up to 64 VFs per physical function
7119 * but this implementation limits allocation to 63 so that
7120 * basic networking resources are still available to the
7121 * physical function
7122 */
7123 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7124 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7125 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7126 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007127 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007128 goto err_novfs;
7129 }
Greg Rosea1cbb152011-05-13 01:33:48 +00007130
7131 num_vf_macvlans = hw->mac.num_rar_entries -
7132 (IXGBE_MAX_PF_MACVLANS + 1 + adapter->num_vfs);
7133
7134 adapter->mv_list = mv_list = kcalloc(num_vf_macvlans,
7135 sizeof(struct vf_macvlans),
7136 GFP_KERNEL);
7137 if (mv_list) {
7138 /* Initialize list of VF macvlans */
7139 INIT_LIST_HEAD(&adapter->vf_mvs.l);
7140 for (i = 0; i < num_vf_macvlans; i++) {
7141 mv_list->vf = -1;
7142 mv_list->free = true;
7143 mv_list->rar_entry = hw->mac.num_rar_entries -
7144 (i + adapter->num_vfs + 1);
7145 list_add(&mv_list->l, &adapter->vf_mvs.l);
7146 mv_list++;
7147 }
7148 }
7149
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007150 /* If call to enable VFs succeeded then allocate memory
7151 * for per VF control structures.
7152 */
7153 adapter->vfinfo =
7154 kcalloc(adapter->num_vfs,
7155 sizeof(struct vf_data_storage), GFP_KERNEL);
7156 if (adapter->vfinfo) {
7157 /* Now that we're sure SR-IOV is enabled
7158 * and memory allocated set up the mailbox parameters
7159 */
7160 ixgbe_init_mbx_params_pf(hw);
7161 memcpy(&hw->mbx.ops, ii->mbx_ops,
7162 sizeof(hw->mbx.ops));
7163
7164 /* Disable RSC when in SR-IOV mode */
7165 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7166 IXGBE_FLAG2_RSC_ENABLED);
7167 return;
7168 }
7169
7170 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007171 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7172 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007173 pci_disable_sriov(adapter->pdev);
7174
7175err_novfs:
7176 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7177 adapter->num_vfs = 0;
7178#endif /* CONFIG_PCI_IOV */
7179}
7180
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007181/**
Auke Kok9a799d72007-09-15 14:07:45 -07007182 * ixgbe_probe - Device Initialization Routine
7183 * @pdev: PCI device information struct
7184 * @ent: entry in ixgbe_pci_tbl
7185 *
7186 * Returns 0 on success, negative on failure
7187 *
7188 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7189 * The OS initialization, configuring of the adapter private structure,
7190 * and a hardware reset occur.
7191 **/
7192static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007193 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007194{
7195 struct net_device *netdev;
7196 struct ixgbe_adapter *adapter = NULL;
7197 struct ixgbe_hw *hw;
7198 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007199 static int cards_found;
7200 int i, err, pci_using_dac;
Don Skidmore289700d2010-12-03 03:32:58 +00007201 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007202 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007203#ifdef IXGBE_FCOE
7204 u16 device_caps;
7205#endif
Don Skidmore289700d2010-12-03 03:32:58 +00007206 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007207
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007208 /* Catch broken hardware that put the wrong VF device ID in
7209 * the PCIe SR-IOV capability.
7210 */
7211 if (pdev->is_virtfn) {
7212 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7213 pci_name(pdev), pdev->vendor, pdev->device);
7214 return -EINVAL;
7215 }
7216
gouji-new9ce77662009-05-06 10:44:45 +00007217 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007218 if (err)
7219 return err;
7220
Nick Nunley1b507732010-04-27 13:10:27 +00007221 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7222 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007223 pci_using_dac = 1;
7224 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007225 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007226 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007227 err = dma_set_coherent_mask(&pdev->dev,
7228 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007229 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007230 dev_err(&pdev->dev,
7231 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007232 goto err_dma;
7233 }
7234 }
7235 pci_using_dac = 0;
7236 }
7237
gouji-new9ce77662009-05-06 10:44:45 +00007238 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007239 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007240 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007241 dev_err(&pdev->dev,
7242 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007243 goto err_pci_reg;
7244 }
7245
Frans Pop19d5afd2009-10-02 10:04:12 -07007246 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007247
Auke Kok9a799d72007-09-15 14:07:45 -07007248 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007249 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007250
John Fastabendc85a2612010-02-25 23:15:21 +00007251 if (ii->mac == ixgbe_mac_82598EB)
7252 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7253 else
7254 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7255
John Fastabende5b64632011-03-08 03:44:52 +00007256#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007257 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007258#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007259 indices += min_t(unsigned int, num_possible_cpus(),
7260 IXGBE_MAX_FCOE_INDICES);
7261#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007262 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007263 if (!netdev) {
7264 err = -ENOMEM;
7265 goto err_alloc_etherdev;
7266 }
7267
Auke Kok9a799d72007-09-15 14:07:45 -07007268 SET_NETDEV_DEV(netdev, &pdev->dev);
7269
Auke Kok9a799d72007-09-15 14:07:45 -07007270 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007271 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007272
7273 adapter->netdev = netdev;
7274 adapter->pdev = pdev;
7275 hw = &adapter->hw;
7276 hw->back = adapter;
7277 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7278
Jeff Kirsher05857982008-09-11 19:57:00 -07007279 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007280 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007281 if (!hw->hw_addr) {
7282 err = -EIO;
7283 goto err_ioremap;
7284 }
7285
7286 for (i = 1; i <= 5; i++) {
7287 if (pci_resource_len(pdev, i) == 0)
7288 continue;
7289 }
7290
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007291 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007292 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007293 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007294 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007295
Auke Kok9a799d72007-09-15 14:07:45 -07007296 adapter->bd_number = cards_found;
7297
Auke Kok9a799d72007-09-15 14:07:45 -07007298 /* Setup hw api */
7299 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007300 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007301
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007302 /* EEPROM */
7303 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7304 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7305 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7306 if (!(eec & (1 << 8)))
7307 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7308
7309 /* PHY */
7310 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007311 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007312 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7313 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7314 hw->phy.mdio.mmds = 0;
7315 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7316 hw->phy.mdio.dev = netdev;
7317 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7318 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007319
7320 /* set up this timer and work struct before calling get_invariants
7321 * which might start the timer
7322 */
7323 init_timer(&adapter->sfp_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00007324 adapter->sfp_timer.function = ixgbe_sfp_timer;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007325 adapter->sfp_timer.data = (unsigned long) adapter;
7326
7327 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007328
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007329 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
7330 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
7331
7332 /* a new SFP+ module arrival, called from GPI SDP2 context */
7333 INIT_WORK(&adapter->sfp_config_module_task,
Joe Perchese8e9f692010-09-07 21:34:53 +00007334 ixgbe_sfp_config_module_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007335
Don Skidmore8ca783a2009-05-26 20:40:47 -07007336 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007337
7338 /* setup the private structure */
7339 err = ixgbe_sw_init(adapter);
7340 if (err)
7341 goto err_sw_init;
7342
Don Skidmoree86bff02010-02-11 04:14:08 +00007343 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007344 switch (adapter->hw.mac.type) {
7345 case ixgbe_mac_82599EB:
7346 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007347 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007348 break;
7349 default:
7350 break;
7351 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007352
Don Skidmorebf069c92009-05-07 10:39:54 +00007353 /*
7354 * If there is a fan on this device and it has failed log the
7355 * failure.
7356 */
7357 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7358 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7359 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007360 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007361 }
7362
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007363 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007364 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007365 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007366 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007367 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7368 hw->mac.type == ixgbe_mac_82598EB) {
7369 /*
7370 * Start a kernel thread to watch for a module to arrive.
7371 * Only do this for 82598, since 82599 will generate
7372 * interrupts on module arrival.
7373 */
7374 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
7375 mod_timer(&adapter->sfp_timer,
7376 round_jiffies(jiffies + (2 * HZ)));
7377 err = 0;
7378 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007379 e_dev_err("failed to initialize because an unsupported SFP+ "
7380 "module type was detected.\n");
7381 e_dev_err("Reload the driver after installing a supported "
7382 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007383 goto err_sw_init;
7384 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007385 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007386 goto err_sw_init;
7387 }
7388
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007389 ixgbe_probe_vf(adapter, ii);
7390
Emil Tantilov396e7992010-07-01 20:05:12 +00007391 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007392 NETIF_F_IP_CSUM |
7393 NETIF_F_HW_VLAN_TX |
7394 NETIF_F_HW_VLAN_RX |
7395 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007396
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007397 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007398 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007399 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007400 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007401 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007402
Don Skidmore58be7662011-04-12 09:42:11 +00007403 switch (adapter->hw.mac.type) {
7404 case ixgbe_mac_82599EB:
7405 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007406 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007407 break;
7408 default:
7409 break;
7410 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007411
Jeff Kirsherad31c402008-06-05 04:05:30 -07007412 netdev->vlan_features |= NETIF_F_TSO;
7413 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007414 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007415 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007416 netdev->vlan_features |= NETIF_F_SG;
7417
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007418 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7419 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7420 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007421
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007422#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007423 netdev->dcbnl_ops = &dcbnl_ops;
7424#endif
7425
Yi Zoueacd73f2009-05-13 13:11:06 +00007426#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007427 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007428 if (hw->mac.ops.get_device_caps) {
7429 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007430 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7431 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007432 }
7433 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007434 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7435 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7436 netdev->vlan_features |= NETIF_F_FSO;
7437 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7438 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007439#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007440 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007441 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007442 netdev->vlan_features |= NETIF_F_HIGHDMA;
7443 }
Auke Kok9a799d72007-09-15 14:07:45 -07007444
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007445 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007446 netdev->features |= NETIF_F_LRO;
7447
Auke Kok9a799d72007-09-15 14:07:45 -07007448 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007449 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007450 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007451 err = -EIO;
7452 goto err_eeprom;
7453 }
7454
7455 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7456 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7457
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007458 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007459 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007460 err = -EIO;
7461 goto err_eeprom;
7462 }
7463
Don Skidmorec6ecf392010-12-03 03:31:51 +00007464 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7465 if (hw->mac.ops.disable_tx_laser &&
7466 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007467 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007468 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007469 hw->mac.ops.disable_tx_laser(hw);
7470
Auke Kok9a799d72007-09-15 14:07:45 -07007471 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00007472 adapter->watchdog_timer.function = ixgbe_watchdog;
Auke Kok9a799d72007-09-15 14:07:45 -07007473 adapter->watchdog_timer.data = (unsigned long)adapter;
7474
7475 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007476 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007477
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007478 err = ixgbe_init_interrupt_scheme(adapter);
7479 if (err)
7480 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007481
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007482 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7483 netdev->features &= ~NETIF_F_RXHASH;
7484
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007485 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007486 case IXGBE_DEV_ID_82599_SFP:
7487 /* Only this subdevice supports WOL */
7488 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7489 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7490 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7491 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007492 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7493 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007494 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7495 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7496 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7497 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007498 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007499 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007500 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007501 break;
7502 default:
7503 adapter->wol = 0;
7504 break;
7505 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007506 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7507
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007508 /* pick up the PCI bus settings for reporting later */
7509 hw->mac.ops.get_bus_info(hw);
7510
Auke Kok9a799d72007-09-15 14:07:45 -07007511 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007512 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007513 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7514 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007515 "Unknown"),
7516 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7517 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7518 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7519 "Unknown"),
7520 netdev->dev_addr);
Don Skidmore289700d2010-12-03 03:32:58 +00007521
7522 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7523 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007524 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007525 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700d2010-12-03 03:32:58 +00007526 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007527 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700d2010-12-03 03:32:58 +00007528 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007529 else
Don Skidmore289700d2010-12-03 03:32:58 +00007530 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7531 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007532
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007533 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007534 e_dev_warn("PCI-Express bandwidth available for this card is "
7535 "not sufficient for optimal performance.\n");
7536 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7537 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007538 }
7539
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007540 /* save off EEPROM version number */
7541 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7542
Auke Kok9a799d72007-09-15 14:07:45 -07007543 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007544 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007545
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007546 if (err == IXGBE_ERR_EEPROM_VERSION) {
7547 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007548 e_dev_warn("This device is a pre-production adapter/LOM. "
7549 "Please be aware there may be issues associated "
7550 "with your hardware. If you are experiencing "
7551 "problems please contact your Intel or hardware "
7552 "representative who provided you with this "
7553 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007554 }
Auke Kok9a799d72007-09-15 14:07:45 -07007555 strcpy(netdev->name, "eth%d");
7556 err = register_netdev(netdev);
7557 if (err)
7558 goto err_register;
7559
Jesse Brandeburg54386462009-04-17 20:44:27 +00007560 /* carrier off reporting is important to ethtool even BEFORE open */
7561 netif_carrier_off(netdev);
7562
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007563 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7564 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7565 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
7566
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007567 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Joe Perchese8e9f692010-09-07 21:34:53 +00007568 INIT_WORK(&adapter->check_overtemp_task,
7569 ixgbe_check_overtemp_task);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007570#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007571 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007572 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007573 ixgbe_setup_dca(adapter);
7574 }
7575#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007576 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007577 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007578 for (i = 0; i < adapter->num_vfs; i++)
7579 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7580 }
7581
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007582 /* add san mac addr to netdev */
7583 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007584
Emil Tantilov849c4542010-06-03 16:53:41 +00007585 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007586 cards_found++;
7587 return 0;
7588
7589err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007590 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007591 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007592err_sw_init:
7593err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007594 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7595 ixgbe_disable_sriov(adapter);
Donald Skidmorec4900be2008-11-20 21:11:42 -08007596 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
7597 del_timer_sync(&adapter->sfp_timer);
7598 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007599 cancel_work_sync(&adapter->multispeed_fiber_task);
7600 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007601 iounmap(hw->hw_addr);
7602err_ioremap:
7603 free_netdev(netdev);
7604err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007605 pci_release_selected_regions(pdev,
7606 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007607err_pci_reg:
7608err_dma:
7609 pci_disable_device(pdev);
7610 return err;
7611}
7612
7613/**
7614 * ixgbe_remove - Device Removal Routine
7615 * @pdev: PCI device information struct
7616 *
7617 * ixgbe_remove is called by the PCI subsystem to alert the driver
7618 * that it should release a PCI device. The could be caused by a
7619 * Hot-Plug event, or because the driver is going to be removed from
7620 * memory.
7621 **/
7622static void __devexit ixgbe_remove(struct pci_dev *pdev)
7623{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007624 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7625 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007626
7627 set_bit(__IXGBE_DOWN, &adapter->state);
Tejun Heo760141a2010-12-12 16:45:14 +01007628
7629 /*
7630 * The timers may be rescheduled, so explicitly disable them
7631 * from being rescheduled.
Donald Skidmorec4900be2008-11-20 21:11:42 -08007632 */
7633 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007634 del_timer_sync(&adapter->watchdog_timer);
Donald Skidmorec4900be2008-11-20 21:11:42 -08007635 del_timer_sync(&adapter->sfp_timer);
Tejun Heo760141a2010-12-12 16:45:14 +01007636
Donald Skidmorec4900be2008-11-20 21:11:42 -08007637 cancel_work_sync(&adapter->watchdog_task);
7638 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007639 cancel_work_sync(&adapter->multispeed_fiber_task);
7640 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007641 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7642 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7643 cancel_work_sync(&adapter->fdir_reinit_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007644 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
7645 cancel_work_sync(&adapter->check_overtemp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007646
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007647#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007648 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7649 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7650 dca_remove_requester(&pdev->dev);
7651 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7652 }
7653
7654#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007655#ifdef IXGBE_FCOE
7656 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7657 ixgbe_cleanup_fcoe(adapter);
7658
7659#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007660
7661 /* remove the added san mac */
7662 ixgbe_del_sanmac_netdev(netdev);
7663
Donald Skidmorec4900be2008-11-20 21:11:42 -08007664 if (netdev->reg_state == NETREG_REGISTERED)
7665 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007666
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007667 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7668 ixgbe_disable_sriov(adapter);
7669
Alexander Duyck7a921c92009-05-06 10:43:28 +00007670 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007671
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007672 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007673
7674 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007675 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007676 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007677
Emil Tantilov849c4542010-06-03 16:53:41 +00007678 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007679
Auke Kok9a799d72007-09-15 14:07:45 -07007680 free_netdev(netdev);
7681
Frans Pop19d5afd2009-10-02 10:04:12 -07007682 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007683
Auke Kok9a799d72007-09-15 14:07:45 -07007684 pci_disable_device(pdev);
7685}
7686
7687/**
7688 * ixgbe_io_error_detected - called when PCI error is detected
7689 * @pdev: Pointer to PCI device
7690 * @state: The current pci connection state
7691 *
7692 * This function is called after a PCI bus error affecting
7693 * this device has been detected.
7694 */
7695static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007696 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007697{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007698 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7699 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007700
7701 netif_device_detach(netdev);
7702
Breno Leitao3044b8d2009-05-06 10:44:26 +00007703 if (state == pci_channel_io_perm_failure)
7704 return PCI_ERS_RESULT_DISCONNECT;
7705
Auke Kok9a799d72007-09-15 14:07:45 -07007706 if (netif_running(netdev))
7707 ixgbe_down(adapter);
7708 pci_disable_device(pdev);
7709
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007710 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007711 return PCI_ERS_RESULT_NEED_RESET;
7712}
7713
7714/**
7715 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7716 * @pdev: Pointer to PCI device
7717 *
7718 * Restart the card from scratch, as if from a cold-boot.
7719 */
7720static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7721{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007722 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007723 pci_ers_result_t result;
7724 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007725
gouji-new9ce77662009-05-06 10:44:45 +00007726 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007727 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007728 result = PCI_ERS_RESULT_DISCONNECT;
7729 } else {
7730 pci_set_master(pdev);
7731 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007732 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007733
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007734 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007735
7736 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007737 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007738 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007739 }
Auke Kok9a799d72007-09-15 14:07:45 -07007740
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007741 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7742 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007743 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7744 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007745 /* non-fatal, continue */
7746 }
Auke Kok9a799d72007-09-15 14:07:45 -07007747
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007748 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007749}
7750
7751/**
7752 * ixgbe_io_resume - called when traffic can start flowing again.
7753 * @pdev: Pointer to PCI device
7754 *
7755 * This callback is called when the error recovery driver tells us that
7756 * its OK to resume normal operation.
7757 */
7758static void ixgbe_io_resume(struct pci_dev *pdev)
7759{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007760 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7761 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007762
7763 if (netif_running(netdev)) {
7764 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007765 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007766 return;
7767 }
7768 }
7769
7770 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007771}
7772
7773static struct pci_error_handlers ixgbe_err_handler = {
7774 .error_detected = ixgbe_io_error_detected,
7775 .slot_reset = ixgbe_io_slot_reset,
7776 .resume = ixgbe_io_resume,
7777};
7778
7779static struct pci_driver ixgbe_driver = {
7780 .name = ixgbe_driver_name,
7781 .id_table = ixgbe_pci_tbl,
7782 .probe = ixgbe_probe,
7783 .remove = __devexit_p(ixgbe_remove),
7784#ifdef CONFIG_PM
7785 .suspend = ixgbe_suspend,
7786 .resume = ixgbe_resume,
7787#endif
7788 .shutdown = ixgbe_shutdown,
7789 .err_handler = &ixgbe_err_handler
7790};
7791
7792/**
7793 * ixgbe_init_module - Driver Registration Routine
7794 *
7795 * ixgbe_init_module is the first routine called when the driver is
7796 * loaded. All it does is register with the PCI subsystem.
7797 **/
7798static int __init ixgbe_init_module(void)
7799{
7800 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007801 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007802 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007803
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007804#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007805 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007806#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007807
Auke Kok9a799d72007-09-15 14:07:45 -07007808 ret = pci_register_driver(&ixgbe_driver);
7809 return ret;
7810}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007811
Auke Kok9a799d72007-09-15 14:07:45 -07007812module_init(ixgbe_init_module);
7813
7814/**
7815 * ixgbe_exit_module - Driver Exit Cleanup Routine
7816 *
7817 * ixgbe_exit_module is called just before the driver is removed
7818 * from memory.
7819 **/
7820static void __exit ixgbe_exit_module(void)
7821{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007822#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007823 dca_unregister_notify(&dca_notifier);
7824#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007825 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007826 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007827}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007828
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007829#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007830static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007831 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007832{
7833 int ret_val;
7834
7835 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007836 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007837
7838 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7839}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007840
Alexander Duyckb4533682009-03-31 21:32:42 +00007841#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007842
Auke Kok9a799d72007-09-15 14:07:45 -07007843module_exit(ixgbe_exit_module);
7844
7845/* ixgbe_main.c */