blob: 56cc9a10c717dc91c3c2799c7b96bd31efb600d8 [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 */
3191 hw->mac.ops.set_mac_anti_spoofing(hw, (adapter->num_vfs != 0),
3192 adapter->num_vfs);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003193}
3194
Alexander Duyck477de6e2010-08-19 13:38:11 +00003195static void ixgbe_set_rx_buffer_len(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003196{
Auke Kok9a799d72007-09-15 14:07:45 -07003197 struct ixgbe_hw *hw = &adapter->hw;
3198 struct net_device *netdev = adapter->netdev;
3199 int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003200 int rx_buf_len;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003201 struct ixgbe_ring *rx_ring;
3202 int i;
3203 u32 mhadd, hlreg0;
Alexander Duyck48654522010-08-19 13:36:27 +00003204
Auke Kok9a799d72007-09-15 14:07:45 -07003205 /* Decide whether to use packet split mode or not */
Don Skidmorea1243392011-01-18 22:53:47 +00003206 /* On by default */
3207 adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED;
3208
Greg Rose1cdd1ec2010-01-09 02:26:46 +00003209 /* Do not use packet split if we're in SR-IOV Mode */
Don Skidmorea1243392011-01-18 22:53:47 +00003210 if (adapter->num_vfs)
3211 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
3212
3213 /* Disable packet split due to 82599 erratum #45 */
3214 if (hw->mac.type == ixgbe_mac_82599EB)
3215 adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED;
Auke Kok9a799d72007-09-15 14:07:45 -07003216
3217 /* Set the RX buffer length according to the mode */
3218 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) {
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003219 rx_buf_len = IXGBE_RX_HDR_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003220 } else {
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00003221 if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) &&
Alexander Duyckf8212f92009-04-27 22:42:37 +00003222 (netdev->mtu <= ETH_DATA_LEN))
Jesse Brandeburg7c6e0a42008-08-26 04:27:16 -07003223 rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE;
Auke Kok9a799d72007-09-15 14:07:45 -07003224 else
Alexander Duyck477de6e2010-08-19 13:38:11 +00003225 rx_buf_len = ALIGN(max_frame + VLAN_HLEN, 1024);
3226 }
3227
3228#ifdef IXGBE_FCOE
3229 /* adjust max frame to be able to do baby jumbo for FCoE */
3230 if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) &&
3231 (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE))
3232 max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE;
3233
3234#endif /* IXGBE_FCOE */
3235 mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD);
3236 if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) {
3237 mhadd &= ~IXGBE_MHADD_MFS_MASK;
3238 mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT;
3239
3240 IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd);
Auke Kok9a799d72007-09-15 14:07:45 -07003241 }
3242
Auke Kok9a799d72007-09-15 14:07:45 -07003243 hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003244 /* set jumbo enable since MHADD.MFS is keeping size locked at max_frame */
3245 hlreg0 |= IXGBE_HLREG0_JUMBOEN;
Auke Kok9a799d72007-09-15 14:07:45 -07003246 IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
3247
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00003248 /*
3249 * Setup the HW Rx Head and Tail Descriptor Pointers and
3250 * the Base and Length of the Rx Descriptor Ring
3251 */
Auke Kok9a799d72007-09-15 14:07:45 -07003252 for (i = 0; i < adapter->num_rx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003253 rx_ring = adapter->rx_ring[i];
Yi Zoua6616b42009-08-06 13:05:23 +00003254 rx_ring->rx_buf_len = rx_buf_len;
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003255
Yi Zou6e455b892009-08-06 13:05:44 +00003256 if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003257 set_ring_ps_enabled(rx_ring);
Peter P Waskiewicz Jr1b3ff022009-09-14 07:47:27 +00003258 else
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003259 clear_ring_ps_enabled(rx_ring);
3260
3261 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
3262 set_ring_rsc_enabled(rx_ring);
3263 else
3264 clear_ring_rsc_enabled(rx_ring);
Jesse Brandeburgcc41ac72008-08-26 04:27:27 -07003265
Yi Zou63f39bd2009-05-17 12:34:35 +00003266#ifdef IXGBE_FCOE
Joe Perchese8e9f692010-09-07 21:34:53 +00003267 if (netdev->features & NETIF_F_FCOE_MTU) {
Yi Zou63f39bd2009-05-17 12:34:35 +00003268 struct ixgbe_ring_feature *f;
3269 f = &adapter->ring_feature[RING_F_FCOE];
Yi Zou6e455b892009-08-06 13:05:44 +00003270 if ((i >= f->mask) && (i < f->mask + f->indices)) {
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003271 clear_ring_ps_enabled(rx_ring);
Yi Zou6e455b892009-08-06 13:05:44 +00003272 if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE)
3273 rx_ring->rx_buf_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00003274 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Alexander Duyck7d637bc2010-11-16 19:26:56 -08003275 } else if (!ring_is_rsc_enabled(rx_ring) &&
3276 !ring_is_ps_enabled(rx_ring)) {
3277 rx_ring->rx_buf_len =
3278 IXGBE_FCOE_JUMBO_FRAME_SIZE;
Yi Zou6e455b892009-08-06 13:05:44 +00003279 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003280 }
Yi Zou63f39bd2009-05-17 12:34:35 +00003281#endif /* IXGBE_FCOE */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003282 }
Alexander Duyck477de6e2010-08-19 13:38:11 +00003283}
3284
Alexander Duyck73670962010-08-19 13:38:34 +00003285static void ixgbe_setup_rdrxctl(struct ixgbe_adapter *adapter)
3286{
3287 struct ixgbe_hw *hw = &adapter->hw;
3288 u32 rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL);
3289
3290 switch (hw->mac.type) {
3291 case ixgbe_mac_82598EB:
3292 /*
3293 * For VMDq support of different descriptor types or
3294 * buffer sizes through the use of multiple SRRCTL
3295 * registers, RDRXCTL.MVMEN must be set to 1
3296 *
3297 * also, the manual doesn't mention it clearly but DCA hints
3298 * will only use queue 0's tags unless this bit is set. Side
3299 * effects of setting this bit are only that SRRCTL must be
3300 * fully programmed [0..15]
3301 */
3302 rdrxctl |= IXGBE_RDRXCTL_MVMEN;
3303 break;
3304 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003305 case ixgbe_mac_X540:
Alexander Duyck73670962010-08-19 13:38:34 +00003306 /* Disable RSC for ACK packets */
3307 IXGBE_WRITE_REG(hw, IXGBE_RSCDBU,
3308 (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU)));
3309 rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE;
3310 /* hardware requires some bits to be set by default */
3311 rdrxctl |= (IXGBE_RDRXCTL_RSCACKC | IXGBE_RDRXCTL_FCOE_WRFIX);
3312 rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP;
3313 break;
3314 default:
3315 /* We should do nothing since we don't know this hardware */
3316 return;
3317 }
3318
3319 IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl);
3320}
3321
Alexander Duyck477de6e2010-08-19 13:38:11 +00003322/**
3323 * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset
3324 * @adapter: board private structure
3325 *
3326 * Configure the Rx unit of the MAC after a reset.
3327 **/
3328static void ixgbe_configure_rx(struct ixgbe_adapter *adapter)
3329{
3330 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003331 int i;
3332 u32 rxctrl;
Alexander Duyck477de6e2010-08-19 13:38:11 +00003333
3334 /* disable receives while setting up the descriptors */
3335 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
3336 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
3337
3338 ixgbe_setup_psrtype(adapter);
Alexander Duyck73670962010-08-19 13:38:34 +00003339 ixgbe_setup_rdrxctl(adapter);
Alexander Duyck477de6e2010-08-19 13:38:11 +00003340
Alexander Duyck9e10e042010-08-19 13:40:06 +00003341 /* Program registers for the distribution of queues */
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003342 ixgbe_setup_mrqc(adapter);
Alexander Duyckf5b4a522010-08-19 13:38:57 +00003343
Alexander Duyck9e10e042010-08-19 13:40:06 +00003344 ixgbe_set_uta(adapter);
3345
Alexander Duyck477de6e2010-08-19 13:38:11 +00003346 /* set_rx_buffer_len must be called before ring initialization */
3347 ixgbe_set_rx_buffer_len(adapter);
3348
3349 /*
3350 * Setup the HW Rx Head and Tail Descriptor Pointers and
3351 * the Base and Length of the Rx Descriptor Ring
3352 */
Alexander Duyck9e10e042010-08-19 13:40:06 +00003353 for (i = 0; i < adapter->num_rx_queues; i++)
3354 ixgbe_configure_rx_ring(adapter, adapter->rx_ring[i]);
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07003355
Alexander Duyck9e10e042010-08-19 13:40:06 +00003356 /* disable drop enable for 82598 parts */
3357 if (hw->mac.type == ixgbe_mac_82598EB)
3358 rxctrl |= IXGBE_RXCTRL_DMBYPS;
3359
3360 /* enable all receives */
3361 rxctrl |= IXGBE_RXCTRL_RXEN;
3362 hw->mac.ops.enable_rx_dma(hw, rxctrl);
Auke Kok9a799d72007-09-15 14:07:45 -07003363}
3364
Auke Kok9a799d72007-09-15 14:07:45 -07003365static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid)
3366{
3367 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003368 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003369 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003370
3371 /* add VID to filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003372 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003373 set_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003374}
3375
3376static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid)
3377{
3378 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003379 struct ixgbe_hw *hw = &adapter->hw;
Greg Rose1ada1b12010-01-22 22:45:43 +00003380 int pool_ndx = adapter->num_vfs;
Auke Kok9a799d72007-09-15 14:07:45 -07003381
Auke Kok9a799d72007-09-15 14:07:45 -07003382 /* remove VID from filter table */
Greg Rose1ada1b12010-01-22 22:45:43 +00003383 hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003384 clear_bit(vid, adapter->active_vlans);
Auke Kok9a799d72007-09-15 14:07:45 -07003385}
3386
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003387/**
3388 * ixgbe_vlan_filter_disable - helper to disable hw vlan filtering
3389 * @adapter: driver data
3390 */
3391static void ixgbe_vlan_filter_disable(struct ixgbe_adapter *adapter)
3392{
3393 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003394 u32 vlnctrl;
3395
3396 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3397 vlnctrl &= ~(IXGBE_VLNCTRL_VFE | IXGBE_VLNCTRL_CFIEN);
3398 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3399}
3400
3401/**
3402 * ixgbe_vlan_filter_enable - helper to enable hw vlan filtering
3403 * @adapter: driver data
3404 */
3405static void ixgbe_vlan_filter_enable(struct ixgbe_adapter *adapter)
3406{
3407 struct ixgbe_hw *hw = &adapter->hw;
3408 u32 vlnctrl;
3409
3410 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3411 vlnctrl |= IXGBE_VLNCTRL_VFE;
3412 vlnctrl &= ~IXGBE_VLNCTRL_CFIEN;
3413 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3414}
3415
3416/**
3417 * ixgbe_vlan_strip_disable - helper to disable hw vlan stripping
3418 * @adapter: driver data
3419 */
3420static void ixgbe_vlan_strip_disable(struct ixgbe_adapter *adapter)
3421{
3422 struct ixgbe_hw *hw = &adapter->hw;
3423 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003424 int i, j;
3425
3426 switch (hw->mac.type) {
3427 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003428 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3429 vlnctrl &= ~IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003430 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3431 break;
3432 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003433 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003434 for (i = 0; i < adapter->num_rx_queues; i++) {
3435 j = adapter->rx_ring[i]->reg_idx;
3436 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3437 vlnctrl &= ~IXGBE_RXDCTL_VME;
3438 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3439 }
3440 break;
3441 default:
3442 break;
3443 }
3444}
3445
3446/**
Jesse Grossf62bbb52010-10-20 13:56:10 +00003447 * ixgbe_vlan_strip_enable - helper to enable hw vlan stripping
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003448 * @adapter: driver data
3449 */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003450static void ixgbe_vlan_strip_enable(struct ixgbe_adapter *adapter)
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003451{
3452 struct ixgbe_hw *hw = &adapter->hw;
Jesse Grossf62bbb52010-10-20 13:56:10 +00003453 u32 vlnctrl;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003454 int i, j;
3455
3456 switch (hw->mac.type) {
3457 case ixgbe_mac_82598EB:
Jesse Grossf62bbb52010-10-20 13:56:10 +00003458 vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL);
3459 vlnctrl |= IXGBE_VLNCTRL_VME;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003460 IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl);
3461 break;
3462 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003463 case ixgbe_mac_X540:
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003464 for (i = 0; i < adapter->num_rx_queues; i++) {
3465 j = adapter->rx_ring[i]->reg_idx;
3466 vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j));
3467 vlnctrl |= IXGBE_RXDCTL_VME;
3468 IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl);
3469 }
3470 break;
3471 default:
3472 break;
3473 }
3474}
3475
Auke Kok9a799d72007-09-15 14:07:45 -07003476static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter)
3477{
Jesse Grossf62bbb52010-10-20 13:56:10 +00003478 u16 vid;
Auke Kok9a799d72007-09-15 14:07:45 -07003479
Jesse Grossf62bbb52010-10-20 13:56:10 +00003480 ixgbe_vlan_rx_add_vid(adapter->netdev, 0);
3481
3482 for_each_set_bit(vid, adapter->active_vlans, VLAN_N_VID)
3483 ixgbe_vlan_rx_add_vid(adapter->netdev, vid);
Auke Kok9a799d72007-09-15 14:07:45 -07003484}
3485
3486/**
Alexander Duyck28500622010-06-15 09:25:48 +00003487 * ixgbe_write_uc_addr_list - write unicast addresses to RAR table
3488 * @netdev: network interface device structure
3489 *
3490 * Writes unicast address list to the RAR table.
3491 * Returns: -ENOMEM on failure/insufficient address space
3492 * 0 on no addresses written
3493 * X on writing X addresses to the RAR table
3494 **/
3495static int ixgbe_write_uc_addr_list(struct net_device *netdev)
3496{
3497 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3498 struct ixgbe_hw *hw = &adapter->hw;
3499 unsigned int vfn = adapter->num_vfs;
3500 unsigned int rar_entries = hw->mac.num_rar_entries - (vfn + 1);
3501 int count = 0;
3502
3503 /* return ENOMEM indicating insufficient memory for addresses */
3504 if (netdev_uc_count(netdev) > rar_entries)
3505 return -ENOMEM;
3506
3507 if (!netdev_uc_empty(netdev) && rar_entries) {
3508 struct netdev_hw_addr *ha;
3509 /* return error if we do not support writing to RAR table */
3510 if (!hw->mac.ops.set_rar)
3511 return -ENOMEM;
3512
3513 netdev_for_each_uc_addr(ha, netdev) {
3514 if (!rar_entries)
3515 break;
3516 hw->mac.ops.set_rar(hw, rar_entries--, ha->addr,
3517 vfn, IXGBE_RAH_AV);
3518 count++;
3519 }
3520 }
3521 /* write the addresses in reverse order to avoid write combining */
3522 for (; rar_entries > 0 ; rar_entries--)
3523 hw->mac.ops.clear_rar(hw, rar_entries);
3524
3525 return count;
3526}
3527
3528/**
Christopher Leech2c5645c2008-08-26 04:27:02 -07003529 * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set
Auke Kok9a799d72007-09-15 14:07:45 -07003530 * @netdev: network interface device structure
3531 *
Christopher Leech2c5645c2008-08-26 04:27:02 -07003532 * The set_rx_method entry point is called whenever the unicast/multicast
3533 * address list or the network interface flags are updated. This routine is
3534 * responsible for configuring the hardware for proper unicast, multicast and
3535 * promiscuous mode.
Auke Kok9a799d72007-09-15 14:07:45 -07003536 **/
Greg Rose7f870472010-01-09 02:25:29 +00003537void ixgbe_set_rx_mode(struct net_device *netdev)
Auke Kok9a799d72007-09-15 14:07:45 -07003538{
3539 struct ixgbe_adapter *adapter = netdev_priv(netdev);
3540 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck28500622010-06-15 09:25:48 +00003541 u32 fctrl, vmolr = IXGBE_VMOLR_BAM | IXGBE_VMOLR_AUPE;
3542 int count;
Auke Kok9a799d72007-09-15 14:07:45 -07003543
3544 /* Check for Promiscuous and All Multicast modes */
3545
3546 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
3547
Alexander Duyckf5dc4422010-08-19 13:36:49 +00003548 /* set all bits that we expect to always be set */
3549 fctrl |= IXGBE_FCTRL_BAM;
3550 fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */
3551 fctrl |= IXGBE_FCTRL_PMCF;
3552
Alexander Duyck28500622010-06-15 09:25:48 +00003553 /* clear the bits we are changing the status of */
3554 fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
3555
Auke Kok9a799d72007-09-15 14:07:45 -07003556 if (netdev->flags & IFF_PROMISC) {
Emil Tantilove433ea12010-05-13 17:33:00 +00003557 hw->addr_ctrl.user_set_promisc = true;
Auke Kok9a799d72007-09-15 14:07:45 -07003558 fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE);
Alexander Duyck28500622010-06-15 09:25:48 +00003559 vmolr |= (IXGBE_VMOLR_ROPE | IXGBE_VMOLR_MPE);
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003560 /* don't hardware filter vlans in promisc mode */
3561 ixgbe_vlan_filter_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003562 } else {
Patrick McHardy746b9f02008-07-16 20:15:45 -07003563 if (netdev->flags & IFF_ALLMULTI) {
3564 fctrl |= IXGBE_FCTRL_MPE;
Alexander Duyck28500622010-06-15 09:25:48 +00003565 vmolr |= IXGBE_VMOLR_MPE;
3566 } else {
3567 /*
3568 * Write addresses to the MTA, if the attempt fails
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003569 * then we should just turn on promiscuous mode so
Alexander Duyck28500622010-06-15 09:25:48 +00003570 * that we can at least receive multicast traffic
3571 */
3572 hw->mac.ops.update_mc_addr_list(hw, netdev);
3573 vmolr |= IXGBE_VMOLR_ROMPE;
Patrick McHardy746b9f02008-07-16 20:15:45 -07003574 }
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003575 ixgbe_vlan_filter_enable(adapter);
Emil Tantilove433ea12010-05-13 17:33:00 +00003576 hw->addr_ctrl.user_set_promisc = false;
Alexander Duyck28500622010-06-15 09:25:48 +00003577 /*
3578 * Write addresses to available RAR registers, if there is not
3579 * sufficient space to store all the addresses then enable
Lucas De Marchi25985ed2011-03-30 22:57:33 -03003580 * unicast promiscuous mode
Alexander Duyck28500622010-06-15 09:25:48 +00003581 */
3582 count = ixgbe_write_uc_addr_list(netdev);
3583 if (count < 0) {
3584 fctrl |= IXGBE_FCTRL_UPE;
3585 vmolr |= IXGBE_VMOLR_ROPE;
3586 }
3587 }
3588
3589 if (adapter->num_vfs) {
3590 ixgbe_restore_vf_multicasts(adapter);
3591 vmolr |= IXGBE_READ_REG(hw, IXGBE_VMOLR(adapter->num_vfs)) &
3592 ~(IXGBE_VMOLR_MPE | IXGBE_VMOLR_ROMPE |
3593 IXGBE_VMOLR_ROPE);
3594 IXGBE_WRITE_REG(hw, IXGBE_VMOLR(adapter->num_vfs), vmolr);
Auke Kok9a799d72007-09-15 14:07:45 -07003595 }
3596
3597 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
Jesse Grossf62bbb52010-10-20 13:56:10 +00003598
3599 if (netdev->features & NETIF_F_HW_VLAN_RX)
3600 ixgbe_vlan_strip_enable(adapter);
3601 else
3602 ixgbe_vlan_strip_disable(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003603}
3604
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003605static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter)
3606{
3607 int q_idx;
3608 struct ixgbe_q_vector *q_vector;
3609 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3610
3611 /* legacy and MSI only use one vector */
3612 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3613 q_vectors = 1;
3614
3615 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003616 struct napi_struct *napi;
Alexander Duyck7a921c92009-05-06 10:43:28 +00003617 q_vector = adapter->q_vector[q_idx];
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003618 napi = &q_vector->napi;
Alexander Duyck91281fd2009-06-04 16:00:27 +00003619 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
3620 if (!q_vector->rxr_count || !q_vector->txr_count) {
3621 if (q_vector->txr_count == 1)
3622 napi->poll = &ixgbe_clean_txonly;
3623 else if (q_vector->rxr_count == 1)
3624 napi->poll = &ixgbe_clean_rxonly;
3625 }
3626 }
Jesse Brandeburgf0848272008-09-11 19:59:42 -07003627
3628 napi_enable(napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003629 }
3630}
3631
3632static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter)
3633{
3634 int q_idx;
3635 struct ixgbe_q_vector *q_vector;
3636 int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
3637
3638 /* legacy and MSI only use one vector */
3639 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED))
3640 q_vectors = 1;
3641
3642 for (q_idx = 0; q_idx < q_vectors; q_idx++) {
Alexander Duyck7a921c92009-05-06 10:43:28 +00003643 q_vector = adapter->q_vector[q_idx];
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003644 napi_disable(&q_vector->napi);
3645 }
3646}
3647
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003648#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08003649/*
3650 * ixgbe_configure_dcb - Configure DCB hardware
3651 * @adapter: ixgbe adapter struct
3652 *
3653 * This is called by the driver on open to configure the DCB hardware.
3654 * This is also called by the gennetlink interface when reconfiguring
3655 * the DCB state.
3656 */
3657static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter)
3658{
3659 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend98063072010-10-28 00:59:57 +00003660 int max_frame = adapter->netdev->mtu + ETH_HLEN + ETH_FCS_LEN;
Alexander Duyck2f90b862008-11-20 20:52:10 -08003661
Alexander Duyck67ebd792010-08-19 13:34:04 +00003662 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) {
3663 if (hw->mac.type == ixgbe_mac_82598EB)
3664 netif_set_gso_max_size(adapter->netdev, 65536);
3665 return;
3666 }
3667
3668 if (hw->mac.type == ixgbe_mac_82598EB)
3669 netif_set_gso_max_size(adapter->netdev, 32768);
3670
Alexander Duyck2f90b862008-11-20 20:52:10 -08003671
Alexander Duyck2f90b862008-11-20 20:52:10 -08003672 /* Enable VLAN tag insert/strip */
Jesse Grossf62bbb52010-10-20 13:56:10 +00003673 adapter->netdev->features |= NETIF_F_HW_VLAN_RX;
Jesse Brandeburg5f6c0182010-04-14 16:04:23 -07003674
Alexander Duyck2f90b862008-11-20 20:52:10 -08003675 hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true);
Alexander Duyck01fa7d92010-11-16 19:26:53 -08003676
3677 /* reconfigure the hardware */
John Fastabendc27931d2011-02-23 05:58:25 +00003678 if (adapter->dcbx_cap & (DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE)) {
3679#ifdef CONFIG_FCOE
3680 if (adapter->netdev->features & NETIF_F_FCOE_MTU)
3681 max_frame = max(max_frame, IXGBE_FCOE_JUMBO_FRAME_SIZE);
3682#endif
3683 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3684 DCB_TX_CONFIG);
3685 ixgbe_dcb_calculate_tc_credits(hw, &adapter->dcb_cfg, max_frame,
3686 DCB_RX_CONFIG);
3687 ixgbe_dcb_hw_config(hw, &adapter->dcb_cfg);
3688 } else {
3689 struct net_device *dev = adapter->netdev;
3690
3691 if (adapter->ixgbe_ieee_ets)
3692 dev->dcbnl_ops->ieee_setets(dev,
3693 adapter->ixgbe_ieee_ets);
3694 if (adapter->ixgbe_ieee_pfc)
3695 dev->dcbnl_ops->ieee_setpfc(dev,
3696 adapter->ixgbe_ieee_pfc);
3697 }
John Fastabend8187cd42011-02-23 05:58:08 +00003698
3699 /* Enable RSS Hash per TC */
3700 if (hw->mac.type != ixgbe_mac_82598EB) {
3701 int i;
3702 u32 reg = 0;
3703
3704 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
3705 u8 msb = 0;
3706 u8 cnt = adapter->netdev->tc_to_txq[i].count;
3707
3708 while (cnt >>= 1)
3709 msb++;
3710
3711 reg |= msb << IXGBE_RQTC_SHIFT_TC(i);
3712 }
3713 IXGBE_WRITE_REG(hw, IXGBE_RQTC, reg);
3714 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08003715}
3716
3717#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003718static void ixgbe_configure(struct ixgbe_adapter *adapter)
3719{
3720 struct net_device *netdev = adapter->netdev;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003721 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07003722 int i;
3723
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08003724#ifdef CONFIG_IXGBE_DCB
Alexander Duyck67ebd792010-08-19 13:34:04 +00003725 ixgbe_configure_dcb(adapter);
Alexander Duyck2f90b862008-11-20 20:52:10 -08003726#endif
Auke Kok9a799d72007-09-15 14:07:45 -07003727
Jesse Grossf62bbb52010-10-20 13:56:10 +00003728 ixgbe_set_rx_mode(netdev);
3729 ixgbe_restore_vlan(adapter);
3730
Yi Zoueacd73f2009-05-13 13:11:06 +00003731#ifdef IXGBE_FCOE
3732 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
3733 ixgbe_configure_fcoe(adapter);
3734
3735#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003736 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
3737 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00003738 adapter->tx_ring[i]->atr_sample_rate =
Joe Perchese8e9f692010-09-07 21:34:53 +00003739 adapter->atr_sample_rate;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003740 ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc);
3741 } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) {
3742 ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc);
3743 }
Alexander Duyck933d41f2010-09-07 21:34:29 +00003744 ixgbe_configure_virtualization(adapter);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00003745
Auke Kok9a799d72007-09-15 14:07:45 -07003746 ixgbe_configure_tx(adapter);
3747 ixgbe_configure_rx(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07003748}
3749
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003750static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw)
3751{
3752 switch (hw->phy.type) {
3753 case ixgbe_phy_sfp_avago:
3754 case ixgbe_phy_sfp_ftl:
3755 case ixgbe_phy_sfp_intel:
3756 case ixgbe_phy_sfp_unknown:
Don Skidmoreea0a04d2010-05-18 16:00:13 +00003757 case ixgbe_phy_sfp_passive_tyco:
3758 case ixgbe_phy_sfp_passive_unknown:
3759 case ixgbe_phy_sfp_active_unknown:
3760 case ixgbe_phy_sfp_ftl_active:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003761 return true;
3762 default:
3763 return false;
3764 }
3765}
3766
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003767/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003768 * ixgbe_sfp_link_config - set up SFP+ link
3769 * @adapter: pointer to private adapter struct
3770 **/
3771static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter)
3772{
3773 struct ixgbe_hw *hw = &adapter->hw;
3774
3775 if (hw->phy.multispeed_fiber) {
3776 /*
3777 * In multispeed fiber setups, the device may not have
3778 * had a physical connection when the driver loaded.
3779 * If that's the case, the initial link configuration
3780 * couldn't get the MAC into 10G or 1G mode, so we'll
3781 * never have a link status change interrupt fire.
3782 * We need to try and force an autonegotiation
3783 * session, then bring up link.
3784 */
Andy Gospodarek4c7e6042011-02-17 01:13:13 -08003785 if (hw->mac.ops.setup_sfp)
3786 hw->mac.ops.setup_sfp(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003787 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
3788 schedule_work(&adapter->multispeed_fiber_task);
3789 } else {
3790 /*
3791 * Direct Attach Cu and non-multispeed fiber modules
3792 * still need to be configured properly prior to
3793 * attempting link.
3794 */
3795 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK))
3796 schedule_work(&adapter->sfp_config_module_task);
3797 }
3798}
3799
3800/**
3801 * ixgbe_non_sfp_link_config - set up non-SFP+ link
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003802 * @hw: pointer to private hardware struct
3803 *
3804 * Returns 0 on success, negative on failure
3805 **/
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003806static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw)
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003807{
3808 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003809 bool negotiation, link_up = false;
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003810 u32 ret = IXGBE_ERR_LINK_SETUP;
3811
3812 if (hw->mac.ops.check_link)
3813 ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false);
3814
3815 if (ret)
3816 goto link_cfg_out;
3817
Emil Tantilov0b0c2b32011-02-26 06:40:16 +00003818 autoneg = hw->phy.autoneg_advertised;
3819 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Joe Perchese8e9f692010-09-07 21:34:53 +00003820 ret = hw->mac.ops.get_link_capabilities(hw, &autoneg,
3821 &negotiation);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003822 if (ret)
3823 goto link_cfg_out;
3824
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00003825 if (hw->mac.ops.setup_link)
3826 ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003827link_cfg_out:
3828 return ret;
3829}
3830
Alexander Duycka34bcff2010-08-19 13:39:20 +00003831static void ixgbe_setup_gpie(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07003832{
Auke Kok9a799d72007-09-15 14:07:45 -07003833 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003834 u32 gpie = 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003835
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003836 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
Alexander Duycka34bcff2010-08-19 13:39:20 +00003837 gpie = IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_PBA_SUPPORT |
3838 IXGBE_GPIE_OCD;
3839 gpie |= IXGBE_GPIE_EIAME;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003840 /*
3841 * use EIAM to auto-mask when MSI-X interrupt is asserted
3842 * this saves a register write for every interrupt
3843 */
3844 switch (hw->mac.type) {
3845 case ixgbe_mac_82598EB:
3846 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
3847 break;
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003848 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08003849 case ixgbe_mac_X540:
3850 default:
Jesse Brandeburg9b471442009-12-03 11:33:54 +00003851 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF);
3852 IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF);
3853 break;
3854 }
3855 } else {
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003856 /* legacy interrupts, use EIAM to auto-mask when reading EICR,
3857 * specifically only auto mask tx and rx interrupts */
3858 IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07003859 }
3860
Alexander Duycka34bcff2010-08-19 13:39:20 +00003861 /* XXX: to interrupt immediately for EICS writes, enable this */
3862 /* gpie |= IXGBE_GPIE_EIMEN; */
3863
3864 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
3865 gpie &= ~IXGBE_GPIE_VTMODE_MASK;
3866 gpie |= IXGBE_GPIE_VTMODE_64;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07003867 }
3868
Alexander Duycka34bcff2010-08-19 13:39:20 +00003869 /* Enable fan failure interrupt */
3870 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE)
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003871 gpie |= IXGBE_SDP1_GPIEN;
Jesse Brandeburg0befdb32008-10-31 00:46:40 -07003872
Don Skidmore2698b202011-04-13 07:01:52 +00003873 if (hw->mac.type == ixgbe_mac_82599EB) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003874 gpie |= IXGBE_SDP1_GPIEN;
3875 gpie |= IXGBE_SDP2_GPIEN;
Don Skidmore2698b202011-04-13 07:01:52 +00003876 }
Alexander Duycka34bcff2010-08-19 13:39:20 +00003877
3878 IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie);
3879}
3880
3881static int ixgbe_up_complete(struct ixgbe_adapter *adapter)
3882{
3883 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003884 int err;
Alexander Duycka34bcff2010-08-19 13:39:20 +00003885 u32 ctrl_ext;
3886
3887 ixgbe_get_hw_control(adapter);
3888 ixgbe_setup_gpie(adapter);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003889
Auke Kok9a799d72007-09-15 14:07:45 -07003890 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
3891 ixgbe_configure_msix(adapter);
3892 else
3893 ixgbe_configure_msi_and_legacy(adapter);
3894
Don Skidmorec6ecf392010-12-03 03:31:51 +00003895 /* enable the optics for both mult-speed fiber and 82599 SFP+ fiber */
3896 if (hw->mac.ops.enable_tx_laser &&
3897 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00003898 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00003899 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00003900 hw->mac.ops.enable_tx_laser(hw);
3901
Auke Kok9a799d72007-09-15 14:07:45 -07003902 clear_bit(__IXGBE_DOWN, &adapter->state);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003903 ixgbe_napi_enable_all(adapter);
3904
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003905 if (ixgbe_is_sfp(hw)) {
3906 ixgbe_sfp_link_config(adapter);
3907 } else {
3908 err = ixgbe_non_sfp_link_config(hw);
3909 if (err)
3910 e_err(probe, "link_config FAILED %d\n", err);
3911 }
3912
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08003913 /* clear any pending interrupts, may auto mask */
3914 IXGBE_READ_REG(hw, IXGBE_EICR);
Emil Tantilov6af3b9e2010-09-29 21:35:23 +00003915 ixgbe_irq_enable(adapter, true, true);
Auke Kok9a799d72007-09-15 14:07:45 -07003916
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003917 /*
Don Skidmorebf069c92009-05-07 10:39:54 +00003918 * If this adapter has a fan, check to see if we had a failure
3919 * before we enabled the interrupt.
3920 */
3921 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
3922 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
3923 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00003924 e_crit(drv, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00003925 }
3926
3927 /*
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003928 * For hot-pluggable SFP+ devices, a new SFP+ module may have
Don Skidmore19343de2009-07-02 12:50:31 +00003929 * arrived before interrupts were enabled but after probe. Such
3930 * devices wouldn't have their type identified yet. We need to
3931 * kick off the SFP+ module setup first, then try to bring up link.
PJ Waskiewicze8e26352009-02-27 15:45:05 +00003932 * If we're not hot-pluggable SFP+, we just need to configure link
3933 * and bring it up.
3934 */
Emil Tantilov21cc5b42011-02-12 10:52:07 +00003935 if (hw->phy.type == ixgbe_phy_none)
Alexander Duyck73c4b7c2010-11-16 19:26:57 -08003936 schedule_work(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jr0ecc0612009-02-06 21:46:54 -08003937
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003938 /* enable transmits */
Alexander Duyck477de6e2010-08-19 13:38:11 +00003939 netif_tx_start_all_queues(adapter->netdev);
Peter P Waskiewicz Jr1da100b2009-01-19 16:55:03 -08003940
Auke Kok9a799d72007-09-15 14:07:45 -07003941 /* bring the link up in the watchdog, this could race with our first
3942 * link up interrupt but shouldn't be a problem */
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07003943 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
3944 adapter->link_check_timeout = jiffies;
Auke Kok9a799d72007-09-15 14:07:45 -07003945 mod_timer(&adapter->watchdog_timer, jiffies);
Greg Rosec9205692010-01-22 22:46:22 +00003946
3947 /* Set PF Reset Done bit so PF/VF Mail Ops can work */
3948 ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT);
3949 ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD;
3950 IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext);
3951
Auke Kok9a799d72007-09-15 14:07:45 -07003952 return 0;
3953}
3954
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003955void ixgbe_reinit_locked(struct ixgbe_adapter *adapter)
3956{
3957 WARN_ON(in_interrupt());
3958 while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state))
Don Skidmore032b4322011-03-18 09:32:53 +00003959 usleep_range(1000, 2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003960 ixgbe_down(adapter);
Greg Rose5809a1a2010-03-24 09:36:08 +00003961 /*
3962 * If SR-IOV enabled then wait a bit before bringing the adapter
3963 * back up to give the VFs time to respond to the reset. The
3964 * two second wait is based upon the watchdog timer cycle in
3965 * the VF driver.
3966 */
3967 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
3968 msleep(2000);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08003969 ixgbe_up(adapter);
3970 clear_bit(__IXGBE_RESETTING, &adapter->state);
3971}
3972
Auke Kok9a799d72007-09-15 14:07:45 -07003973int ixgbe_up(struct ixgbe_adapter *adapter)
3974{
3975 /* hardware has been reset, we need to reload some things */
3976 ixgbe_configure(adapter);
3977
3978 return ixgbe_up_complete(adapter);
3979}
3980
3981void ixgbe_reset(struct ixgbe_adapter *adapter)
3982{
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07003983 struct ixgbe_hw *hw = &adapter->hw;
Don Skidmore8ca783a2009-05-26 20:40:47 -07003984 int err;
3985
3986 err = hw->mac.ops.init_hw(hw);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003987 switch (err) {
3988 case 0:
3989 case IXGBE_ERR_SFP_NOT_PRESENT:
3990 break;
3991 case IXGBE_ERR_MASTER_REQUESTS_PENDING:
Emil Tantilov849c4542010-06-03 16:53:41 +00003992 e_dev_err("master disable timed out\n");
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00003993 break;
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00003994 case IXGBE_ERR_EEPROM_VERSION:
3995 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00003996 e_dev_warn("This device is a pre-production adapter/LOM. "
3997 "Please be aware there may be issuesassociated with "
3998 "your hardware. If you are experiencing problems "
3999 "please contact your Intel or hardware "
4000 "representative who provided you with this "
4001 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00004002 break;
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004003 default:
Emil Tantilov849c4542010-06-03 16:53:41 +00004004 e_dev_err("Hardware Error: %d\n", err);
Peter P Waskiewicz Jrda4dd0f2009-06-04 11:10:35 +00004005 }
Auke Kok9a799d72007-09-15 14:07:45 -07004006
4007 /* reprogram the RAR[0] in case user changed it. */
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004008 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
4009 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07004010}
4011
Auke Kok9a799d72007-09-15 14:07:45 -07004012/**
4013 * ixgbe_clean_rx_ring - Free Rx Buffers per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07004014 * @rx_ring: ring to free buffers from
4015 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004016static void ixgbe_clean_rx_ring(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004017{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004018 struct device *dev = rx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07004019 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004020 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004021
Alexander Duyck84418e32010-08-19 13:40:54 +00004022 /* ring already cleared, nothing to do */
4023 if (!rx_ring->rx_buffer_info)
4024 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004025
Alexander Duyck84418e32010-08-19 13:40:54 +00004026 /* Free all the Rx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004027 for (i = 0; i < rx_ring->count; i++) {
4028 struct ixgbe_rx_buffer *rx_buffer_info;
4029
4030 rx_buffer_info = &rx_ring->rx_buffer_info[i];
4031 if (rx_buffer_info->dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004032 dma_unmap_single(rx_ring->dev, rx_buffer_info->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004033 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004034 DMA_FROM_DEVICE);
Auke Kok9a799d72007-09-15 14:07:45 -07004035 rx_buffer_info->dma = 0;
4036 }
4037 if (rx_buffer_info->skb) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00004038 struct sk_buff *skb = rx_buffer_info->skb;
Auke Kok9a799d72007-09-15 14:07:45 -07004039 rx_buffer_info->skb = NULL;
Alexander Duyckf8212f92009-04-27 22:42:37 +00004040 do {
4041 struct sk_buff *this = skb;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004042 if (IXGBE_RSC_CB(this)->delay_unmap) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004043 dma_unmap_single(dev,
Nick Nunley1b507732010-04-27 13:10:27 +00004044 IXGBE_RSC_CB(this)->dma,
Joe Perchese8e9f692010-09-07 21:34:53 +00004045 rx_ring->rx_buf_len,
Nick Nunley1b507732010-04-27 13:10:27 +00004046 DMA_FROM_DEVICE);
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004047 IXGBE_RSC_CB(this)->dma = 0;
Mallikarjuna R Chilakalae8171aa2010-05-13 17:33:21 +00004048 IXGBE_RSC_CB(skb)->delay_unmap = false;
Mallikarjuna R Chilakalafd3686a2010-03-19 04:41:33 +00004049 }
Alexander Duyckf8212f92009-04-27 22:42:37 +00004050 skb = skb->prev;
4051 dev_kfree_skb(this);
4052 } while (skb);
Auke Kok9a799d72007-09-15 14:07:45 -07004053 }
4054 if (!rx_buffer_info->page)
4055 continue;
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004056 if (rx_buffer_info->page_dma) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004057 dma_unmap_page(dev, rx_buffer_info->page_dma,
Nick Nunley1b507732010-04-27 13:10:27 +00004058 PAGE_SIZE / 2, DMA_FROM_DEVICE);
Jesse Brandeburg4f57ca62009-06-30 11:44:56 +00004059 rx_buffer_info->page_dma = 0;
4060 }
Auke Kok9a799d72007-09-15 14:07:45 -07004061 put_page(rx_buffer_info->page);
4062 rx_buffer_info->page = NULL;
Jesse Brandeburg762f4c52008-09-11 19:58:43 -07004063 rx_buffer_info->page_offset = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004064 }
4065
4066 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
4067 memset(rx_ring->rx_buffer_info, 0, size);
4068
4069 /* Zero out the descriptor ring */
4070 memset(rx_ring->desc, 0, rx_ring->size);
4071
4072 rx_ring->next_to_clean = 0;
4073 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004074}
4075
4076/**
4077 * ixgbe_clean_tx_ring - Free Tx Buffers
Auke Kok9a799d72007-09-15 14:07:45 -07004078 * @tx_ring: ring to be cleaned
4079 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004080static void ixgbe_clean_tx_ring(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07004081{
4082 struct ixgbe_tx_buffer *tx_buffer_info;
4083 unsigned long size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004084 u16 i;
Auke Kok9a799d72007-09-15 14:07:45 -07004085
Alexander Duyck84418e32010-08-19 13:40:54 +00004086 /* ring already cleared, nothing to do */
4087 if (!tx_ring->tx_buffer_info)
4088 return;
Auke Kok9a799d72007-09-15 14:07:45 -07004089
Alexander Duyck84418e32010-08-19 13:40:54 +00004090 /* Free all the Tx ring sk_buffs */
Auke Kok9a799d72007-09-15 14:07:45 -07004091 for (i = 0; i < tx_ring->count; i++) {
4092 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004093 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Auke Kok9a799d72007-09-15 14:07:45 -07004094 }
4095
4096 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
4097 memset(tx_ring->tx_buffer_info, 0, size);
4098
4099 /* Zero out the descriptor ring */
4100 memset(tx_ring->desc, 0, tx_ring->size);
4101
4102 tx_ring->next_to_use = 0;
4103 tx_ring->next_to_clean = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004104}
4105
4106/**
Auke Kok9a799d72007-09-15 14:07:45 -07004107 * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues
4108 * @adapter: board private structure
4109 **/
4110static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter)
4111{
4112 int i;
4113
4114 for (i = 0; i < adapter->num_rx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004115 ixgbe_clean_rx_ring(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07004116}
4117
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004118/**
4119 * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues
4120 * @adapter: board private structure
4121 **/
4122static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter)
4123{
4124 int i;
4125
4126 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004127 ixgbe_clean_tx_ring(adapter->tx_ring[i]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004128}
4129
Auke Kok9a799d72007-09-15 14:07:45 -07004130void ixgbe_down(struct ixgbe_adapter *adapter)
4131{
4132 struct net_device *netdev = adapter->netdev;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004133 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07004134 u32 rxctrl;
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004135 u32 txdctl;
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004136 int i;
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004137 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Auke Kok9a799d72007-09-15 14:07:45 -07004138
4139 /* signal that we are down to the interrupt handler */
4140 set_bit(__IXGBE_DOWN, &adapter->state);
4141
Greg Rose767081a2010-01-22 22:46:40 +00004142 /* disable receive for all VFs and wait one second */
4143 if (adapter->num_vfs) {
Greg Rose767081a2010-01-22 22:46:40 +00004144 /* ping all the active vfs to let them know we are going down */
4145 ixgbe_ping_all_vfs(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004146
Greg Rose767081a2010-01-22 22:46:40 +00004147 /* Disable all VFTE/VFRE TX/RX */
4148 ixgbe_disable_tx_rx(adapter);
Greg Rose581d1aa2010-03-24 09:36:27 +00004149
4150 /* Mark all the VFs as inactive */
4151 for (i = 0 ; i < adapter->num_vfs; i++)
4152 adapter->vfinfo[i].clear_to_send = 0;
Greg Rose767081a2010-01-22 22:46:40 +00004153 }
4154
Auke Kok9a799d72007-09-15 14:07:45 -07004155 /* disable receives */
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004156 rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL);
4157 IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN);
Auke Kok9a799d72007-09-15 14:07:45 -07004158
Yi Zou2d39d572011-01-06 14:29:56 +00004159 /* disable all enabled rx queues */
4160 for (i = 0; i < adapter->num_rx_queues; i++)
4161 /* this call also flushes the previous write */
4162 ixgbe_disable_rx_queue(adapter, adapter->rx_ring[i]);
4163
Don Skidmore032b4322011-03-18 09:32:53 +00004164 usleep_range(10000, 20000);
Auke Kok9a799d72007-09-15 14:07:45 -07004165
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004166 netif_tx_stop_all_queues(netdev);
4167
Don Skidmore0a1f87c2009-09-18 09:45:43 +00004168 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
4169 del_timer_sync(&adapter->sfp_timer);
Auke Kok9a799d72007-09-15 14:07:45 -07004170 del_timer_sync(&adapter->watchdog_timer);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07004171 cancel_work_sync(&adapter->watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07004172
John Fastabendc0dfb902010-04-27 02:13:39 +00004173 netif_carrier_off(netdev);
4174 netif_tx_disable(netdev);
4175
4176 ixgbe_irq_disable(adapter);
4177
4178 ixgbe_napi_disable_all(adapter);
4179
Peter Waskiewiczb25ebfd2010-10-05 01:27:49 +00004180 /* Cleanup the affinity_hint CPU mask memory and callback */
4181 for (i = 0; i < num_q_vectors; i++) {
4182 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
4183 /* clear the affinity_mask in the IRQ descriptor */
4184 irq_set_affinity_hint(adapter->msix_entries[i]. vector, NULL);
4185 /* release the CPU mask memory */
4186 free_cpumask_var(q_vector->affinity_mask);
4187 }
4188
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004189 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4190 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
4191 cancel_work_sync(&adapter->fdir_reinit_task);
4192
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07004193 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
4194 cancel_work_sync(&adapter->check_overtemp_task);
4195
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004196 /* disable transmits in the hardware now that interrupts are off */
4197 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004198 u8 reg_idx = adapter->tx_ring[i]->reg_idx;
4199 txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(reg_idx));
4200 IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(reg_idx),
Joe Perchese8e9f692010-09-07 21:34:53 +00004201 (txdctl & ~IXGBE_TXDCTL_ENABLE));
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004202 }
PJ Waskiewicz88512532009-03-13 22:15:10 +00004203 /* Disable the Tx DMA engine on 82599 */
Alexander Duyckbd508172010-11-16 19:27:03 -08004204 switch (hw->mac.type) {
4205 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08004206 case ixgbe_mac_X540:
PJ Waskiewicz88512532009-03-13 22:15:10 +00004207 IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL,
Joe Perchese8e9f692010-09-07 21:34:53 +00004208 (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) &
4209 ~IXGBE_DMATXCTL_TE));
Alexander Duyckbd508172010-11-16 19:27:03 -08004210 break;
4211 default:
4212 break;
4213 }
Jesse Brandeburg7f821872008-09-11 20:00:16 -07004214
Paul Larson6f4a0e42008-06-24 17:00:56 -07004215 if (!pci_channel_offline(adapter->pdev))
4216 ixgbe_reset(adapter);
Don Skidmorec6ecf392010-12-03 03:31:51 +00004217
4218 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
4219 if (hw->mac.ops.disable_tx_laser &&
4220 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00004221 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00004222 (hw->mac.type == ixgbe_mac_82599EB))))
4223 hw->mac.ops.disable_tx_laser(hw);
4224
Auke Kok9a799d72007-09-15 14:07:45 -07004225 ixgbe_clean_all_tx_rings(adapter);
4226 ixgbe_clean_all_rx_rings(adapter);
4227
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004228#ifdef CONFIG_IXGBE_DCA
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004229 /* since we reset the hardware DCA settings were cleared */
Alexander Duycke35ec122009-05-21 13:07:12 +00004230 ixgbe_setup_dca(adapter);
Jesse Brandeburg96b0e0f2008-08-26 04:27:21 -07004231#endif
Auke Kok9a799d72007-09-15 14:07:45 -07004232}
4233
Auke Kok9a799d72007-09-15 14:07:45 -07004234/**
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004235 * ixgbe_poll - NAPI Rx polling callback
4236 * @napi: structure for representing this polling device
4237 * @budget: how many packets driver is allowed to clean
4238 *
4239 * This function is used for legacy and MSI, NAPI mode
Auke Kok9a799d72007-09-15 14:07:45 -07004240 **/
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004241static int ixgbe_poll(struct napi_struct *napi, int budget)
Auke Kok9a799d72007-09-15 14:07:45 -07004242{
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004243 struct ixgbe_q_vector *q_vector =
Joe Perchese8e9f692010-09-07 21:34:53 +00004244 container_of(napi, struct ixgbe_q_vector, napi);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004245 struct ixgbe_adapter *adapter = q_vector->adapter;
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004246 int tx_clean_complete, work_done = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07004247
Jeff Garzik5dd2d332008-10-16 05:09:31 -04004248#ifdef CONFIG_IXGBE_DCA
Alexander Duyck33cf09c2010-11-16 19:26:55 -08004249 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED)
4250 ixgbe_update_dca(q_vector);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08004251#endif
4252
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004253 tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]);
4254 ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget);
Auke Kok9a799d72007-09-15 14:07:45 -07004255
Jesse Brandeburg9a1a69ad2009-03-13 22:14:10 +00004256 if (!tx_clean_complete)
David S. Millerd2c7ddd2008-01-15 22:43:24 -08004257 work_done = budget;
4258
David S. Miller53e52c72008-01-07 21:06:12 -08004259 /* If budget not fully consumed, exit the polling mode */
4260 if (work_done < budget) {
Ben Hutchings288379f2009-01-19 16:43:59 -08004261 napi_complete(napi);
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004262 if (adapter->rx_itr_setting & 1)
Ayyappan Veeraiyanf494e8f2008-03-03 15:03:57 -08004263 ixgbe_set_itr(adapter);
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004264 if (!test_bit(__IXGBE_DOWN, &adapter->state))
Nelson, Shannon835462f2009-04-27 22:42:54 +00004265 ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE);
Auke Kok9a799d72007-09-15 14:07:45 -07004266 }
Auke Kok9a799d72007-09-15 14:07:45 -07004267 return work_done;
4268}
4269
4270/**
4271 * ixgbe_tx_timeout - Respond to a Tx Hang
4272 * @netdev: network interface device structure
4273 **/
4274static void ixgbe_tx_timeout(struct net_device *netdev)
4275{
4276 struct ixgbe_adapter *adapter = netdev_priv(netdev);
4277
John Fastabendc84d3242010-11-16 19:27:12 -08004278 adapter->tx_timeout_count++;
4279
Auke Kok9a799d72007-09-15 14:07:45 -07004280 /* Do the reset outside of interrupt context */
4281 schedule_work(&adapter->reset_task);
4282}
4283
4284static void ixgbe_reset_task(struct work_struct *work)
4285{
4286 struct ixgbe_adapter *adapter;
4287 adapter = container_of(work, struct ixgbe_adapter, reset_task);
4288
Alexander Duyck2f90b862008-11-20 20:52:10 -08004289 /* If we're already down or resetting, just bail */
4290 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
4291 test_bit(__IXGBE_RESETTING, &adapter->state))
4292 return;
4293
Taku Izumidcd79ae2010-04-27 14:39:53 +00004294 ixgbe_dump(adapter);
4295 netdev_err(adapter->netdev, "Reset adapter\n");
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08004296 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004297}
4298
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004299/**
4300 * ixgbe_set_rss_queues: Allocate queues for RSS
4301 * @adapter: board private structure to initialize
4302 *
4303 * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try
4304 * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU.
4305 *
4306 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004307static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter)
4308{
4309 bool ret = false;
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004310 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS];
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004311
4312 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Jesse Brandeburg0cefafa2009-05-19 09:19:11 +00004313 f->mask = 0xF;
4314 adapter->num_rx_queues = f->indices;
4315 adapter->num_tx_queues = f->indices;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004316 ret = true;
4317 } else {
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004318 ret = false;
4319 }
4320
4321 return ret;
4322}
4323
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004324/**
4325 * ixgbe_set_fdir_queues: Allocate queues for Flow Director
4326 * @adapter: board private structure to initialize
4327 *
4328 * Flow Director is an advanced Rx filter, attempting to get Rx flows back
4329 * to the original CPU that initiated the Tx session. This runs in addition
4330 * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the
4331 * Rx load across CPUs using RSS.
4332 *
4333 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004334static inline bool ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004335{
4336 bool ret = false;
4337 struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR];
4338
4339 f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices);
4340 f_fdir->mask = 0;
4341
4342 /* Flow Director must have RSS enabled */
4343 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4344 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
4345 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) {
4346 adapter->num_tx_queues = f_fdir->indices;
4347 adapter->num_rx_queues = f_fdir->indices;
4348 ret = true;
4349 } else {
4350 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4351 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4352 }
4353 return ret;
4354}
4355
Yi Zou0331a832009-05-17 12:33:52 +00004356#ifdef IXGBE_FCOE
4357/**
4358 * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE)
4359 * @adapter: board private structure to initialize
4360 *
4361 * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges.
4362 * The ring feature mask is not used as a mask for FCoE, as it can take any 8
4363 * rx queues out of the max number of rx queues, instead, it is used as the
4364 * index of the first rx queue used by FCoE.
4365 *
4366 **/
4367static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter)
4368{
Yi Zou0331a832009-05-17 12:33:52 +00004369 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
4370
John Fastabende5b64632011-03-08 03:44:52 +00004371 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4372 return false;
4373
4374 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
4375#ifdef CONFIG_IXGBE_DCB
4376 int tc;
4377 struct net_device *dev = adapter->netdev;
4378
4379 tc = netdev_get_prio_tc_map(dev, adapter->fcoe.up);
4380 f->indices = dev->tc_to_txq[tc].count;
4381 f->mask = dev->tc_to_txq[tc].offset;
4382#endif
4383 } else {
4384 f->indices = min((int)num_online_cpus(), f->indices);
4385
Yi Zou8de8b2e2009-09-03 14:55:50 +00004386 adapter->num_rx_queues = 1;
4387 adapter->num_tx_queues = 1;
John Fastabende5b64632011-03-08 03:44:52 +00004388
Yi Zou0331a832009-05-17 12:33:52 +00004389 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00004390 e_info(probe, "FCoE enabled with RSS\n");
Yi Zou8faa2a72009-07-09 02:29:50 +00004391 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4392 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4393 ixgbe_set_fdir_queues(adapter);
4394 else
4395 ixgbe_set_rss_queues(adapter);
Yi Zou0331a832009-05-17 12:33:52 +00004396 }
4397 /* adding FCoE rx rings to the end */
4398 f->mask = adapter->num_rx_queues;
4399 adapter->num_rx_queues += f->indices;
Yi Zou8de8b2e2009-09-03 14:55:50 +00004400 adapter->num_tx_queues += f->indices;
Yi Zou0331a832009-05-17 12:33:52 +00004401 }
4402
John Fastabende5b64632011-03-08 03:44:52 +00004403 return true;
4404}
4405#endif /* IXGBE_FCOE */
4406
4407#ifdef CONFIG_IXGBE_DCB
4408static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter)
4409{
4410 bool ret = false;
4411 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB];
4412 int i, q;
4413
4414 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4415 return ret;
4416
4417 f->indices = 0;
4418 for (i = 0; i < MAX_TRAFFIC_CLASS; i++) {
4419 q = min((int)num_online_cpus(), MAX_TRAFFIC_CLASS);
4420 f->indices += q;
4421 }
4422
4423 f->mask = 0x7 << 3;
4424 adapter->num_rx_queues = f->indices;
4425 adapter->num_tx_queues = f->indices;
4426 ret = true;
4427
4428#ifdef IXGBE_FCOE
4429 /* FCoE enabled queues require special configuration done through
4430 * configure_fcoe() and others. Here we map FCoE indices onto the
4431 * DCB queue pairs allowing FCoE to own configuration later.
4432 */
4433 ixgbe_set_fcoe_queues(adapter);
4434#endif
4435
Yi Zou0331a832009-05-17 12:33:52 +00004436 return ret;
4437}
John Fastabende5b64632011-03-08 03:44:52 +00004438#endif
Yi Zou0331a832009-05-17 12:33:52 +00004439
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004440/**
4441 * ixgbe_set_sriov_queues: Allocate queues for IOV use
4442 * @adapter: board private structure to initialize
4443 *
4444 * IOV doesn't actually use anything, so just NAK the
4445 * request for now and let the other queue routines
4446 * figure out what to do.
4447 */
4448static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter)
4449{
4450 return false;
4451}
4452
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004453/*
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004454 * ixgbe_set_num_queues: Allocate queues for device, feature dependent
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004455 * @adapter: board private structure to initialize
4456 *
4457 * This is the top level queue allocation routine. The order here is very
4458 * important, starting with the "most" number of features turned on at once,
4459 * and ending with the smallest set of features. This way large combinations
4460 * can be allocated if they're turned on, and smaller combinations are the
4461 * fallthrough conditions.
4462 *
4463 **/
Ben Hutchings847f53f2010-09-27 08:28:56 +00004464static int ixgbe_set_num_queues(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004465{
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004466 /* Start with base case */
4467 adapter->num_rx_queues = 1;
4468 adapter->num_tx_queues = 1;
4469 adapter->num_rx_pools = adapter->num_rx_queues;
4470 adapter->num_rx_queues_per_pool = 1;
4471
4472 if (ixgbe_set_sriov_queues(adapter))
Ben Hutchings847f53f2010-09-27 08:28:56 +00004473 goto done;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004474
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004475#ifdef CONFIG_IXGBE_DCB
4476 if (ixgbe_set_dcb_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004477 goto done;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004478
4479#endif
John Fastabende5b64632011-03-08 03:44:52 +00004480#ifdef IXGBE_FCOE
4481 if (ixgbe_set_fcoe_queues(adapter))
4482 goto done;
4483
4484#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004485 if (ixgbe_set_fdir_queues(adapter))
4486 goto done;
4487
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004488 if (ixgbe_set_rss_queues(adapter))
Wu Fengguangaf22ab12009-04-14 21:54:07 -07004489 goto done;
4490
4491 /* fallback to base case */
4492 adapter->num_rx_queues = 1;
4493 adapter->num_tx_queues = 1;
4494
4495done:
Ben Hutchings847f53f2010-09-27 08:28:56 +00004496 /* Notify the stack of the (possibly) reduced queue counts. */
John Fastabendf0796d52010-07-01 13:21:57 +00004497 netif_set_real_num_tx_queues(adapter->netdev, adapter->num_tx_queues);
Ben Hutchings847f53f2010-09-27 08:28:56 +00004498 return netif_set_real_num_rx_queues(adapter->netdev,
4499 adapter->num_rx_queues);
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004500}
4501
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004502static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00004503 int vectors)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004504{
4505 int err, vector_threshold;
4506
4507 /* We'll want at least 3 (vector_threshold):
4508 * 1) TxQ[0] Cleanup
4509 * 2) RxQ[0] Cleanup
4510 * 3) Other (Link Status Change, etc.)
4511 * 4) TCP Timer (optional)
4512 */
4513 vector_threshold = MIN_MSIX_COUNT;
4514
4515 /* The more we get, the more we will assign to Tx/Rx Cleanup
4516 * for the separate queues...where Rx Cleanup >= Tx Cleanup.
4517 * Right now, we simply care about how many we'll get; we'll
4518 * set them up later while requesting irq's.
4519 */
4520 while (vectors >= vector_threshold) {
4521 err = pci_enable_msix(adapter->pdev, adapter->msix_entries,
Joe Perchese8e9f692010-09-07 21:34:53 +00004522 vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004523 if (!err) /* Success in acquiring all requested vectors. */
4524 break;
4525 else if (err < 0)
4526 vectors = 0; /* Nasty failure, quit now */
4527 else /* err == number of vectors we should try again with */
4528 vectors = err;
4529 }
4530
4531 if (vectors < vector_threshold) {
4532 /* Can't allocate enough MSI-X interrupts? Oh well.
4533 * This just means we'll go with either a single MSI
4534 * vector or fall back to legacy interrupts.
4535 */
Emil Tantilov849c4542010-06-03 16:53:41 +00004536 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4537 "Unable to allocate MSI-X interrupts\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004538 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
4539 kfree(adapter->msix_entries);
4540 adapter->msix_entries = NULL;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004541 } else {
4542 adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */
Peter P Waskiewicz Jreb7f1392009-02-01 01:18:58 -08004543 /*
4544 * Adjust for only the vectors we'll use, which is minimum
4545 * of max_msix_q_vectors + NON_Q_VECTORS, or the number of
4546 * vectors we were allocated.
4547 */
4548 adapter->num_msix_vectors = min(vectors,
Joe Perchese8e9f692010-09-07 21:34:53 +00004549 adapter->max_msix_q_vectors + NON_Q_VECTORS);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004550 }
4551}
4552
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004553/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004554 * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004555 * @adapter: board private structure to initialize
4556 *
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004557 * Cache the descriptor ring offsets for RSS to the assigned rings.
4558 *
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004559 **/
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004560static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004561{
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004562 int i;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004563
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004564 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
4565 return false;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004566
Alexander Duyck9d6b7582010-11-16 19:27:06 -08004567 for (i = 0; i < adapter->num_rx_queues; i++)
4568 adapter->rx_ring[i]->reg_idx = i;
4569 for (i = 0; i < adapter->num_tx_queues; i++)
4570 adapter->tx_ring[i]->reg_idx = i;
4571
4572 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004573}
4574
4575#ifdef CONFIG_IXGBE_DCB
John Fastabende5b64632011-03-08 03:44:52 +00004576
4577/* ixgbe_get_first_reg_idx - Return first register index associated with ring */
John Fastabendb32c8dc2011-04-12 02:44:55 +00004578static void ixgbe_get_first_reg_idx(struct ixgbe_adapter *adapter, u8 tc,
4579 unsigned int *tx, unsigned int *rx)
John Fastabende5b64632011-03-08 03:44:52 +00004580{
4581 struct net_device *dev = adapter->netdev;
4582 struct ixgbe_hw *hw = &adapter->hw;
4583 u8 num_tcs = netdev_get_num_tc(dev);
4584
4585 *tx = 0;
4586 *rx = 0;
4587
4588 switch (hw->mac.type) {
4589 case ixgbe_mac_82598EB:
4590 *tx = tc << 3;
4591 *rx = tc << 2;
4592 break;
4593 case ixgbe_mac_82599EB:
4594 case ixgbe_mac_X540:
4595 if (num_tcs == 8) {
4596 if (tc < 3) {
4597 *tx = tc << 5;
4598 *rx = tc << 4;
4599 } else if (tc < 5) {
4600 *tx = ((tc + 2) << 4);
4601 *rx = tc << 4;
4602 } else if (tc < num_tcs) {
4603 *tx = ((tc + 8) << 3);
4604 *rx = tc << 4;
4605 }
4606 } else if (num_tcs == 4) {
4607 *rx = tc << 5;
4608 switch (tc) {
4609 case 0:
4610 *tx = 0;
4611 break;
4612 case 1:
4613 *tx = 64;
4614 break;
4615 case 2:
4616 *tx = 96;
4617 break;
4618 case 3:
4619 *tx = 112;
4620 break;
4621 default:
4622 break;
4623 }
4624 }
4625 break;
4626 default:
4627 break;
4628 }
4629}
4630
4631#define IXGBE_MAX_Q_PER_TC (IXGBE_MAX_DCB_INDICES / MAX_TRAFFIC_CLASS)
4632
4633/* ixgbe_setup_tc - routine to configure net_device for multiple traffic
4634 * classes.
4635 *
4636 * @netdev: net device to configure
4637 * @tc: number of traffic classes to enable
4638 */
4639int ixgbe_setup_tc(struct net_device *dev, u8 tc)
4640{
4641 int i;
4642 unsigned int q, offset = 0;
4643
4644 if (!tc) {
4645 netdev_reset_tc(dev);
4646 } else {
John Fastabend24095aa2011-02-23 05:58:03 +00004647 struct ixgbe_adapter *adapter = netdev_priv(dev);
4648
4649 /* Hardware supports up to 8 traffic classes */
4650 if (tc > MAX_TRAFFIC_CLASS || netdev_set_num_tc(dev, tc))
John Fastabende5b64632011-03-08 03:44:52 +00004651 return -EINVAL;
4652
4653 /* Partition Tx queues evenly amongst traffic classes */
4654 for (i = 0; i < tc; i++) {
4655 q = min((int)num_online_cpus(), IXGBE_MAX_Q_PER_TC);
4656 netdev_set_prio_tc_map(dev, i, i);
4657 netdev_set_tc_queue(dev, i, q, offset);
4658 offset += q;
4659 }
John Fastabend24095aa2011-02-23 05:58:03 +00004660
4661 /* This enables multiple traffic class support in the hardware
4662 * which defaults to strict priority transmission by default.
4663 * If traffic classes are already enabled perhaps through DCB
4664 * code path then existing configuration will be used.
4665 */
4666 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED) &&
4667 dev->dcbnl_ops && dev->dcbnl_ops->setdcbx) {
4668 struct ieee_ets ets = {
4669 .prio_tc = {0, 1, 2, 3, 4, 5, 6, 7},
4670 };
4671 u8 mode = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_IEEE;
4672
4673 dev->dcbnl_ops->setdcbx(dev, mode);
4674 dev->dcbnl_ops->ieee_setets(dev, &ets);
4675 }
John Fastabende5b64632011-03-08 03:44:52 +00004676 }
4677 return 0;
4678}
4679
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004680/**
4681 * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB
4682 * @adapter: board private structure to initialize
4683 *
4684 * Cache the descriptor ring offsets for DCB to the assigned rings.
4685 *
4686 **/
4687static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter)
4688{
John Fastabende5b64632011-03-08 03:44:52 +00004689 struct net_device *dev = adapter->netdev;
4690 int i, j, k;
4691 u8 num_tcs = netdev_get_num_tc(dev);
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004692
Alexander Duyckbd508172010-11-16 19:27:03 -08004693 if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED))
4694 return false;
4695
John Fastabende5b64632011-03-08 03:44:52 +00004696 for (i = 0, k = 0; i < num_tcs; i++) {
4697 unsigned int tx_s, rx_s;
4698 u16 count = dev->tc_to_txq[i].count;
4699
4700 ixgbe_get_first_reg_idx(adapter, i, &tx_s, &rx_s);
4701 for (j = 0; j < count; j++, k++) {
4702 adapter->tx_ring[k]->reg_idx = tx_s + j;
4703 adapter->rx_ring[k]->reg_idx = rx_s + j;
4704 adapter->tx_ring[k]->dcb_tc = i;
4705 adapter->rx_ring[k]->dcb_tc = i;
Alexander Duyckbd508172010-11-16 19:27:03 -08004706 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004707 }
John Fastabende5b64632011-03-08 03:44:52 +00004708
4709 return true;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004710}
4711#endif
4712
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004713/**
4714 * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director
4715 * @adapter: board private structure to initialize
4716 *
4717 * Cache the descriptor ring offsets for Flow Director to the assigned rings.
4718 *
4719 **/
Joe Perchese8e9f692010-09-07 21:34:53 +00004720static inline bool ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004721{
4722 int i;
4723 bool ret = false;
4724
4725 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED &&
4726 ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4727 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) {
4728 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004729 adapter->rx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004730 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004731 adapter->tx_ring[i]->reg_idx = i;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004732 ret = true;
4733 }
4734
4735 return ret;
4736}
4737
Yi Zou0331a832009-05-17 12:33:52 +00004738#ifdef IXGBE_FCOE
4739/**
4740 * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE
4741 * @adapter: board private structure to initialize
4742 *
4743 * Cache the descriptor ring offsets for FCoE mode to the assigned rings.
4744 *
4745 */
4746static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter)
4747{
Yi Zou0331a832009-05-17 12:33:52 +00004748 struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE];
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004749 int i;
4750 u8 fcoe_rx_i = 0, fcoe_tx_i = 0;
Yi Zou0331a832009-05-17 12:33:52 +00004751
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004752 if (!(adapter->flags & IXGBE_FLAG_FCOE_ENABLED))
4753 return false;
4754
Alexander Duyckbf29ee62010-11-16 19:27:07 -08004755 if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) {
4756 if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) ||
4757 (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))
4758 ixgbe_cache_ring_fdir(adapter);
4759 else
4760 ixgbe_cache_ring_rss(adapter);
4761
4762 fcoe_rx_i = f->mask;
4763 fcoe_tx_i = f->mask;
4764 }
4765 for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) {
4766 adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i;
4767 adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i;
4768 }
4769 return true;
Yi Zou0331a832009-05-17 12:33:52 +00004770}
4771
4772#endif /* IXGBE_FCOE */
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004773/**
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004774 * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov
4775 * @adapter: board private structure to initialize
4776 *
4777 * SR-IOV doesn't use any descriptor rings but changes the default if
4778 * no other mapping is used.
4779 *
4780 */
4781static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter)
4782{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004783 adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2;
4784 adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004785 if (adapter->num_vfs)
4786 return true;
4787 else
4788 return false;
4789}
4790
4791/**
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004792 * ixgbe_cache_ring_register - Descriptor ring to register mapping
4793 * @adapter: board private structure to initialize
4794 *
4795 * Once we know the feature-set enabled for the device, we'll cache
4796 * the register offset the descriptor ring is assigned to.
4797 *
4798 * Note, the order the various feature calls is important. It must start with
4799 * the "most" features enabled at the same time, then trickle down to the
4800 * least amount of features turned on at once.
4801 **/
4802static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter)
4803{
4804 /* start with default case */
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004805 adapter->rx_ring[0]->reg_idx = 0;
4806 adapter->tx_ring[0]->reg_idx = 0;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004807
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004808 if (ixgbe_cache_ring_sriov(adapter))
4809 return;
4810
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004811#ifdef CONFIG_IXGBE_DCB
4812 if (ixgbe_cache_ring_dcb(adapter))
4813 return;
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004814#endif
John Fastabende5b64632011-03-08 03:44:52 +00004815
4816#ifdef IXGBE_FCOE
4817 if (ixgbe_cache_ring_fcoe(adapter))
4818 return;
4819#endif /* IXGBE_FCOE */
4820
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004821 if (ixgbe_cache_ring_fdir(adapter))
4822 return;
4823
Peter P Waskiewicz Jrbc971142009-02-05 23:53:59 -08004824 if (ixgbe_cache_ring_rss(adapter))
4825 return;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004826}
4827
Auke Kok9a799d72007-09-15 14:07:45 -07004828/**
4829 * ixgbe_alloc_queues - Allocate memory for all rings
4830 * @adapter: board private structure to initialize
4831 *
4832 * We allocate one ring per queue at run-time since we don't know the
Jesse Brandeburg4df10462009-03-13 22:15:31 +00004833 * number of queues at compile-time. The polling_netdev array is
4834 * intended for Multiqueue, but should work fine with a single queue.
Auke Kok9a799d72007-09-15 14:07:45 -07004835 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08004836static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter)
Auke Kok9a799d72007-09-15 14:07:45 -07004837{
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004838 int rx = 0, tx = 0, nid = adapter->node;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004839
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004840 if (nid < 0 || !node_online(nid))
4841 nid = first_online_node;
4842
4843 for (; tx < adapter->num_tx_queues; tx++) {
4844 struct ixgbe_ring *ring;
4845
4846 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004847 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004848 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004849 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004850 goto err_allocation;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004851 ring->count = adapter->tx_ring_count;
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004852 ring->queue_index = tx;
4853 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004854 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004855 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004856
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004857 adapter->tx_ring[tx] = ring;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004858 }
Jesse Brandeburgb9804972008-09-11 20:00:29 -07004859
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004860 for (; rx < adapter->num_rx_queues; rx++) {
4861 struct ixgbe_ring *ring;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004862
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004863 ring = kzalloc_node(sizeof(*ring), GFP_KERNEL, nid);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004864 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004865 ring = kzalloc(sizeof(*ring), GFP_KERNEL);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004866 if (!ring)
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004867 goto err_allocation;
4868 ring->count = adapter->rx_ring_count;
4869 ring->queue_index = rx;
4870 ring->numa_node = nid;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08004871 ring->dev = &adapter->pdev->dev;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08004872 ring->netdev = adapter->netdev;
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00004873
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004874 adapter->rx_ring[rx] = ring;
Auke Kok9a799d72007-09-15 14:07:45 -07004875 }
4876
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004877 ixgbe_cache_ring_register(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07004878
4879 return 0;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004880
Eric Dumazete2ddeba2010-11-16 19:27:18 -08004881err_allocation:
4882 while (tx)
4883 kfree(adapter->tx_ring[--tx]);
4884
4885 while (rx)
4886 kfree(adapter->rx_ring[--rx]);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004887 return -ENOMEM;
4888}
4889
4890/**
4891 * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported
4892 * @adapter: board private structure to initialize
4893 *
4894 * Attempt to configure the interrupts using the best available
4895 * capabilities of the hardware and the kernel.
4896 **/
Al Virofeea6a52008-11-27 15:34:07 -08004897static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004898{
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004899 struct ixgbe_hw *hw = &adapter->hw;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004900 int err = 0;
4901 int vector, v_budget;
4902
4903 /*
4904 * It's easy to be greedy for MSI-X vectors, but it really
4905 * doesn't do us much good if we have a lot more vectors
4906 * than CPU's. So let's be conservative and only ask for
PJ Waskiewicz342bde12009-11-12 23:50:43 +00004907 * (roughly) the same number of vectors as there are CPU's.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004908 */
4909 v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues,
Joe Perchese8e9f692010-09-07 21:34:53 +00004910 (int)num_online_cpus()) + NON_Q_VECTORS;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004911
4912 /*
4913 * At the same time, hardware can only support a maximum of
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004914 * hw.mac->max_msix_vectors vectors. With features
4915 * such as RSS and VMDq, we can easily surpass the number of Rx and Tx
4916 * descriptor queues supported by our device. Thus, we cap it off in
4917 * those rare cases where the cpu count also exceeds our vector limit.
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004918 */
PJ Waskiewicz8be0e462009-03-31 21:34:05 +00004919 v_budget = min(v_budget, (int)hw->mac.max_msix_vectors);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004920
4921 /* A failure in MSI-X entry allocation isn't fatal, but it does
4922 * mean we disable MSI-X capabilities of the adapter. */
4923 adapter->msix_entries = kcalloc(v_budget,
Joe Perchese8e9f692010-09-07 21:34:53 +00004924 sizeof(struct msix_entry), GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004925 if (adapter->msix_entries) {
4926 for (vector = 0; vector < v_budget; vector++)
4927 adapter->msix_entries[vector].entry = vector;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004928
Alexander Duyck7a921c92009-05-06 10:43:28 +00004929 ixgbe_acquire_msix_vectors(adapter, v_budget);
4930
4931 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
4932 goto out;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004933 }
David S. Miller26d27842010-05-03 15:18:22 -07004934
Alexander Duyck7a921c92009-05-06 10:43:28 +00004935 adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED;
4936 adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck45b9f502011-01-06 14:29:59 +00004937 if (adapter->flags & (IXGBE_FLAG_FDIR_HASH_CAPABLE |
4938 IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) {
4939 e_err(probe,
4940 "Flow Director is not supported while multiple "
4941 "queues are disabled. Disabling Flow Director\n");
4942 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00004943 adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE;
4944 adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE;
4945 adapter->atr_sample_rate = 0;
Greg Rose1cdd1ec2010-01-09 02:26:46 +00004946 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
4947 ixgbe_disable_sriov(adapter);
4948
Ben Hutchings847f53f2010-09-27 08:28:56 +00004949 err = ixgbe_set_num_queues(adapter);
4950 if (err)
4951 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004952
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004953 err = pci_enable_msi(adapter->pdev);
4954 if (!err) {
4955 adapter->flags |= IXGBE_FLAG_MSI_ENABLED;
4956 } else {
Emil Tantilov849c4542010-06-03 16:53:41 +00004957 netif_printk(adapter, hw, KERN_DEBUG, adapter->netdev,
4958 "Unable to allocate MSI interrupt, "
4959 "falling back to legacy. Error: %d\n", err);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004960 /* reset err */
4961 err = 0;
4962 }
4963
4964out:
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08004965 return err;
4966}
4967
Alexander Duyck7a921c92009-05-06 10:43:28 +00004968/**
4969 * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors
4970 * @adapter: board private structure to initialize
4971 *
4972 * We allocate one q_vector per queue interrupt. If allocation fails we
4973 * return -ENOMEM.
4974 **/
4975static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter)
4976{
4977 int q_idx, num_q_vectors;
4978 struct ixgbe_q_vector *q_vector;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004979 int (*poll)(struct napi_struct *, int);
4980
4981 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
4982 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00004983 poll = &ixgbe_clean_rxtx_many;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004984 } else {
4985 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00004986 poll = &ixgbe_poll;
4987 }
4988
4989 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004990 q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004991 GFP_KERNEL, adapter->node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00004992 if (!q_vector)
4993 q_vector = kzalloc(sizeof(struct ixgbe_q_vector),
Joe Perchese8e9f692010-09-07 21:34:53 +00004994 GFP_KERNEL);
Alexander Duyck7a921c92009-05-06 10:43:28 +00004995 if (!q_vector)
4996 goto err_out;
4997 q_vector->adapter = adapter;
Nelson, Shannonf7554a22009-09-18 09:46:06 +00004998 if (q_vector->txr_count && !q_vector->rxr_count)
4999 q_vector->eitr = adapter->tx_eitr_param;
5000 else
5001 q_vector->eitr = adapter->rx_eitr_param;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005002 q_vector->v_idx = q_idx;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005003 netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005004 adapter->q_vector[q_idx] = q_vector;
5005 }
5006
5007 return 0;
5008
5009err_out:
5010 while (q_idx) {
5011 q_idx--;
5012 q_vector = adapter->q_vector[q_idx];
5013 netif_napi_del(&q_vector->napi);
5014 kfree(q_vector);
5015 adapter->q_vector[q_idx] = NULL;
5016 }
5017 return -ENOMEM;
5018}
5019
5020/**
5021 * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors
5022 * @adapter: board private structure to initialize
5023 *
5024 * This function frees the memory allocated to the q_vectors. In addition if
5025 * NAPI is enabled it will delete any references to the NAPI struct prior
5026 * to freeing the q_vector.
5027 **/
5028static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter)
5029{
5030 int q_idx, num_q_vectors;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005031
Alexander Duyck91281fd2009-06-04 16:00:27 +00005032 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED)
Alexander Duyck7a921c92009-05-06 10:43:28 +00005033 num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005034 else
Alexander Duyck7a921c92009-05-06 10:43:28 +00005035 num_q_vectors = 1;
Alexander Duyck7a921c92009-05-06 10:43:28 +00005036
5037 for (q_idx = 0; q_idx < num_q_vectors; q_idx++) {
5038 struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx];
Alexander Duyck7a921c92009-05-06 10:43:28 +00005039 adapter->q_vector[q_idx] = NULL;
Alexander Duyck91281fd2009-06-04 16:00:27 +00005040 netif_napi_del(&q_vector->napi);
Alexander Duyck7a921c92009-05-06 10:43:28 +00005041 kfree(q_vector);
5042 }
5043}
5044
Don Skidmore7b25cdb2009-08-25 04:47:32 +00005045static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005046{
5047 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
5048 adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED;
5049 pci_disable_msix(adapter->pdev);
5050 kfree(adapter->msix_entries);
5051 adapter->msix_entries = NULL;
5052 } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) {
5053 adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED;
5054 pci_disable_msi(adapter->pdev);
5055 }
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005056}
5057
5058/**
5059 * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme
5060 * @adapter: board private structure to initialize
5061 *
5062 * We determine which interrupt scheme to use based on...
5063 * - Kernel support (MSI, MSI-X)
5064 * - which can be user-defined (via MODULE_PARAM)
5065 * - Hardware queue count (num_*_queues)
5066 * - defined by miscellaneous hardware support/features (RSS, etc.)
5067 **/
Alexander Duyck2f90b862008-11-20 20:52:10 -08005068int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter)
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005069{
5070 int err;
5071
5072 /* Number of supported queues */
Ben Hutchings847f53f2010-09-27 08:28:56 +00005073 err = ixgbe_set_num_queues(adapter);
5074 if (err)
5075 return err;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005076
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005077 err = ixgbe_set_interrupt_capability(adapter);
5078 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005079 e_dev_err("Unable to setup interrupt capabilities\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005080 goto err_set_interrupt;
5081 }
5082
Alexander Duyck7a921c92009-05-06 10:43:28 +00005083 err = ixgbe_alloc_q_vectors(adapter);
5084 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005085 e_dev_err("Unable to allocate memory for queue vectors\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005086 goto err_alloc_q_vectors;
5087 }
5088
5089 err = ixgbe_alloc_queues(adapter);
5090 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005091 e_dev_err("Unable to allocate memory for queues\n");
Alexander Duyck7a921c92009-05-06 10:43:28 +00005092 goto err_alloc_queues;
5093 }
5094
Emil Tantilov849c4542010-06-03 16:53:41 +00005095 e_dev_info("Multiqueue %s: Rx Queue count = %u, Tx Queue count = %u\n",
Emil Tantilov396e7992010-07-01 20:05:12 +00005096 (adapter->num_rx_queues > 1) ? "Enabled" : "Disabled",
5097 adapter->num_rx_queues, adapter->num_tx_queues);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005098
5099 set_bit(__IXGBE_DOWN, &adapter->state);
5100
5101 return 0;
5102
Alexander Duyck7a921c92009-05-06 10:43:28 +00005103err_alloc_queues:
5104 ixgbe_free_q_vectors(adapter);
5105err_alloc_q_vectors:
5106 ixgbe_reset_interrupt_capability(adapter);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005107err_set_interrupt:
Alexander Duyck7a921c92009-05-06 10:43:28 +00005108 return err;
5109}
5110
Eric Dumazet1a515022010-11-16 19:26:42 -08005111static void ring_free_rcu(struct rcu_head *head)
5112{
5113 kfree(container_of(head, struct ixgbe_ring, rcu));
5114}
5115
Alexander Duyck7a921c92009-05-06 10:43:28 +00005116/**
5117 * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings
5118 * @adapter: board private structure to clear interrupt scheme on
5119 *
5120 * We go through and clear interrupt specific resources and reset the structure
5121 * to pre-load conditions
5122 **/
5123void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter)
5124{
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005125 int i;
5126
5127 for (i = 0; i < adapter->num_tx_queues; i++) {
5128 kfree(adapter->tx_ring[i]);
5129 adapter->tx_ring[i] = NULL;
5130 }
5131 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08005132 struct ixgbe_ring *ring = adapter->rx_ring[i];
5133
5134 /* ixgbe_get_stats64() might access this ring, we must wait
5135 * a grace period before freeing it.
5136 */
5137 call_rcu(&ring->rcu, ring_free_rcu);
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005138 adapter->rx_ring[i] = NULL;
5139 }
Alexander Duyck7a921c92009-05-06 10:43:28 +00005140
Don Skidmoreb8eb3a12010-12-01 20:54:53 +00005141 adapter->num_tx_queues = 0;
5142 adapter->num_rx_queues = 0;
5143
Alexander Duyck7a921c92009-05-06 10:43:28 +00005144 ixgbe_free_q_vectors(adapter);
5145 ixgbe_reset_interrupt_capability(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005146}
5147
5148/**
Donald Skidmorec4900be2008-11-20 21:11:42 -08005149 * ixgbe_sfp_timer - worker thread to find a missing module
5150 * @data: pointer to our adapter struct
5151 **/
5152static void ixgbe_sfp_timer(unsigned long data)
5153{
5154 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
5155
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005156 /*
5157 * Do the sfp_timer outside of interrupt context due to the
Donald Skidmorec4900be2008-11-20 21:11:42 -08005158 * delays that sfp+ detection requires
5159 */
5160 schedule_work(&adapter->sfp_task);
5161}
5162
5163/**
5164 * ixgbe_sfp_task - worker thread to find a missing module
5165 * @work: pointer to work_struct containing our data
5166 **/
5167static void ixgbe_sfp_task(struct work_struct *work)
5168{
5169 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00005170 struct ixgbe_adapter,
5171 sfp_task);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005172 struct ixgbe_hw *hw = &adapter->hw;
5173
5174 if ((hw->phy.type == ixgbe_phy_nl) &&
5175 (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) {
5176 s32 ret = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00005177 if (ret == IXGBE_ERR_SFP_NOT_PRESENT)
Donald Skidmorec4900be2008-11-20 21:11:42 -08005178 goto reschedule;
5179 ret = hw->phy.ops.reset(hw);
5180 if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005181 e_dev_err("failed to initialize because an unsupported "
5182 "SFP+ module type was detected.\n");
5183 e_dev_err("Reload the driver after installing a "
5184 "supported module.\n");
Donald Skidmorec4900be2008-11-20 21:11:42 -08005185 unregister_netdev(adapter->netdev);
5186 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00005187 e_info(probe, "detected SFP+: %d\n", hw->phy.sfp_type);
Donald Skidmorec4900be2008-11-20 21:11:42 -08005188 }
5189 /* don't need this routine any more */
5190 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
5191 }
5192 return;
5193reschedule:
5194 if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state))
5195 mod_timer(&adapter->sfp_timer,
Joe Perchese8e9f692010-09-07 21:34:53 +00005196 round_jiffies(jiffies + (2 * HZ)));
Donald Skidmorec4900be2008-11-20 21:11:42 -08005197}
5198
5199/**
Auke Kok9a799d72007-09-15 14:07:45 -07005200 * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter)
5201 * @adapter: board private structure to initialize
5202 *
5203 * ixgbe_sw_init initializes the Adapter private data structure.
5204 * Fields are initialized based on PCI device information and
5205 * OS network device settings (MTU size).
5206 **/
5207static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter)
5208{
5209 struct ixgbe_hw *hw = &adapter->hw;
5210 struct pci_dev *pdev = adapter->pdev;
Peter Waskiewicz9a713e72010-02-10 16:07:54 +00005211 struct net_device *dev = adapter->netdev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005212 unsigned int rss;
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005213#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005214 int j;
5215 struct tc_configuration *tc;
5216#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005217 int max_frame = dev->mtu + ETH_HLEN + ETH_FCS_LEN;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005218
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005219 /* PCI config space info */
5220
5221 hw->vendor_id = pdev->vendor;
5222 hw->device_id = pdev->device;
5223 hw->revision_id = pdev->revision;
5224 hw->subsystem_vendor_id = pdev->subsystem_vendor;
5225 hw->subsystem_device_id = pdev->subsystem_device;
5226
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005227 /* Set capability flags */
5228 rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus());
5229 adapter->ring_feature[RING_F_RSS].indices = rss;
5230 adapter->flags |= IXGBE_FLAG_RSS_ENABLED;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005231 adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES;
Alexander Duyckbd508172010-11-16 19:27:03 -08005232 switch (hw->mac.type) {
5233 case ixgbe_mac_82598EB:
Don Skidmorebf069c92009-05-07 10:39:54 +00005234 if (hw->device_id == IXGBE_DEV_ID_82598AT)
5235 adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005236 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598;
Alexander Duyckbd508172010-11-16 19:27:03 -08005237 break;
5238 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005239 case ixgbe_mac_X540:
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005240 adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599;
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00005241 adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE;
5242 adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED;
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07005243 if (hw->device_id == IXGBE_DEV_ID_82599_T3_LOM)
5244 adapter->flags2 |= IXGBE_FLAG2_TEMP_SENSOR_CAPABLE;
Alexander Duyck45b9f502011-01-06 14:29:59 +00005245 /* n-tuple support exists, always init our spinlock */
5246 spin_lock_init(&adapter->fdir_perfect_lock);
5247 /* Flow Director hash filters enabled */
5248 adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE;
5249 adapter->atr_sample_rate = 20;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005250 adapter->ring_feature[RING_F_FDIR].indices =
Joe Perchese8e9f692010-09-07 21:34:53 +00005251 IXGBE_MAX_FDIR_INDICES;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00005252 adapter->fdir_pballoc = 0;
Yi Zoueacd73f2009-05-13 13:11:06 +00005253#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00005254 adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE;
5255 adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED;
5256 adapter->ring_feature[RING_F_FCOE].indices = 0;
Yi Zou61a0f422009-12-03 11:32:22 +00005257#ifdef CONFIG_IXGBE_DCB
Yi Zou6ee16522009-08-31 12:34:28 +00005258 /* Default traffic class to use for FCoE */
5259 adapter->fcoe.tc = IXGBE_FCOE_DEFTC;
John Fastabend56075a92010-07-26 20:41:31 +00005260 adapter->fcoe.up = IXGBE_FCOE_DEFTC;
Yi Zou61a0f422009-12-03 11:32:22 +00005261#endif
Yi Zoueacd73f2009-05-13 13:11:06 +00005262#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005263 break;
5264 default:
5265 break;
Alexander Duyckf8212f92009-04-27 22:42:37 +00005266 }
Alexander Duyck2f90b862008-11-20 20:52:10 -08005267
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08005268#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08005269 /* Configure DCB traffic classes */
5270 for (j = 0; j < MAX_TRAFFIC_CLASS; j++) {
5271 tc = &adapter->dcb_cfg.tc_config[j];
5272 tc->path[DCB_TX_CONFIG].bwg_id = 0;
5273 tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1);
5274 tc->path[DCB_RX_CONFIG].bwg_id = 0;
5275 tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1);
5276 tc->dcb_pfc = pfc_disabled;
5277 }
5278 adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100;
5279 adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100;
5280 adapter->dcb_cfg.rx_pba_cfg = pba_equal;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005281 adapter->dcb_cfg.pfc_mode_enable = false;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005282 adapter->dcb_set_bitmap = 0x00;
John Fastabend30323092011-03-01 05:25:35 +00005283 adapter->dcbx_cap = DCB_CAP_DCBX_HOST | DCB_CAP_DCBX_VER_CEE;
Alexander Duyck2f90b862008-11-20 20:52:10 -08005284 ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg,
John Fastabende5b64632011-03-08 03:44:52 +00005285 MAX_TRAFFIC_CLASS);
Alexander Duyck2f90b862008-11-20 20:52:10 -08005286
5287#endif
Auke Kok9a799d72007-09-15 14:07:45 -07005288
5289 /* default flow control settings */
Don Skidmorecd7664f2009-03-31 21:33:44 +00005290 hw->fc.requested_mode = ixgbe_fc_full;
Don Skidmore71fd5702009-03-31 21:35:05 +00005291 hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00005292#ifdef CONFIG_DCB
5293 adapter->last_lfc_mode = hw->fc.current_mode;
5294#endif
John Fastabend16b61be2010-11-16 19:26:44 -08005295 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5296 hw->fc.low_water = FC_LOW_WATER(max_frame);
Jesse Brandeburg2b9ade92008-08-26 04:27:10 -07005297 hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE;
5298 hw->fc.send_xon = true;
Don Skidmore71fd5702009-03-31 21:35:05 +00005299 hw->fc.disable_fc_autoneg = false;
Auke Kok9a799d72007-09-15 14:07:45 -07005300
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005301 /* enable itr by default in dynamic mode */
Nelson, Shannonf7554a22009-09-18 09:46:06 +00005302 adapter->rx_itr_setting = 1;
5303 adapter->rx_eitr_param = 20000;
5304 adapter->tx_itr_setting = 1;
5305 adapter->tx_eitr_param = 10000;
Jesse Brandeburg30efa5a2008-09-11 19:58:14 -07005306
5307 /* set defaults for eitr in MegaBytes */
5308 adapter->eitr_low = 10;
5309 adapter->eitr_high = 20;
5310
5311 /* set default ring sizes */
5312 adapter->tx_ring_count = IXGBE_DEFAULT_TXD;
5313 adapter->rx_ring_count = IXGBE_DEFAULT_RXD;
5314
Auke Kok9a799d72007-09-15 14:07:45 -07005315 /* initialize eeprom parameters */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07005316 if (ixgbe_init_eeprom_params_generic(hw)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005317 e_dev_err("EEPROM initialization failed\n");
Auke Kok9a799d72007-09-15 14:07:45 -07005318 return -EIO;
5319 }
5320
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005321 /* enable rx csum by default */
Auke Kok9a799d72007-09-15 14:07:45 -07005322 adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED;
5323
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005324 /* get assigned NUMA node */
5325 adapter->node = dev_to_node(&pdev->dev);
5326
Auke Kok9a799d72007-09-15 14:07:45 -07005327 set_bit(__IXGBE_DOWN, &adapter->state);
5328
5329 return 0;
5330}
5331
5332/**
5333 * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005334 * @tx_ring: tx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005335 *
5336 * Return 0 on success, negative on failure
5337 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005338int ixgbe_setup_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005339{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005340 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07005341 int size;
5342
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005343 size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005344 tx_ring->tx_buffer_info = vzalloc_node(size, tx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005345 if (!tx_ring->tx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005346 tx_ring->tx_buffer_info = vzalloc(size);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005347 if (!tx_ring->tx_buffer_info)
5348 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005349
5350 /* round up to nearest 4K */
Peter P Waskiewicz Jr12207e42009-02-06 21:47:24 -08005351 tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc);
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005352 tx_ring->size = ALIGN(tx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005353
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005354 tx_ring->desc = dma_alloc_coherent(dev, tx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005355 &tx_ring->dma, GFP_KERNEL);
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005356 if (!tx_ring->desc)
5357 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005358
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005359 tx_ring->next_to_use = 0;
5360 tx_ring->next_to_clean = 0;
5361 tx_ring->work_limit = tx_ring->count;
Auke Kok9a799d72007-09-15 14:07:45 -07005362 return 0;
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005363
5364err:
5365 vfree(tx_ring->tx_buffer_info);
5366 tx_ring->tx_buffer_info = NULL;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005367 dev_err(dev, "Unable to allocate memory for the Tx descriptor ring\n");
Jesse Brandeburge01c31a2008-08-26 04:27:13 -07005368 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005369}
5370
5371/**
Alexander Duyck69888672008-09-11 20:05:39 -07005372 * ixgbe_setup_all_tx_resources - allocate all queues Tx resources
5373 * @adapter: board private structure
5374 *
5375 * If this function returns with an error, then it's possible one or
5376 * more of the rings is populated (while the rest are not). It is the
5377 * callers duty to clean those orphaned rings.
5378 *
5379 * Return 0 on success, negative on failure
5380 **/
5381static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter)
5382{
5383 int i, err = 0;
5384
5385 for (i = 0; i < adapter->num_tx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005386 err = ixgbe_setup_tx_resources(adapter->tx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005387 if (!err)
5388 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005389 e_err(probe, "Allocation for Tx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005390 break;
5391 }
5392
5393 return err;
5394}
5395
5396/**
Auke Kok9a799d72007-09-15 14:07:45 -07005397 * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors)
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005398 * @rx_ring: rx descriptor ring (for a specific queue) to setup
Auke Kok9a799d72007-09-15 14:07:45 -07005399 *
5400 * Returns 0 on success, negative on failure
5401 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005402int ixgbe_setup_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005403{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005404 struct device *dev = rx_ring->dev;
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005405 int size;
Auke Kok9a799d72007-09-15 14:07:45 -07005406
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005407 size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count;
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005408 rx_ring->rx_buffer_info = vzalloc_node(size, rx_ring->numa_node);
Jesse Brandeburg1a6c14a2010-02-03 14:18:50 +00005409 if (!rx_ring->rx_buffer_info)
Eric Dumazet89bf67f2010-11-22 00:15:06 +00005410 rx_ring->rx_buffer_info = vzalloc(size);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005411 if (!rx_ring->rx_buffer_info)
5412 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005413
Auke Kok9a799d72007-09-15 14:07:45 -07005414 /* Round up to nearest 4K */
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005415 rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc);
5416 rx_ring->size = ALIGN(rx_ring->size, 4096);
Auke Kok9a799d72007-09-15 14:07:45 -07005417
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005418 rx_ring->desc = dma_alloc_coherent(dev, rx_ring->size,
Nick Nunley1b507732010-04-27 13:10:27 +00005419 &rx_ring->dma, GFP_KERNEL);
Auke Kok9a799d72007-09-15 14:07:45 -07005420
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005421 if (!rx_ring->desc)
5422 goto err;
Auke Kok9a799d72007-09-15 14:07:45 -07005423
Jesse Brandeburg3a581072008-08-26 04:27:08 -07005424 rx_ring->next_to_clean = 0;
5425 rx_ring->next_to_use = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005426
5427 return 0;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005428err:
5429 vfree(rx_ring->rx_buffer_info);
5430 rx_ring->rx_buffer_info = NULL;
5431 dev_err(dev, "Unable to allocate memory for the Rx descriptor ring\n");
Mallikarjuna R Chilakala177db6f2008-06-18 15:32:19 -07005432 return -ENOMEM;
Auke Kok9a799d72007-09-15 14:07:45 -07005433}
5434
5435/**
Alexander Duyck69888672008-09-11 20:05:39 -07005436 * ixgbe_setup_all_rx_resources - allocate all queues Rx resources
5437 * @adapter: board private structure
5438 *
5439 * If this function returns with an error, then it's possible one or
5440 * more of the rings is populated (while the rest are not). It is the
5441 * callers duty to clean those orphaned rings.
5442 *
5443 * Return 0 on success, negative on failure
5444 **/
Alexander Duyck69888672008-09-11 20:05:39 -07005445static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter)
5446{
5447 int i, err = 0;
5448
5449 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005450 err = ixgbe_setup_rx_resources(adapter->rx_ring[i]);
Alexander Duyck69888672008-09-11 20:05:39 -07005451 if (!err)
5452 continue;
Emil Tantilov396e7992010-07-01 20:05:12 +00005453 e_err(probe, "Allocation for Rx Queue %u failed\n", i);
Alexander Duyck69888672008-09-11 20:05:39 -07005454 break;
5455 }
5456
5457 return err;
5458}
5459
5460/**
Auke Kok9a799d72007-09-15 14:07:45 -07005461 * ixgbe_free_tx_resources - Free Tx Resources per Queue
Auke Kok9a799d72007-09-15 14:07:45 -07005462 * @tx_ring: Tx descriptor ring for a specific queue
5463 *
5464 * Free all transmit software resources
5465 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005466void ixgbe_free_tx_resources(struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005467{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005468 ixgbe_clean_tx_ring(tx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005469
5470 vfree(tx_ring->tx_buffer_info);
5471 tx_ring->tx_buffer_info = NULL;
5472
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005473 /* if not set, then don't free */
5474 if (!tx_ring->desc)
5475 return;
5476
5477 dma_free_coherent(tx_ring->dev, tx_ring->size,
5478 tx_ring->desc, tx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005479
5480 tx_ring->desc = NULL;
5481}
5482
5483/**
5484 * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues
5485 * @adapter: board private structure
5486 *
5487 * Free all transmit software resources
5488 **/
5489static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter)
5490{
5491 int i;
5492
5493 for (i = 0; i < adapter->num_tx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005494 if (adapter->tx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005495 ixgbe_free_tx_resources(adapter->tx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005496}
5497
5498/**
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07005499 * ixgbe_free_rx_resources - Free Rx Resources
Auke Kok9a799d72007-09-15 14:07:45 -07005500 * @rx_ring: ring to clean the resources from
5501 *
5502 * Free all receive software resources
5503 **/
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005504void ixgbe_free_rx_resources(struct ixgbe_ring *rx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07005505{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005506 ixgbe_clean_rx_ring(rx_ring);
Auke Kok9a799d72007-09-15 14:07:45 -07005507
5508 vfree(rx_ring->rx_buffer_info);
5509 rx_ring->rx_buffer_info = NULL;
5510
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005511 /* if not set, then don't free */
5512 if (!rx_ring->desc)
5513 return;
5514
5515 dma_free_coherent(rx_ring->dev, rx_ring->size,
5516 rx_ring->desc, rx_ring->dma);
Auke Kok9a799d72007-09-15 14:07:45 -07005517
5518 rx_ring->desc = NULL;
5519}
5520
5521/**
5522 * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues
5523 * @adapter: board private structure
5524 *
5525 * Free all receive software resources
5526 **/
5527static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter)
5528{
5529 int i;
5530
5531 for (i = 0; i < adapter->num_rx_queues; i++)
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00005532 if (adapter->rx_ring[i]->desc)
Alexander Duyckb6ec8952010-11-16 19:26:49 -08005533 ixgbe_free_rx_resources(adapter->rx_ring[i]);
Auke Kok9a799d72007-09-15 14:07:45 -07005534}
5535
5536/**
Auke Kok9a799d72007-09-15 14:07:45 -07005537 * ixgbe_change_mtu - Change the Maximum Transfer Unit
5538 * @netdev: network interface device structure
5539 * @new_mtu: new value for maximum frame size
5540 *
5541 * Returns 0 on success, negative on failure
5542 **/
5543static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu)
5544{
5545 struct ixgbe_adapter *adapter = netdev_priv(netdev);
John Fastabend16b61be2010-11-16 19:26:44 -08005546 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07005547 int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN;
5548
Jesse Brandeburg42c783c2008-09-11 19:56:28 -07005549 /* MTU < 68 is an error and causes problems on some kernels */
Greg Rosee9f98072011-01-26 01:06:07 +00005550 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED &&
5551 hw->mac.type != ixgbe_mac_X540) {
5552 if ((new_mtu < 68) || (max_frame > MAXIMUM_ETHERNET_VLAN_SIZE))
5553 return -EINVAL;
5554 } else {
5555 if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE))
5556 return -EINVAL;
5557 }
Auke Kok9a799d72007-09-15 14:07:45 -07005558
Emil Tantilov396e7992010-07-01 20:05:12 +00005559 e_info(probe, "changing MTU from %d to %d\n", netdev->mtu, new_mtu);
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005560 /* must set new MTU before calling down or up */
Auke Kok9a799d72007-09-15 14:07:45 -07005561 netdev->mtu = new_mtu;
5562
John Fastabend16b61be2010-11-16 19:26:44 -08005563 hw->fc.high_water = FC_HIGH_WATER(max_frame);
5564 hw->fc.low_water = FC_LOW_WATER(max_frame);
5565
Ayyappan Veeraiyand4f80882008-02-01 15:58:41 -08005566 if (netif_running(netdev))
5567 ixgbe_reinit_locked(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005568
5569 return 0;
5570}
5571
5572/**
5573 * ixgbe_open - Called when a network interface is made active
5574 * @netdev: network interface device structure
5575 *
5576 * Returns 0 on success, negative value on failure
5577 *
5578 * The open entry point is called when a network interface is made
5579 * active by the system (IFF_UP). At this point all resources needed
5580 * for transmit and receive operations are allocated, the interrupt
5581 * handler is registered with the OS, the watchdog timer is started,
5582 * and the stack is notified that the interface is ready.
5583 **/
5584static int ixgbe_open(struct net_device *netdev)
5585{
5586 struct ixgbe_adapter *adapter = netdev_priv(netdev);
5587 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07005588
Auke Kok4bebfaa2008-02-11 09:26:01 -08005589 /* disallow open during test */
5590 if (test_bit(__IXGBE_TESTING, &adapter->state))
5591 return -EBUSY;
5592
Jesse Brandeburg54386462009-04-17 20:44:27 +00005593 netif_carrier_off(netdev);
5594
Auke Kok9a799d72007-09-15 14:07:45 -07005595 /* allocate transmit descriptors */
5596 err = ixgbe_setup_all_tx_resources(adapter);
5597 if (err)
5598 goto err_setup_tx;
5599
Auke Kok9a799d72007-09-15 14:07:45 -07005600 /* allocate receive descriptors */
5601 err = ixgbe_setup_all_rx_resources(adapter);
5602 if (err)
5603 goto err_setup_rx;
5604
5605 ixgbe_configure(adapter);
5606
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08005607 err = ixgbe_request_irq(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005608 if (err)
5609 goto err_req_irq;
5610
Auke Kok9a799d72007-09-15 14:07:45 -07005611 err = ixgbe_up_complete(adapter);
5612 if (err)
5613 goto err_up;
5614
Jeff Kirsherd55b53f2008-07-18 04:33:03 -07005615 netif_tx_start_all_queues(netdev);
5616
Auke Kok9a799d72007-09-15 14:07:45 -07005617 return 0;
5618
5619err_up:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005620 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005621 ixgbe_free_irq(adapter);
5622err_req_irq:
Auke Kok9a799d72007-09-15 14:07:45 -07005623err_setup_rx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005624 ixgbe_free_all_rx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005625err_setup_tx:
Mallikarjuna R Chilakalaa20a1192009-03-31 21:34:44 +00005626 ixgbe_free_all_tx_resources(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005627 ixgbe_reset(adapter);
5628
5629 return err;
5630}
5631
5632/**
5633 * ixgbe_close - Disables a network interface
5634 * @netdev: network interface device structure
5635 *
5636 * Returns 0, this is not allowed to fail
5637 *
5638 * The close entry point is called when an interface is de-activated
5639 * by the OS. The hardware is still under the drivers control, but
5640 * needs to be disabled. A global MAC reset is issued to stop the
5641 * hardware, and all transmit and receive resources are freed.
5642 **/
5643static int ixgbe_close(struct net_device *netdev)
5644{
5645 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07005646
5647 ixgbe_down(adapter);
5648 ixgbe_free_irq(adapter);
5649
5650 ixgbe_free_all_tx_resources(adapter);
5651 ixgbe_free_all_rx_resources(adapter);
5652
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08005653 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07005654
5655 return 0;
5656}
5657
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005658#ifdef CONFIG_PM
5659static int ixgbe_resume(struct pci_dev *pdev)
5660{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005661 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5662 struct net_device *netdev = adapter->netdev;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005663 u32 err;
5664
5665 pci_set_power_state(pdev, PCI_D0);
5666 pci_restore_state(pdev);
Don Skidmore656ab812009-12-23 21:19:19 -08005667 /*
5668 * pci_restore_state clears dev->state_saved so call
5669 * pci_save_state to restore it.
5670 */
5671 pci_save_state(pdev);
gouji-new9ce77662009-05-06 10:44:45 +00005672
5673 err = pci_enable_device_mem(pdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005674 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005675 e_dev_err("Cannot enable PCI device from suspend\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005676 return err;
5677 }
5678 pci_set_master(pdev);
5679
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005680 pci_wake_from_d3(pdev, false);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005681
5682 err = ixgbe_init_interrupt_scheme(adapter);
5683 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00005684 e_dev_err("Cannot initialize interrupts for device\n");
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005685 return err;
5686 }
5687
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005688 ixgbe_reset(adapter);
5689
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00005690 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
5691
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005692 if (netif_running(netdev)) {
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005693 err = ixgbe_open(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005694 if (err)
5695 return err;
5696 }
5697
5698 netif_device_attach(netdev);
5699
5700 return 0;
5701}
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005702#endif /* CONFIG_PM */
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005703
5704static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake)
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005705{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08005706 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
5707 struct net_device *netdev = adapter->netdev;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005708 struct ixgbe_hw *hw = &adapter->hw;
5709 u32 ctrl, fctrl;
5710 u32 wufc = adapter->wol;
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005711#ifdef CONFIG_PM
5712 int retval = 0;
5713#endif
5714
5715 netif_device_detach(netdev);
5716
5717 if (netif_running(netdev)) {
5718 ixgbe_down(adapter);
5719 ixgbe_free_irq(adapter);
5720 ixgbe_free_all_tx_resources(adapter);
5721 ixgbe_free_all_rx_resources(adapter);
5722 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005723
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005724 ixgbe_clear_interrupt_scheme(adapter);
John Fastabendd033d522011-02-10 14:40:01 +00005725#ifdef CONFIG_DCB
5726 kfree(adapter->ixgbe_ieee_pfc);
5727 kfree(adapter->ixgbe_ieee_ets);
5728#endif
Alexander Duyck5f5ae6f2010-11-16 19:26:52 -08005729
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005730#ifdef CONFIG_PM
5731 retval = pci_save_state(pdev);
5732 if (retval)
5733 return retval;
Jesse Brandeburg4df10462009-03-13 22:15:31 +00005734
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005735#endif
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005736 if (wufc) {
5737 ixgbe_set_rx_mode(netdev);
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005738
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005739 /* turn on all-multi mode if wake on multicast is enabled */
5740 if (wufc & IXGBE_WUFC_MC) {
5741 fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
5742 fctrl |= IXGBE_FCTRL_MPE;
5743 IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl);
5744 }
5745
5746 ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL);
5747 ctrl |= IXGBE_CTRL_GIO_DIS;
5748 IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl);
5749
5750 IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc);
5751 } else {
5752 IXGBE_WRITE_REG(hw, IXGBE_WUC, 0);
5753 IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0);
5754 }
5755
Alexander Duyckbd508172010-11-16 19:27:03 -08005756 switch (hw->mac.type) {
5757 case ixgbe_mac_82598EB:
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07005758 pci_wake_from_d3(pdev, false);
Alexander Duyckbd508172010-11-16 19:27:03 -08005759 break;
5760 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005761 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005762 pci_wake_from_d3(pdev, !!wufc);
5763 break;
5764 default:
5765 break;
5766 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005767
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005768 *enable_wake = !!wufc;
5769
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005770 ixgbe_release_hw_control(adapter);
5771
5772 pci_disable_device(pdev);
5773
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005774 return 0;
5775}
5776
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005777#ifdef CONFIG_PM
5778static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state)
5779{
5780 int retval;
5781 bool wake;
5782
5783 retval = __ixgbe_shutdown(pdev, &wake);
5784 if (retval)
5785 return retval;
5786
5787 if (wake) {
5788 pci_prepare_to_sleep(pdev);
5789 } else {
5790 pci_wake_from_d3(pdev, false);
5791 pci_set_power_state(pdev, PCI_D3hot);
5792 }
5793
5794 return 0;
5795}
5796#endif /* CONFIG_PM */
5797
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005798static void ixgbe_shutdown(struct pci_dev *pdev)
5799{
Rafael J. Wysocki9d8d05a2009-04-15 17:44:01 +00005800 bool wake;
5801
5802 __ixgbe_shutdown(pdev, &wake);
5803
5804 if (system_state == SYSTEM_POWER_OFF) {
5805 pci_wake_from_d3(pdev, wake);
5806 pci_set_power_state(pdev, PCI_D3hot);
5807 }
Alexander Duyckb3c8b4b2008-09-11 20:04:56 -07005808}
5809
5810/**
Auke Kok9a799d72007-09-15 14:07:45 -07005811 * ixgbe_update_stats - Update the board statistics counters.
5812 * @adapter: board private structure
5813 **/
5814void ixgbe_update_stats(struct ixgbe_adapter *adapter)
5815{
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005816 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07005817 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005818 struct ixgbe_hw_stats *hwstats = &adapter->stats;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005819 u64 total_mpc = 0;
5820 u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005821 u64 non_eop_descs = 0, restart_queue = 0, tx_busy = 0;
5822 u64 alloc_rx_page_failed = 0, alloc_rx_buff_failed = 0;
5823 u64 bytes = 0, packets = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07005824
Don Skidmored08935c2010-06-11 13:20:29 +00005825 if (test_bit(__IXGBE_DOWN, &adapter->state) ||
5826 test_bit(__IXGBE_RESETTING, &adapter->state))
5827 return;
5828
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005829 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) {
Alexander Duyckf8212f92009-04-27 22:42:37 +00005830 u64 rsc_count = 0;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005831 u64 rsc_flush = 0;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005832 for (i = 0; i < 16; i++)
5833 adapter->hw_rx_no_dma_resources +=
Joe Perches7ca647b2010-09-07 21:35:40 +00005834 IXGBE_READ_REG(hw, IXGBE_QPRDC(i));
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005835 for (i = 0; i < adapter->num_rx_queues; i++) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08005836 rsc_count += adapter->rx_ring[i]->rx_stats.rsc_count;
5837 rsc_flush += adapter->rx_ring[i]->rx_stats.rsc_flush;
Mallikarjuna R Chilakala94b982b2009-11-23 06:32:06 +00005838 }
5839 adapter->rsc_total_count = rsc_count;
5840 adapter->rsc_total_flush = rsc_flush;
PJ Waskiewiczd51019a2009-03-13 22:12:48 +00005841 }
5842
Alexander Duyck5b7da512010-11-16 19:26:50 -08005843 for (i = 0; i < adapter->num_rx_queues; i++) {
5844 struct ixgbe_ring *rx_ring = adapter->rx_ring[i];
5845 non_eop_descs += rx_ring->rx_stats.non_eop_descs;
5846 alloc_rx_page_failed += rx_ring->rx_stats.alloc_rx_page_failed;
5847 alloc_rx_buff_failed += rx_ring->rx_stats.alloc_rx_buff_failed;
5848 bytes += rx_ring->stats.bytes;
5849 packets += rx_ring->stats.packets;
5850 }
Mallikarjuna R Chilakalaeb985f02009-12-15 11:56:59 +00005851 adapter->non_eop_descs = non_eop_descs;
Alexander Duyck5b7da512010-11-16 19:26:50 -08005852 adapter->alloc_rx_page_failed = alloc_rx_page_failed;
5853 adapter->alloc_rx_buff_failed = alloc_rx_buff_failed;
5854 netdev->stats.rx_bytes = bytes;
5855 netdev->stats.rx_packets = packets;
5856
5857 bytes = 0;
5858 packets = 0;
5859 /* gather some stats to the adapter struct that are per queue */
5860 for (i = 0; i < adapter->num_tx_queues; i++) {
5861 struct ixgbe_ring *tx_ring = adapter->tx_ring[i];
5862 restart_queue += tx_ring->tx_stats.restart_queue;
5863 tx_busy += tx_ring->tx_stats.tx_busy;
5864 bytes += tx_ring->stats.bytes;
5865 packets += tx_ring->stats.packets;
5866 }
5867 adapter->restart_queue = restart_queue;
5868 adapter->tx_busy = tx_busy;
5869 netdev->stats.tx_bytes = bytes;
5870 netdev->stats.tx_packets = packets;
Jesse Brandeburg7ca3bc52009-12-03 11:33:29 +00005871
Joe Perches7ca647b2010-09-07 21:35:40 +00005872 hwstats->crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005873 for (i = 0; i < 8; i++) {
5874 /* for packet buffers not used, the register should read 0 */
5875 mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i));
5876 missed_rx += mpc;
Joe Perches7ca647b2010-09-07 21:35:40 +00005877 hwstats->mpc[i] += mpc;
5878 total_mpc += hwstats->mpc[i];
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005879 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005880 hwstats->rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i));
5881 hwstats->qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i));
5882 hwstats->qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i));
5883 hwstats->qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i));
5884 hwstats->qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005885 switch (hw->mac.type) {
5886 case ixgbe_mac_82598EB:
Joe Perches7ca647b2010-09-07 21:35:40 +00005887 hwstats->pxonrxc[i] +=
5888 IXGBE_READ_REG(hw, IXGBE_PXONRXC(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005889 break;
5890 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005891 case ixgbe_mac_X540:
Alexander Duyckbd508172010-11-16 19:27:03 -08005892 hwstats->pxonrxc[i] +=
5893 IXGBE_READ_REG(hw, IXGBE_PXONRXCNT(i));
Alexander Duyckbd508172010-11-16 19:27:03 -08005894 break;
5895 default:
5896 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005897 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005898 hwstats->pxontxc[i] += IXGBE_READ_REG(hw, IXGBE_PXONTXC(i));
5899 hwstats->pxofftxc[i] += IXGBE_READ_REG(hw, IXGBE_PXOFFTXC(i));
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005900 }
Joe Perches7ca647b2010-09-07 21:35:40 +00005901 hwstats->gprc += IXGBE_READ_REG(hw, IXGBE_GPRC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005902 /* work around hardware counting issue */
Joe Perches7ca647b2010-09-07 21:35:40 +00005903 hwstats->gprc -= missed_rx;
Auke Kok9a799d72007-09-15 14:07:45 -07005904
John Fastabendc84d3242010-11-16 19:27:12 -08005905 ixgbe_update_xoff_received(adapter);
5906
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005907 /* 82598 hardware only has a 32 bit counter in the high register */
Alexander Duyckbd508172010-11-16 19:27:03 -08005908 switch (hw->mac.type) {
5909 case ixgbe_mac_82598EB:
5910 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC);
Alexander Duyckbd508172010-11-16 19:27:03 -08005911 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCH);
5912 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH);
5913 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORH);
5914 break;
5915 case ixgbe_mac_82599EB:
Don Skidmoreb93a2222010-11-16 19:27:17 -08005916 case ixgbe_mac_X540:
Joe Perches7ca647b2010-09-07 21:35:40 +00005917 hwstats->gorc += IXGBE_READ_REG(hw, IXGBE_GORCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005918 IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005919 hwstats->gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005920 IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005921 hwstats->tor += IXGBE_READ_REG(hw, IXGBE_TORL);
Alexander Duyckbd508172010-11-16 19:27:03 -08005922 IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */
Joe Perches7ca647b2010-09-07 21:35:40 +00005923 hwstats->lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT);
Joe Perches7ca647b2010-09-07 21:35:40 +00005924 hwstats->fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH);
5925 hwstats->fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS);
Yi Zou6d455222009-05-13 13:12:16 +00005926#ifdef IXGBE_FCOE
Joe Perches7ca647b2010-09-07 21:35:40 +00005927 hwstats->fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC);
5928 hwstats->fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC);
5929 hwstats->fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC);
5930 hwstats->fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC);
5931 hwstats->fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC);
5932 hwstats->fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC);
Yi Zou6d455222009-05-13 13:12:16 +00005933#endif /* IXGBE_FCOE */
Alexander Duyckbd508172010-11-16 19:27:03 -08005934 break;
5935 default:
5936 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005937 }
Auke Kok9a799d72007-09-15 14:07:45 -07005938 bprc = IXGBE_READ_REG(hw, IXGBE_BPRC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005939 hwstats->bprc += bprc;
5940 hwstats->mprc += IXGBE_READ_REG(hw, IXGBE_MPRC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00005941 if (hw->mac.type == ixgbe_mac_82598EB)
Joe Perches7ca647b2010-09-07 21:35:40 +00005942 hwstats->mprc -= bprc;
5943 hwstats->roc += IXGBE_READ_REG(hw, IXGBE_ROC);
5944 hwstats->prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64);
5945 hwstats->prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127);
5946 hwstats->prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255);
5947 hwstats->prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511);
5948 hwstats->prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023);
5949 hwstats->prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522);
5950 hwstats->rlec += IXGBE_READ_REG(hw, IXGBE_RLEC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005951 lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005952 hwstats->lxontxc += lxon;
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005953 lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC);
Joe Perches7ca647b2010-09-07 21:35:40 +00005954 hwstats->lxofftxc += lxoff;
5955 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5956 hwstats->gptc += IXGBE_READ_REG(hw, IXGBE_GPTC);
5957 hwstats->mptc += IXGBE_READ_REG(hw, IXGBE_MPTC);
Ayyappan Veeraiyan6f11eef2008-02-01 15:59:14 -08005958 /*
5959 * 82598 errata - tx of flow control packets is included in tx counters
5960 */
5961 xon_off_tot = lxon + lxoff;
Joe Perches7ca647b2010-09-07 21:35:40 +00005962 hwstats->gptc -= xon_off_tot;
5963 hwstats->mptc -= xon_off_tot;
5964 hwstats->gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN));
5965 hwstats->ruc += IXGBE_READ_REG(hw, IXGBE_RUC);
5966 hwstats->rfc += IXGBE_READ_REG(hw, IXGBE_RFC);
5967 hwstats->rjc += IXGBE_READ_REG(hw, IXGBE_RJC);
5968 hwstats->tpr += IXGBE_READ_REG(hw, IXGBE_TPR);
5969 hwstats->ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64);
5970 hwstats->ptc64 -= xon_off_tot;
5971 hwstats->ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127);
5972 hwstats->ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255);
5973 hwstats->ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511);
5974 hwstats->ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023);
5975 hwstats->ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522);
5976 hwstats->bptc += IXGBE_READ_REG(hw, IXGBE_BPTC);
Auke Kok9a799d72007-09-15 14:07:45 -07005977
5978 /* Fill out the OS statistics structure */
Joe Perches7ca647b2010-09-07 21:35:40 +00005979 netdev->stats.multicast = hwstats->mprc;
Auke Kok9a799d72007-09-15 14:07:45 -07005980
5981 /* Rx Errors */
Joe Perches7ca647b2010-09-07 21:35:40 +00005982 netdev->stats.rx_errors = hwstats->crcerrs + hwstats->rlec;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005983 netdev->stats.rx_dropped = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00005984 netdev->stats.rx_length_errors = hwstats->rlec;
5985 netdev->stats.rx_crc_errors = hwstats->crcerrs;
Ajit Khaparde2d86f132009-10-07 02:43:49 +00005986 netdev->stats.rx_missed_errors = total_mpc;
Auke Kok9a799d72007-09-15 14:07:45 -07005987}
5988
5989/**
5990 * ixgbe_watchdog - Timer Call-back
5991 * @data: pointer to adapter cast into an unsigned long
5992 **/
5993static void ixgbe_watchdog(unsigned long data)
5994{
5995 struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07005996 struct ixgbe_hw *hw = &adapter->hw;
Alexander Duyckfe49f042009-06-04 16:00:09 +00005997 u64 eics = 0;
5998 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07005999
Alexander Duyckfe49f042009-06-04 16:00:09 +00006000 /*
6001 * Do the watchdog outside of interrupt context due to the lovely
6002 * delays that some of the newer hardware requires
6003 */
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006004
Alexander Duyckfe49f042009-06-04 16:00:09 +00006005 if (test_bit(__IXGBE_DOWN, &adapter->state))
6006 goto watchdog_short_circuit;
Jesse Brandeburg22d5a712009-03-19 01:24:04 +00006007
Alexander Duyckfe49f042009-06-04 16:00:09 +00006008 if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) {
6009 /*
6010 * for legacy and MSI interrupts don't set any bits
6011 * that are enabled for EIAM, because this operation
6012 * would set *both* EIMS and EICS for any bit in EIAM
6013 */
6014 IXGBE_WRITE_REG(hw, IXGBE_EICS,
6015 (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER));
6016 goto watchdog_reschedule;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006017 }
6018
Alexander Duyckfe49f042009-06-04 16:00:09 +00006019 /* get one bit for every active tx/rx interrupt vector */
6020 for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) {
6021 struct ixgbe_q_vector *qv = adapter->q_vector[i];
6022 if (qv->rxr_count || qv->txr_count)
6023 eics |= ((u64)1 << i);
6024 }
6025
6026 /* Cause software interrupt to ensure rx rings are cleaned */
6027 ixgbe_irq_rearm_queues(adapter, eics);
6028
6029watchdog_reschedule:
6030 /* Reset the timer */
6031 mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ));
6032
6033watchdog_short_circuit:
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006034 schedule_work(&adapter->watchdog_task);
6035}
6036
6037/**
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006038 * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber
6039 * @work: pointer to work_struct containing our data
6040 **/
6041static void ixgbe_multispeed_fiber_task(struct work_struct *work)
6042{
6043 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006044 struct ixgbe_adapter,
6045 multispeed_fiber_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006046 struct ixgbe_hw *hw = &adapter->hw;
6047 u32 autoneg;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006048 bool negotiation;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006049
6050 adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK;
Mallikarjuna R Chilakalaa1f25322009-06-30 11:44:36 +00006051 autoneg = hw->phy.autoneg_advertised;
6052 if ((!autoneg) && (hw->mac.ops.get_link_capabilities))
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006053 hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation);
Mallikarjuna R Chilakala1097cd12010-03-18 14:34:52 +00006054 hw->mac.autotry_restart = false;
Mallikarjuna R Chilakala8620a102009-09-01 13:49:35 +00006055 if (hw->mac.ops.setup_link)
6056 hw->mac.ops.setup_link(hw, autoneg, negotiation, true);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006057 adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE;
6058 adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK;
6059}
6060
6061/**
6062 * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module
6063 * @work: pointer to work_struct containing our data
6064 **/
6065static void ixgbe_sfp_config_module_task(struct work_struct *work)
6066{
6067 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006068 struct ixgbe_adapter,
6069 sfp_config_module_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006070 struct ixgbe_hw *hw = &adapter->hw;
6071 u32 err;
6072
6073 adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK;
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006074
6075 /* Time for electrical oscillations to settle down */
6076 msleep(100);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006077 err = hw->phy.ops.identify_sfp(hw);
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006078
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006079 if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00006080 e_dev_err("failed to initialize because an unsupported SFP+ "
6081 "module type was detected.\n");
6082 e_dev_err("Reload the driver after installing a supported "
6083 "module.\n");
Don Skidmore63d6e1d2009-07-02 12:50:12 +00006084 unregister_netdev(adapter->netdev);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006085 return;
6086 }
Andy Gospodarek4c7e6042011-02-17 01:13:13 -08006087 if (hw->mac.ops.setup_sfp)
6088 hw->mac.ops.setup_sfp(hw);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006089
Tony Breeds8d1c3c02009-04-09 22:29:10 +00006090 if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK))
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006091 /* This will also work for DA Twinax connections */
6092 schedule_work(&adapter->multispeed_fiber_task);
6093 adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK;
6094}
6095
6096/**
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006097 * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table
6098 * @work: pointer to work_struct containing our data
6099 **/
6100static void ixgbe_fdir_reinit_task(struct work_struct *work)
6101{
6102 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006103 struct ixgbe_adapter,
6104 fdir_reinit_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006105 struct ixgbe_hw *hw = &adapter->hw;
6106 int i;
6107
6108 if (ixgbe_reinit_fdir_tables_82599(hw) == 0) {
6109 for (i = 0; i < adapter->num_tx_queues; i++)
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006110 set_bit(__IXGBE_TX_FDIR_INIT_DONE,
6111 &(adapter->tx_ring[i]->state));
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006112 } else {
Emil Tantilov396e7992010-07-01 20:05:12 +00006113 e_err(probe, "failed to finish FDIR re-initialization, "
Emil Tantilov849c4542010-06-03 16:53:41 +00006114 "ignored adding FDIR ATR filters\n");
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006115 }
6116 /* Done FDIR Re-initialization, enable transmits */
6117 netif_tx_start_all_queues(adapter->netdev);
6118}
6119
Greg Rosea985b6c32010-11-18 03:02:52 +00006120static void ixgbe_spoof_check(struct ixgbe_adapter *adapter)
6121{
6122 u32 ssvpc;
6123
6124 /* Do not perform spoof check for 82598 */
6125 if (adapter->hw.mac.type == ixgbe_mac_82598EB)
6126 return;
6127
6128 ssvpc = IXGBE_READ_REG(&adapter->hw, IXGBE_SSVPC);
6129
6130 /*
6131 * ssvpc register is cleared on read, if zero then no
6132 * spoofed packets in the last interval.
6133 */
6134 if (!ssvpc)
6135 return;
6136
6137 e_warn(drv, "%d Spoofed packets detected\n", ssvpc);
6138}
6139
John Fastabend10eec952010-02-03 14:23:32 +00006140static DEFINE_MUTEX(ixgbe_watchdog_lock);
6141
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006142/**
Alexander Duyck69888672008-09-11 20:05:39 -07006143 * ixgbe_watchdog_task - worker thread to bring link up
6144 * @work: pointer to work_struct containing our data
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006145 **/
6146static void ixgbe_watchdog_task(struct work_struct *work)
6147{
6148 struct ixgbe_adapter *adapter = container_of(work,
Joe Perchese8e9f692010-09-07 21:34:53 +00006149 struct ixgbe_adapter,
6150 watchdog_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006151 struct net_device *netdev = adapter->netdev;
6152 struct ixgbe_hw *hw = &adapter->hw;
John Fastabend10eec952010-02-03 14:23:32 +00006153 u32 link_speed;
6154 bool link_up;
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006155 int i;
6156 struct ixgbe_ring *tx_ring;
6157 int some_tx_pending = 0;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006158
John Fastabend10eec952010-02-03 14:23:32 +00006159 mutex_lock(&ixgbe_watchdog_lock);
6160
6161 link_up = adapter->link_up;
6162 link_speed = adapter->link_speed;
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006163
6164 if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) {
6165 hw->mac.ops.check_link(hw, &link_speed, &link_up, false);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006166 if (link_up) {
6167#ifdef CONFIG_DCB
6168 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6169 for (i = 0; i < MAX_TRAFFIC_CLASS; i++)
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006170 hw->mac.ops.fc_enable(hw, i);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006171 } else {
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006172 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006173 }
6174#else
Mallikarjuna R Chilakala620fa032009-06-04 11:11:13 +00006175 hw->mac.ops.fc_enable(hw, 0);
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006176#endif
6177 }
6178
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006179 if (link_up ||
6180 time_after(jiffies, (adapter->link_check_timeout +
Joe Perchese8e9f692010-09-07 21:34:53 +00006181 IXGBE_TRY_LINK_TIMEOUT))) {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006182 adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE;
Peter P Waskiewicz Jr264857b2009-05-17 12:35:16 +00006183 IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006184 }
6185 adapter->link_up = link_up;
6186 adapter->link_speed = link_speed;
6187 }
Auke Kok9a799d72007-09-15 14:07:45 -07006188
6189 if (link_up) {
6190 if (!netif_carrier_ok(netdev)) {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006191 bool flow_rx, flow_tx;
6192
Alexander Duyckbd508172010-11-16 19:27:03 -08006193 switch (hw->mac.type) {
6194 case ixgbe_mac_82598EB: {
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006195 u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL);
6196 u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS);
Peter P Waskiewicz Jr078788b2009-07-16 15:50:32 +00006197 flow_rx = !!(frctl & IXGBE_FCTRL_RFCE);
6198 flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006199 }
Alexander Duyckbd508172010-11-16 19:27:03 -08006200 break;
Don Skidmoreb93a2222010-11-16 19:27:17 -08006201 case ixgbe_mac_82599EB:
6202 case ixgbe_mac_X540: {
Alexander Duyckbd508172010-11-16 19:27:03 -08006203 u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN);
6204 u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG);
6205 flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE);
6206 flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X);
6207 }
6208 break;
6209 default:
6210 flow_tx = false;
6211 flow_rx = false;
6212 break;
6213 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006214
Emil Tantilov396e7992010-07-01 20:05:12 +00006215 e_info(drv, "NIC Link is Up %s, Flow Control: %s\n",
Jeff Kirshera46e5342008-11-27 00:22:21 -08006216 (link_speed == IXGBE_LINK_SPEED_10GB_FULL ?
Emil Tantilov849c4542010-06-03 16:53:41 +00006217 "10 Gbps" :
6218 (link_speed == IXGBE_LINK_SPEED_1GB_FULL ?
Atita Shirwaikar1b1c0a42011-01-05 02:00:55 +00006219 "1 Gbps" :
6220 (link_speed == IXGBE_LINK_SPEED_100_FULL ?
6221 "100 Mbps" :
6222 "unknown speed"))),
PJ Waskiewicze8e26352009-02-27 15:45:05 +00006223 ((flow_rx && flow_tx) ? "RX/TX" :
Emil Tantilov849c4542010-06-03 16:53:41 +00006224 (flow_rx ? "RX" :
6225 (flow_tx ? "TX" : "None"))));
Auke Kok9a799d72007-09-15 14:07:45 -07006226
6227 netif_carrier_on(netdev);
Lior Levyff4ab202011-03-11 02:03:07 +00006228 ixgbe_check_vf_rate_limit(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006229 } else {
6230 /* Force detection of hung controller */
Alexander Duyck7d637bc2010-11-16 19:26:56 -08006231 for (i = 0; i < adapter->num_tx_queues; i++) {
6232 tx_ring = adapter->tx_ring[i];
6233 set_check_for_tx_hang(tx_ring);
6234 }
Auke Kok9a799d72007-09-15 14:07:45 -07006235 }
6236 } else {
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07006237 adapter->link_up = false;
6238 adapter->link_speed = 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006239 if (netif_carrier_ok(netdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00006240 e_info(drv, "NIC Link is Down\n");
Auke Kok9a799d72007-09-15 14:07:45 -07006241 netif_carrier_off(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07006242 }
6243 }
6244
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006245 if (!netif_carrier_ok(netdev)) {
6246 for (i = 0; i < adapter->num_tx_queues; i++) {
PJ Waskiewicz4a0b9ca2010-02-03 14:19:12 +00006247 tx_ring = adapter->tx_ring[i];
Nelson, Shannonbc59fcd2009-04-27 22:43:12 +00006248 if (tx_ring->next_to_use != tx_ring->next_to_clean) {
6249 some_tx_pending = 1;
6250 break;
6251 }
6252 }
6253
6254 if (some_tx_pending) {
6255 /* We've lost link, so the controller stops DMA,
6256 * but we've got queued Tx work that's never going
6257 * to get done, so reset controller to flush Tx.
6258 * (Do the reset outside of interrupt context).
6259 */
6260 schedule_work(&adapter->reset_task);
6261 }
6262 }
6263
Greg Rosea985b6c32010-11-18 03:02:52 +00006264 ixgbe_spoof_check(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07006265 ixgbe_update_stats(adapter);
John Fastabend10eec952010-02-03 14:23:32 +00006266 mutex_unlock(&ixgbe_watchdog_lock);
Auke Kok9a799d72007-09-15 14:07:45 -07006267}
6268
Auke Kok9a799d72007-09-15 14:07:45 -07006269static int ixgbe_tso(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006270 struct ixgbe_ring *tx_ring, struct sk_buff *skb,
Hao Zheng5e09a102010-11-11 13:47:59 +00006271 u32 tx_flags, u8 *hdr_len, __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006272{
6273 struct ixgbe_adv_tx_context_desc *context_desc;
6274 unsigned int i;
6275 int err;
6276 struct ixgbe_tx_buffer *tx_buffer_info;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006277 u32 vlan_macip_lens = 0, type_tucmd_mlhl;
6278 u32 mss_l4len_idx, l4len;
Auke Kok9a799d72007-09-15 14:07:45 -07006279
6280 if (skb_is_gso(skb)) {
6281 if (skb_header_cloned(skb)) {
6282 err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC);
6283 if (err)
6284 return err;
6285 }
6286 l4len = tcp_hdrlen(skb);
6287 *hdr_len += l4len;
6288
Hao Zheng5e09a102010-11-11 13:47:59 +00006289 if (protocol == htons(ETH_P_IP)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006290 struct iphdr *iph = ip_hdr(skb);
6291 iph->tot_len = 0;
6292 iph->check = 0;
6293 tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006294 iph->daddr, 0,
6295 IPPROTO_TCP,
6296 0);
Sridhar Samudrala8e1e8a42010-01-23 02:02:21 -08006297 } else if (skb_is_gso_v6(skb)) {
Auke Kok9a799d72007-09-15 14:07:45 -07006298 ipv6_hdr(skb)->payload_len = 0;
6299 tcp_hdr(skb)->check =
6300 ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr,
Joe Perchese8e9f692010-09-07 21:34:53 +00006301 &ipv6_hdr(skb)->daddr,
6302 0, IPPROTO_TCP, 0);
Auke Kok9a799d72007-09-15 14:07:45 -07006303 }
6304
6305 i = tx_ring->next_to_use;
6306
6307 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006308 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006309
6310 /* VLAN MACLEN IPLEN */
6311 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6312 vlan_macip_lens |=
6313 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6314 vlan_macip_lens |= ((skb_network_offset(skb)) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006315 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006316 *hdr_len += skb_network_offset(skb);
6317 vlan_macip_lens |=
6318 (skb_transport_header(skb) - skb_network_header(skb));
6319 *hdr_len +=
6320 (skb_transport_header(skb) - skb_network_header(skb));
6321 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6322 context_desc->seqnum_seed = 0;
6323
6324 /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006325 type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006326 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006327
Hao Zheng5e09a102010-11-11 13:47:59 +00006328 if (protocol == htons(ETH_P_IP))
Auke Kok9a799d72007-09-15 14:07:45 -07006329 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4;
6330 type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6331 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
6332
6333 /* MSS L4LEN IDX */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006334 mss_l4len_idx =
Auke Kok9a799d72007-09-15 14:07:45 -07006335 (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT);
6336 mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006337 /* use index 1 for TSO */
6338 mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006339 context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx);
6340
6341 tx_buffer_info->time_stamp = jiffies;
6342 tx_buffer_info->next_to_watch = i;
6343
6344 i++;
6345 if (i == tx_ring->count)
6346 i = 0;
6347 tx_ring->next_to_use = i;
6348
6349 return true;
6350 }
6351 return false;
6352}
6353
Hao Zheng5e09a102010-11-11 13:47:59 +00006354static u32 ixgbe_psum(struct ixgbe_adapter *adapter, struct sk_buff *skb,
6355 __be16 protocol)
Joe Perches7ca647b2010-09-07 21:35:40 +00006356{
6357 u32 rtn = 0;
Joe Perches7ca647b2010-09-07 21:35:40 +00006358
6359 switch (protocol) {
6360 case cpu_to_be16(ETH_P_IP):
6361 rtn |= IXGBE_ADVTXD_TUCMD_IPV4;
6362 switch (ip_hdr(skb)->protocol) {
6363 case IPPROTO_TCP:
6364 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6365 break;
6366 case IPPROTO_SCTP:
6367 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6368 break;
6369 }
6370 break;
6371 case cpu_to_be16(ETH_P_IPV6):
6372 /* XXX what about other V6 headers?? */
6373 switch (ipv6_hdr(skb)->nexthdr) {
6374 case IPPROTO_TCP:
6375 rtn |= IXGBE_ADVTXD_TUCMD_L4T_TCP;
6376 break;
6377 case IPPROTO_SCTP:
6378 rtn |= IXGBE_ADVTXD_TUCMD_L4T_SCTP;
6379 break;
6380 }
6381 break;
6382 default:
6383 if (unlikely(net_ratelimit()))
6384 e_warn(probe, "partial checksum but proto=%x!\n",
Hao Zheng5e09a102010-11-11 13:47:59 +00006385 protocol);
Joe Perches7ca647b2010-09-07 21:35:40 +00006386 break;
6387 }
6388
6389 return rtn;
6390}
6391
Auke Kok9a799d72007-09-15 14:07:45 -07006392static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006393 struct ixgbe_ring *tx_ring,
Hao Zheng5e09a102010-11-11 13:47:59 +00006394 struct sk_buff *skb, u32 tx_flags,
6395 __be16 protocol)
Auke Kok9a799d72007-09-15 14:07:45 -07006396{
6397 struct ixgbe_adv_tx_context_desc *context_desc;
6398 unsigned int i;
6399 struct ixgbe_tx_buffer *tx_buffer_info;
6400 u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0;
6401
6402 if (skb->ip_summed == CHECKSUM_PARTIAL ||
6403 (tx_flags & IXGBE_TX_FLAGS_VLAN)) {
6404 i = tx_ring->next_to_use;
6405 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006406 context_desc = IXGBE_TX_CTXTDESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006407
6408 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6409 vlan_macip_lens |=
6410 (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK);
6411 vlan_macip_lens |= (skb_network_offset(skb) <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006412 IXGBE_ADVTXD_MACLEN_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006413 if (skb->ip_summed == CHECKSUM_PARTIAL)
6414 vlan_macip_lens |= (skb_transport_header(skb) -
Joe Perchese8e9f692010-09-07 21:34:53 +00006415 skb_network_header(skb));
Auke Kok9a799d72007-09-15 14:07:45 -07006416
6417 context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens);
6418 context_desc->seqnum_seed = 0;
6419
6420 type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT |
Joe Perchese8e9f692010-09-07 21:34:53 +00006421 IXGBE_ADVTXD_DTYP_CTXT);
Auke Kok9a799d72007-09-15 14:07:45 -07006422
Joe Perches7ca647b2010-09-07 21:35:40 +00006423 if (skb->ip_summed == CHECKSUM_PARTIAL)
Hao Zheng5e09a102010-11-11 13:47:59 +00006424 type_tucmd_mlhl |= ixgbe_psum(adapter, skb, protocol);
Auke Kok9a799d72007-09-15 14:07:45 -07006425
6426 context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl);
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006427 /* use index zero for tx checksum offload */
Auke Kok9a799d72007-09-15 14:07:45 -07006428 context_desc->mss_l4len_idx = 0;
6429
6430 tx_buffer_info->time_stamp = jiffies;
6431 tx_buffer_info->next_to_watch = i;
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006432
Auke Kok9a799d72007-09-15 14:07:45 -07006433 i++;
6434 if (i == tx_ring->count)
6435 i = 0;
6436 tx_ring->next_to_use = i;
6437
6438 return true;
6439 }
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006440
Auke Kok9a799d72007-09-15 14:07:45 -07006441 return false;
6442}
6443
6444static int ixgbe_tx_map(struct ixgbe_adapter *adapter,
Joe Perchese8e9f692010-09-07 21:34:53 +00006445 struct ixgbe_ring *tx_ring,
6446 struct sk_buff *skb, u32 tx_flags,
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006447 unsigned int first, const u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006448{
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006449 struct device *dev = tx_ring->dev;
Auke Kok9a799d72007-09-15 14:07:45 -07006450 struct ixgbe_tx_buffer *tx_buffer_info;
Yi Zoueacd73f2009-05-13 13:11:06 +00006451 unsigned int len;
6452 unsigned int total = skb->len;
Auke Kok9a799d72007-09-15 14:07:45 -07006453 unsigned int offset = 0, size, count = 0, i;
6454 unsigned int nr_frags = skb_shinfo(skb)->nr_frags;
6455 unsigned int f;
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006456 unsigned int bytecount = skb->len;
6457 u16 gso_segs = 1;
Auke Kok9a799d72007-09-15 14:07:45 -07006458
6459 i = tx_ring->next_to_use;
6460
Yi Zoueacd73f2009-05-13 13:11:06 +00006461 if (tx_flags & IXGBE_TX_FLAGS_FCOE)
6462 /* excluding fcoe_crc_eof for FCoE */
6463 total -= sizeof(struct fcoe_crc_eof);
6464
6465 len = min(skb_headlen(skb), total);
Auke Kok9a799d72007-09-15 14:07:45 -07006466 while (len) {
6467 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6468 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6469
6470 tx_buffer_info->length = size;
Alexander Duycke5a43542009-12-02 16:46:56 +00006471 tx_buffer_info->mapped_as_page = false;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006472 tx_buffer_info->dma = dma_map_single(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006473 skb->data + offset,
Nick Nunley1b507732010-04-27 13:10:27 +00006474 size, DMA_TO_DEVICE);
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006475 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006476 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006477 tx_buffer_info->time_stamp = jiffies;
6478 tx_buffer_info->next_to_watch = i;
6479
6480 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006481 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006482 offset += size;
6483 count++;
Alexander Duyck44df32c2009-03-31 21:34:23 +00006484
6485 if (len) {
6486 i++;
6487 if (i == tx_ring->count)
6488 i = 0;
6489 }
Auke Kok9a799d72007-09-15 14:07:45 -07006490 }
6491
6492 for (f = 0; f < nr_frags; f++) {
6493 struct skb_frag_struct *frag;
6494
6495 frag = &skb_shinfo(skb)->frags[f];
Yi Zoueacd73f2009-05-13 13:11:06 +00006496 len = min((unsigned int)frag->size, total);
Alexander Duycke5a43542009-12-02 16:46:56 +00006497 offset = frag->page_offset;
Auke Kok9a799d72007-09-15 14:07:45 -07006498
6499 while (len) {
Alexander Duyck44df32c2009-03-31 21:34:23 +00006500 i++;
6501 if (i == tx_ring->count)
6502 i = 0;
6503
Auke Kok9a799d72007-09-15 14:07:45 -07006504 tx_buffer_info = &tx_ring->tx_buffer_info[i];
6505 size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD);
6506
6507 tx_buffer_info->length = size;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006508 tx_buffer_info->dma = dma_map_page(dev,
Alexander Duycke5a43542009-12-02 16:46:56 +00006509 frag->page,
6510 offset, size,
Nick Nunley1b507732010-04-27 13:10:27 +00006511 DMA_TO_DEVICE);
Alexander Duycke5a43542009-12-02 16:46:56 +00006512 tx_buffer_info->mapped_as_page = true;
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006513 if (dma_mapping_error(dev, tx_buffer_info->dma))
Alexander Duycke5a43542009-12-02 16:46:56 +00006514 goto dma_error;
Auke Kok9a799d72007-09-15 14:07:45 -07006515 tx_buffer_info->time_stamp = jiffies;
6516 tx_buffer_info->next_to_watch = i;
6517
6518 len -= size;
Yi Zoueacd73f2009-05-13 13:11:06 +00006519 total -= size;
Auke Kok9a799d72007-09-15 14:07:45 -07006520 offset += size;
6521 count++;
Auke Kok9a799d72007-09-15 14:07:45 -07006522 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006523 if (total == 0)
6524 break;
Auke Kok9a799d72007-09-15 14:07:45 -07006525 }
Alexander Duyck44df32c2009-03-31 21:34:23 +00006526
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006527 if (tx_flags & IXGBE_TX_FLAGS_TSO)
6528 gso_segs = skb_shinfo(skb)->gso_segs;
6529#ifdef IXGBE_FCOE
6530 /* adjust for FCoE Sequence Offload */
6531 else if (tx_flags & IXGBE_TX_FLAGS_FSO)
6532 gso_segs = DIV_ROUND_UP(skb->len - hdr_len,
6533 skb_shinfo(skb)->gso_size);
6534#endif /* IXGBE_FCOE */
6535 bytecount += (gso_segs - 1) * hdr_len;
6536
6537 /* multiply data chunks by size of headers */
6538 tx_ring->tx_buffer_info[i].bytecount = bytecount;
6539 tx_ring->tx_buffer_info[i].gso_segs = gso_segs;
Auke Kok9a799d72007-09-15 14:07:45 -07006540 tx_ring->tx_buffer_info[i].skb = skb;
6541 tx_ring->tx_buffer_info[first].next_to_watch = i;
6542
6543 return count;
Alexander Duycke5a43542009-12-02 16:46:56 +00006544
6545dma_error:
Emil Tantilov849c4542010-06-03 16:53:41 +00006546 e_dev_err("TX DMA map failed\n");
Alexander Duycke5a43542009-12-02 16:46:56 +00006547
6548 /* clear timestamp and dma mappings for failed tx_buffer_info map */
6549 tx_buffer_info->dma = 0;
6550 tx_buffer_info->time_stamp = 0;
6551 tx_buffer_info->next_to_watch = 0;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006552 if (count)
6553 count--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006554
6555 /* clear timestamp and dma mappings for remaining portion of packet */
Roel Kluinc1fa3472010-01-19 14:21:45 +00006556 while (count--) {
Joe Perchese8e9f692010-09-07 21:34:53 +00006557 if (i == 0)
Alexander Duycke5a43542009-12-02 16:46:56 +00006558 i += tx_ring->count;
Roel Kluinc1fa3472010-01-19 14:21:45 +00006559 i--;
Alexander Duycke5a43542009-12-02 16:46:56 +00006560 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyckb6ec8952010-11-16 19:26:49 -08006561 ixgbe_unmap_and_free_tx_resource(tx_ring, tx_buffer_info);
Alexander Duycke5a43542009-12-02 16:46:56 +00006562 }
6563
Anton Blancharde44d38e2010-02-03 13:12:51 +00006564 return 0;
Auke Kok9a799d72007-09-15 14:07:45 -07006565}
6566
Alexander Duyck84ea2592010-11-16 19:26:49 -08006567static void ixgbe_tx_queue(struct ixgbe_ring *tx_ring,
Joe Perchese8e9f692010-09-07 21:34:53 +00006568 int tx_flags, int count, u32 paylen, u8 hdr_len)
Auke Kok9a799d72007-09-15 14:07:45 -07006569{
6570 union ixgbe_adv_tx_desc *tx_desc = NULL;
6571 struct ixgbe_tx_buffer *tx_buffer_info;
6572 u32 olinfo_status = 0, cmd_type_len = 0;
6573 unsigned int i;
6574 u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS;
6575
6576 cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA;
6577
6578 cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT;
6579
6580 if (tx_flags & IXGBE_TX_FLAGS_VLAN)
6581 cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE;
6582
6583 if (tx_flags & IXGBE_TX_FLAGS_TSO) {
6584 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6585
6586 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006587 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006588
PJ Waskiewicz4eeae6f2008-08-26 04:27:30 -07006589 /* use index 1 context for tso */
6590 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
Auke Kok9a799d72007-09-15 14:07:45 -07006591 if (tx_flags & IXGBE_TX_FLAGS_IPV4)
6592 olinfo_status |= IXGBE_TXD_POPTS_IXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006593 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006594
6595 } else if (tx_flags & IXGBE_TX_FLAGS_CSUM)
6596 olinfo_status |= IXGBE_TXD_POPTS_TXSM <<
Joe Perchese8e9f692010-09-07 21:34:53 +00006597 IXGBE_ADVTXD_POPTS_SHIFT;
Auke Kok9a799d72007-09-15 14:07:45 -07006598
Yi Zoueacd73f2009-05-13 13:11:06 +00006599 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6600 olinfo_status |= IXGBE_ADVTXD_CC;
6601 olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT);
6602 if (tx_flags & IXGBE_TX_FLAGS_FSO)
6603 cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE;
6604 }
6605
Auke Kok9a799d72007-09-15 14:07:45 -07006606 olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT);
6607
6608 i = tx_ring->next_to_use;
6609 while (count--) {
6610 tx_buffer_info = &tx_ring->tx_buffer_info[i];
Alexander Duyck31f05a22010-08-19 13:40:31 +00006611 tx_desc = IXGBE_TX_DESC_ADV(tx_ring, i);
Auke Kok9a799d72007-09-15 14:07:45 -07006612 tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma);
6613 tx_desc->read.cmd_type_len =
Joe Perchese8e9f692010-09-07 21:34:53 +00006614 cpu_to_le32(cmd_type_len | tx_buffer_info->length);
Auke Kok9a799d72007-09-15 14:07:45 -07006615 tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status);
Auke Kok9a799d72007-09-15 14:07:45 -07006616 i++;
6617 if (i == tx_ring->count)
6618 i = 0;
6619 }
6620
6621 tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd);
6622
6623 /*
6624 * Force memory writes to complete before letting h/w
6625 * know there are new descriptors to fetch. (Only
6626 * applicable for weak-ordered memory model archs,
6627 * such as IA-64).
6628 */
6629 wmb();
6630
6631 tx_ring->next_to_use = i;
Alexander Duyck84ea2592010-11-16 19:26:49 -08006632 writel(i, tx_ring->tail);
Auke Kok9a799d72007-09-15 14:07:45 -07006633}
6634
Alexander Duyck69830522011-01-06 14:29:58 +00006635static void ixgbe_atr(struct ixgbe_ring *ring, struct sk_buff *skb,
6636 u32 tx_flags, __be16 protocol)
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006637{
Alexander Duyck69830522011-01-06 14:29:58 +00006638 struct ixgbe_q_vector *q_vector = ring->q_vector;
6639 union ixgbe_atr_hash_dword input = { .dword = 0 };
6640 union ixgbe_atr_hash_dword common = { .dword = 0 };
6641 union {
6642 unsigned char *network;
6643 struct iphdr *ipv4;
6644 struct ipv6hdr *ipv6;
6645 } hdr;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006646 struct tcphdr *th;
Alexander Duyck905e4a42011-01-06 14:29:57 +00006647 __be16 vlan_id;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006648
Alexander Duyck69830522011-01-06 14:29:58 +00006649 /* if ring doesn't have a interrupt vector, cannot perform ATR */
6650 if (!q_vector)
Guillaume Gaudonvilled3ead242010-06-29 18:29:00 +00006651 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006652
Alexander Duyck69830522011-01-06 14:29:58 +00006653 /* do nothing if sampling is disabled */
6654 if (!ring->atr_sample_rate)
6655 return;
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006656
Alexander Duyck69830522011-01-06 14:29:58 +00006657 ring->atr_count++;
6658
6659 /* snag network header to get L4 type and address */
6660 hdr.network = skb_network_header(skb);
6661
6662 /* Currently only IPv4/IPv6 with TCP is supported */
6663 if ((protocol != __constant_htons(ETH_P_IPV6) ||
6664 hdr.ipv6->nexthdr != IPPROTO_TCP) &&
6665 (protocol != __constant_htons(ETH_P_IP) ||
6666 hdr.ipv4->protocol != IPPROTO_TCP))
6667 return;
Alexander Duyckee9e0f02010-11-16 19:27:01 -08006668
6669 th = tcp_hdr(skb);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006670
Alexander Duyck69830522011-01-06 14:29:58 +00006671 /* skip this packet since the socket is closing */
6672 if (th->fin)
6673 return;
6674
6675 /* sample on all syn packets or once every atr sample count */
6676 if (!th->syn && (ring->atr_count < ring->atr_sample_rate))
6677 return;
6678
6679 /* reset sample count */
6680 ring->atr_count = 0;
6681
6682 vlan_id = htons(tx_flags >> IXGBE_TX_FLAGS_VLAN_SHIFT);
6683
6684 /*
6685 * src and dst are inverted, think how the receiver sees them
6686 *
6687 * The input is broken into two sections, a non-compressed section
6688 * containing vm_pool, vlan_id, and flow_type. The rest of the data
6689 * is XORed together and stored in the compressed dword.
6690 */
6691 input.formatted.vlan_id = vlan_id;
6692
6693 /*
6694 * since src port and flex bytes occupy the same word XOR them together
6695 * and write the value to source port portion of compressed dword
6696 */
6697 if (vlan_id)
6698 common.port.src ^= th->dest ^ __constant_htons(ETH_P_8021Q);
6699 else
6700 common.port.src ^= th->dest ^ protocol;
6701 common.port.dst ^= th->source;
6702
6703 if (protocol == __constant_htons(ETH_P_IP)) {
6704 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV4;
6705 common.ip ^= hdr.ipv4->saddr ^ hdr.ipv4->daddr;
6706 } else {
6707 input.formatted.flow_type = IXGBE_ATR_FLOW_TYPE_TCPV6;
6708 common.ip ^= hdr.ipv6->saddr.s6_addr32[0] ^
6709 hdr.ipv6->saddr.s6_addr32[1] ^
6710 hdr.ipv6->saddr.s6_addr32[2] ^
6711 hdr.ipv6->saddr.s6_addr32[3] ^
6712 hdr.ipv6->daddr.s6_addr32[0] ^
6713 hdr.ipv6->daddr.s6_addr32[1] ^
6714 hdr.ipv6->daddr.s6_addr32[2] ^
6715 hdr.ipv6->daddr.s6_addr32[3];
6716 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006717
6718 /* This assumes the Rx queue and Tx queue are bound to the same CPU */
Alexander Duyck69830522011-01-06 14:29:58 +00006719 ixgbe_fdir_add_signature_filter_82599(&q_vector->adapter->hw,
6720 input, common, ring->queue_index);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006721}
6722
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006723static int __ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006724{
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006725 netif_stop_subqueue(tx_ring->netdev, tx_ring->queue_index);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006726 /* Herbert's original patch had:
6727 * smp_mb__after_netif_stop_queue();
6728 * but since that doesn't exist yet, just open code it. */
6729 smp_mb();
6730
6731 /* We need to check again in a case another CPU has just
6732 * made room available. */
6733 if (likely(IXGBE_DESC_UNUSED(tx_ring) < size))
6734 return -EBUSY;
6735
6736 /* A reprieve! - use start_queue because it doesn't call schedule */
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006737 netif_start_subqueue(tx_ring->netdev, tx_ring->queue_index);
Alexander Duyck5b7da512010-11-16 19:26:50 -08006738 ++tx_ring->tx_stats.restart_queue;
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006739 return 0;
6740}
6741
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006742static int ixgbe_maybe_stop_tx(struct ixgbe_ring *tx_ring, int size)
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006743{
6744 if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size))
6745 return 0;
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006746 return __ixgbe_maybe_stop_tx(tx_ring, size);
Ayyappan Veeraiyane092be62008-02-01 15:58:49 -08006747}
6748
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006749static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb)
6750{
6751 struct ixgbe_adapter *adapter = netdev_priv(dev);
Yi Zou5f715822009-12-03 11:32:44 +00006752 int txq = smp_processor_id();
John Fastabend56075a92010-07-26 20:41:31 +00006753#ifdef IXGBE_FCOE
Hao Zheng5e09a102010-11-11 13:47:59 +00006754 __be16 protocol;
6755
6756 protocol = vlan_get_protocol(skb);
6757
John Fastabende5b64632011-03-08 03:44:52 +00006758 if (((protocol == htons(ETH_P_FCOE)) ||
6759 (protocol == htons(ETH_P_FIP))) &&
6760 (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)) {
6761 txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1);
6762 txq += adapter->ring_feature[RING_F_FCOE].mask;
6763 return txq;
John Fastabend56075a92010-07-26 20:41:31 +00006764 }
6765#endif
6766
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006767 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) {
6768 while (unlikely(txq >= dev->real_num_tx_queues))
6769 txq -= dev->real_num_tx_queues;
Yi Zou5f715822009-12-03 11:32:44 +00006770 return txq;
Krishna Kumarfdd3d632010-02-03 13:13:10 +00006771 }
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006772
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07006773 return skb_tx_hash(dev, skb);
6774}
6775
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006776netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
Alexander Duyck84418e32010-08-19 13:40:54 +00006777 struct ixgbe_adapter *adapter,
6778 struct ixgbe_ring *tx_ring)
Auke Kok9a799d72007-09-15 14:07:45 -07006779{
Auke Kok9a799d72007-09-15 14:07:45 -07006780 unsigned int first;
6781 unsigned int tx_flags = 0;
Ayyappan Veeraiyan30eba972008-03-03 15:03:52 -08006782 u8 hdr_len = 0;
Yi Zou5f715822009-12-03 11:32:44 +00006783 int tso;
Auke Kok9a799d72007-09-15 14:07:45 -07006784 int count = 0;
6785 unsigned int f;
Hao Zheng5e09a102010-11-11 13:47:59 +00006786 __be16 protocol;
6787
6788 protocol = vlan_get_protocol(skb);
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006789
Jesse Grosseab6d182010-10-20 13:56:03 +00006790 if (vlan_tx_tag_present(skb)) {
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006791 tx_flags |= vlan_tx_tag_get(skb);
Alexander Duyck2f90b862008-11-20 20:52:10 -08006792 if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) {
6793 tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK;
John Fastabende5b64632011-03-08 03:44:52 +00006794 tx_flags |= tx_ring->dcb_tc << 13;
Alexander Duyck2f90b862008-11-20 20:52:10 -08006795 }
6796 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6797 tx_flags |= IXGBE_TX_FLAGS_VLAN;
John Fastabend33c66bd2010-05-18 16:00:11 +00006798 } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED &&
6799 skb->priority != TC_PRIO_CONTROL) {
John Fastabende5b64632011-03-08 03:44:52 +00006800 tx_flags |= tx_ring->dcb_tc << 13;
John Fastabend2ea186a2010-02-27 03:28:24 -08006801 tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT;
6802 tx_flags |= IXGBE_TX_FLAGS_VLAN;
Auke Kok9a799d72007-09-15 14:07:45 -07006803 }
Yi Zoueacd73f2009-05-13 13:11:06 +00006804
Yi Zou09ad1cc2009-09-03 14:56:10 +00006805#ifdef IXGBE_FCOE
John Fastabend56075a92010-07-26 20:41:31 +00006806 /* for FCoE with DCB, we force the priority to what
6807 * was specified by the switch */
6808 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED &&
John Fastabende5b64632011-03-08 03:44:52 +00006809 (protocol == htons(ETH_P_FCOE)))
6810 tx_flags |= IXGBE_TX_FLAGS_FCOE;
Robert Loveca77cd52010-03-24 12:45:00 +00006811#endif
6812
Yi Zoueacd73f2009-05-13 13:11:06 +00006813 /* four things can cause us to need a context descriptor */
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006814 if (skb_is_gso(skb) ||
6815 (skb->ip_summed == CHECKSUM_PARTIAL) ||
Yi Zoueacd73f2009-05-13 13:11:06 +00006816 (tx_flags & IXGBE_TX_FLAGS_VLAN) ||
6817 (tx_flags & IXGBE_TX_FLAGS_FCOE))
Auke Kok9a799d72007-09-15 14:07:45 -07006818 count++;
6819
Jesse Brandeburg9f8cdf42008-09-11 20:03:35 -07006820 count += TXD_USE_COUNT(skb_headlen(skb));
6821 for (f = 0; f < skb_shinfo(skb)->nr_frags; f++)
Auke Kok9a799d72007-09-15 14:07:45 -07006822 count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size);
6823
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006824 if (ixgbe_maybe_stop_tx(tx_ring, count)) {
Alexander Duyck5b7da512010-11-16 19:26:50 -08006825 tx_ring->tx_stats.tx_busy++;
Auke Kok9a799d72007-09-15 14:07:45 -07006826 return NETDEV_TX_BUSY;
6827 }
Auke Kok9a799d72007-09-15 14:07:45 -07006828
Auke Kok9a799d72007-09-15 14:07:45 -07006829 first = tx_ring->next_to_use;
Yi Zoueacd73f2009-05-13 13:11:06 +00006830 if (tx_flags & IXGBE_TX_FLAGS_FCOE) {
6831#ifdef IXGBE_FCOE
6832 /* setup tx offload for FCoE */
6833 tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len);
6834 if (tso < 0) {
6835 dev_kfree_skb_any(skb);
6836 return NETDEV_TX_OK;
6837 }
6838 if (tso)
6839 tx_flags |= IXGBE_TX_FLAGS_FSO;
6840#endif /* IXGBE_FCOE */
6841 } else {
Hao Zheng5e09a102010-11-11 13:47:59 +00006842 if (protocol == htons(ETH_P_IP))
Yi Zoueacd73f2009-05-13 13:11:06 +00006843 tx_flags |= IXGBE_TX_FLAGS_IPV4;
Hao Zheng5e09a102010-11-11 13:47:59 +00006844 tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len,
6845 protocol);
Yi Zoueacd73f2009-05-13 13:11:06 +00006846 if (tso < 0) {
6847 dev_kfree_skb_any(skb);
6848 return NETDEV_TX_OK;
6849 }
6850
6851 if (tso)
6852 tx_flags |= IXGBE_TX_FLAGS_TSO;
Hao Zheng5e09a102010-11-11 13:47:59 +00006853 else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags,
6854 protocol) &&
Yi Zoueacd73f2009-05-13 13:11:06 +00006855 (skb->ip_summed == CHECKSUM_PARTIAL))
6856 tx_flags |= IXGBE_TX_FLAGS_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07006857 }
6858
Alexander Duyck8ad494b2010-11-16 19:26:47 -08006859 count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first, hdr_len);
Alexander Duyck44df32c2009-03-31 21:34:23 +00006860 if (count) {
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00006861 /* add the ATR filter if ATR is on */
Alexander Duyck69830522011-01-06 14:29:58 +00006862 if (test_bit(__IXGBE_TX_FDIR_INIT_DONE, &tx_ring->state))
6863 ixgbe_atr(tx_ring, skb, tx_flags, protocol);
Alexander Duyck84ea2592010-11-16 19:26:49 -08006864 ixgbe_tx_queue(tx_ring, tx_flags, count, skb->len, hdr_len);
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006865 ixgbe_maybe_stop_tx(tx_ring, DESC_NEEDED);
Auke Kok9a799d72007-09-15 14:07:45 -07006866
Alexander Duyck44df32c2009-03-31 21:34:23 +00006867 } else {
6868 dev_kfree_skb_any(skb);
6869 tx_ring->tx_buffer_info[first].time_stamp = 0;
6870 tx_ring->next_to_use = first;
6871 }
Auke Kok9a799d72007-09-15 14:07:45 -07006872
6873 return NETDEV_TX_OK;
6874}
6875
Alexander Duyck84418e32010-08-19 13:40:54 +00006876static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev)
6877{
6878 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6879 struct ixgbe_ring *tx_ring;
6880
6881 tx_ring = adapter->tx_ring[skb->queue_mapping];
Alexander Duyckfc77dc32010-11-16 19:26:51 -08006882 return ixgbe_xmit_frame_ring(skb, adapter, tx_ring);
Alexander Duyck84418e32010-08-19 13:40:54 +00006883}
6884
Auke Kok9a799d72007-09-15 14:07:45 -07006885/**
Auke Kok9a799d72007-09-15 14:07:45 -07006886 * ixgbe_set_mac - Change the Ethernet Address of the NIC
6887 * @netdev: network interface device structure
6888 * @p: pointer to an address structure
6889 *
6890 * Returns 0 on success, negative on failure
6891 **/
6892static int ixgbe_set_mac(struct net_device *netdev, void *p)
6893{
6894 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006895 struct ixgbe_hw *hw = &adapter->hw;
Auke Kok9a799d72007-09-15 14:07:45 -07006896 struct sockaddr *addr = p;
6897
6898 if (!is_valid_ether_addr(addr->sa_data))
6899 return -EADDRNOTAVAIL;
6900
6901 memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len);
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07006902 memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len);
Auke Kok9a799d72007-09-15 14:07:45 -07006903
Greg Rose1cdd1ec2010-01-09 02:26:46 +00006904 hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs,
6905 IXGBE_RAH_AV);
Auke Kok9a799d72007-09-15 14:07:45 -07006906
6907 return 0;
6908}
6909
Ben Hutchings6b73e102009-04-29 08:08:58 +00006910static int
6911ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr)
6912{
6913 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6914 struct ixgbe_hw *hw = &adapter->hw;
6915 u16 value;
6916 int rc;
6917
6918 if (prtad != hw->phy.mdio.prtad)
6919 return -EINVAL;
6920 rc = hw->phy.ops.read_reg(hw, addr, devad, &value);
6921 if (!rc)
6922 rc = value;
6923 return rc;
6924}
6925
6926static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad,
6927 u16 addr, u16 value)
6928{
6929 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6930 struct ixgbe_hw *hw = &adapter->hw;
6931
6932 if (prtad != hw->phy.mdio.prtad)
6933 return -EINVAL;
6934 return hw->phy.ops.write_reg(hw, addr, devad, value);
6935}
6936
6937static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd)
6938{
6939 struct ixgbe_adapter *adapter = netdev_priv(netdev);
6940
6941 return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd);
6942}
6943
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006944/**
6945 * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006946 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006947 * @netdev: network interface device structure
6948 *
6949 * Returns non-zero on failure
6950 **/
6951static int ixgbe_add_sanmac_netdev(struct net_device *dev)
6952{
6953 int err = 0;
6954 struct ixgbe_adapter *adapter = netdev_priv(dev);
6955 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6956
6957 if (is_valid_ether_addr(mac->san_addr)) {
6958 rtnl_lock();
6959 err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6960 rtnl_unlock();
6961 }
6962 return err;
6963}
6964
6965/**
6966 * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding
Jiri Pirko31278e72009-06-17 01:12:19 +00006967 * netdev->dev_addrs
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00006968 * @netdev: network interface device structure
6969 *
6970 * Returns non-zero on failure
6971 **/
6972static int ixgbe_del_sanmac_netdev(struct net_device *dev)
6973{
6974 int err = 0;
6975 struct ixgbe_adapter *adapter = netdev_priv(dev);
6976 struct ixgbe_mac_info *mac = &adapter->hw.mac;
6977
6978 if (is_valid_ether_addr(mac->san_addr)) {
6979 rtnl_lock();
6980 err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN);
6981 rtnl_unlock();
6982 }
6983 return err;
6984}
6985
Auke Kok9a799d72007-09-15 14:07:45 -07006986#ifdef CONFIG_NET_POLL_CONTROLLER
6987/*
6988 * Polling 'interrupt' - used by things like netconsole to send skbs
6989 * without having to re-enable interrupts. It's not called while
6990 * the interrupt routine is executing.
6991 */
6992static void ixgbe_netpoll(struct net_device *netdev)
6993{
6994 struct ixgbe_adapter *adapter = netdev_priv(netdev);
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00006995 int i;
Auke Kok9a799d72007-09-15 14:07:45 -07006996
Alexander Duyck1a647bd2010-01-13 01:49:13 +00006997 /* if interface is down do nothing */
6998 if (test_bit(__IXGBE_DOWN, &adapter->state))
6999 return;
7000
Auke Kok9a799d72007-09-15 14:07:45 -07007001 adapter->flags |= IXGBE_FLAG_IN_NETPOLL;
Peter P Waskiewicz Jr8f9a7162009-07-30 12:25:09 +00007002 if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) {
7003 int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS;
7004 for (i = 0; i < num_q_vectors; i++) {
7005 struct ixgbe_q_vector *q_vector = adapter->q_vector[i];
7006 ixgbe_msix_clean_many(0, q_vector);
7007 }
7008 } else {
7009 ixgbe_intr(adapter->pdev->irq, netdev);
7010 }
Auke Kok9a799d72007-09-15 14:07:45 -07007011 adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL;
Auke Kok9a799d72007-09-15 14:07:45 -07007012}
7013#endif
7014
Eric Dumazetde1036b2010-10-20 23:00:04 +00007015static struct rtnl_link_stats64 *ixgbe_get_stats64(struct net_device *netdev,
7016 struct rtnl_link_stats64 *stats)
7017{
7018 struct ixgbe_adapter *adapter = netdev_priv(netdev);
7019 int i;
7020
Eric Dumazet1a515022010-11-16 19:26:42 -08007021 rcu_read_lock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007022 for (i = 0; i < adapter->num_rx_queues; i++) {
Eric Dumazet1a515022010-11-16 19:26:42 -08007023 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
Eric Dumazetde1036b2010-10-20 23:00:04 +00007024 u64 bytes, packets;
7025 unsigned int start;
7026
Eric Dumazet1a515022010-11-16 19:26:42 -08007027 if (ring) {
7028 do {
7029 start = u64_stats_fetch_begin_bh(&ring->syncp);
7030 packets = ring->stats.packets;
7031 bytes = ring->stats.bytes;
7032 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7033 stats->rx_packets += packets;
7034 stats->rx_bytes += bytes;
7035 }
Eric Dumazetde1036b2010-10-20 23:00:04 +00007036 }
Eric Dumazet1ac9ad12011-01-12 12:13:14 +00007037
7038 for (i = 0; i < adapter->num_tx_queues; i++) {
7039 struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
7040 u64 bytes, packets;
7041 unsigned int start;
7042
7043 if (ring) {
7044 do {
7045 start = u64_stats_fetch_begin_bh(&ring->syncp);
7046 packets = ring->stats.packets;
7047 bytes = ring->stats.bytes;
7048 } while (u64_stats_fetch_retry_bh(&ring->syncp, start));
7049 stats->tx_packets += packets;
7050 stats->tx_bytes += bytes;
7051 }
7052 }
Eric Dumazet1a515022010-11-16 19:26:42 -08007053 rcu_read_unlock();
Eric Dumazetde1036b2010-10-20 23:00:04 +00007054 /* following stats updated by ixgbe_watchdog_task() */
7055 stats->multicast = netdev->stats.multicast;
7056 stats->rx_errors = netdev->stats.rx_errors;
7057 stats->rx_length_errors = netdev->stats.rx_length_errors;
7058 stats->rx_crc_errors = netdev->stats.rx_crc_errors;
7059 stats->rx_missed_errors = netdev->stats.rx_missed_errors;
7060 return stats;
7061}
7062
7063
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007064static const struct net_device_ops ixgbe_netdev_ops = {
Joe Perchese8e9f692010-09-07 21:34:53 +00007065 .ndo_open = ixgbe_open,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007066 .ndo_stop = ixgbe_close,
Stephen Hemminger00829822008-11-20 20:14:53 -08007067 .ndo_start_xmit = ixgbe_xmit_frame,
Stephen Hemminger09a3b1f2009-03-21 13:40:01 -07007068 .ndo_select_queue = ixgbe_select_queue,
Chris Leeche90d4002009-03-10 16:00:24 +00007069 .ndo_set_rx_mode = ixgbe_set_rx_mode,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007070 .ndo_set_multicast_list = ixgbe_set_rx_mode,
7071 .ndo_validate_addr = eth_validate_addr,
7072 .ndo_set_mac_address = ixgbe_set_mac,
7073 .ndo_change_mtu = ixgbe_change_mtu,
7074 .ndo_tx_timeout = ixgbe_tx_timeout,
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007075 .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid,
7076 .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid,
Ben Hutchings6b73e102009-04-29 08:08:58 +00007077 .ndo_do_ioctl = ixgbe_ioctl,
Greg Rose7f016482010-05-04 22:12:06 +00007078 .ndo_set_vf_mac = ixgbe_ndo_set_vf_mac,
7079 .ndo_set_vf_vlan = ixgbe_ndo_set_vf_vlan,
7080 .ndo_set_vf_tx_rate = ixgbe_ndo_set_vf_bw,
7081 .ndo_get_vf_config = ixgbe_ndo_get_vf_config,
Eric Dumazetde1036b2010-10-20 23:00:04 +00007082 .ndo_get_stats64 = ixgbe_get_stats64,
John Fastabend24095aa2011-02-23 05:58:03 +00007083#ifdef CONFIG_IXGBE_DCB
7084 .ndo_setup_tc = ixgbe_setup_tc,
7085#endif
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007086#ifdef CONFIG_NET_POLL_CONTROLLER
7087 .ndo_poll_controller = ixgbe_netpoll,
7088#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007089#ifdef IXGBE_FCOE
7090 .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get,
Yi Zou68a683c2011-02-01 07:22:16 +00007091 .ndo_fcoe_ddp_target = ixgbe_fcoe_ddp_target,
Yi Zou332d4a72009-05-13 13:11:53 +00007092 .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put,
Yi Zou8450ff82009-08-31 12:32:14 +00007093 .ndo_fcoe_enable = ixgbe_fcoe_enable,
7094 .ndo_fcoe_disable = ixgbe_fcoe_disable,
Yi Zou61a1fa12009-10-28 18:24:56 +00007095 .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn,
Yi Zou332d4a72009-05-13 13:11:53 +00007096#endif /* IXGBE_FCOE */
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007097};
7098
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007099static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter,
7100 const struct ixgbe_info *ii)
7101{
7102#ifdef CONFIG_PCI_IOV
7103 struct ixgbe_hw *hw = &adapter->hw;
7104 int err;
7105
Greg Rose3377eba792010-12-07 08:16:45 +00007106 if (hw->mac.type == ixgbe_mac_82598EB || !max_vfs)
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007107 return;
7108
7109 /* The 82599 supports up to 64 VFs per physical function
7110 * but this implementation limits allocation to 63 so that
7111 * basic networking resources are still available to the
7112 * physical function
7113 */
7114 adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs;
7115 adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED;
7116 err = pci_enable_sriov(adapter->pdev, adapter->num_vfs);
7117 if (err) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007118 e_err(probe, "Failed to enable PCI sriov: %d\n", err);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007119 goto err_novfs;
7120 }
7121 /* If call to enable VFs succeeded then allocate memory
7122 * for per VF control structures.
7123 */
7124 adapter->vfinfo =
7125 kcalloc(adapter->num_vfs,
7126 sizeof(struct vf_data_storage), GFP_KERNEL);
7127 if (adapter->vfinfo) {
7128 /* Now that we're sure SR-IOV is enabled
7129 * and memory allocated set up the mailbox parameters
7130 */
7131 ixgbe_init_mbx_params_pf(hw);
7132 memcpy(&hw->mbx.ops, ii->mbx_ops,
7133 sizeof(hw->mbx.ops));
7134
7135 /* Disable RSC when in SR-IOV mode */
7136 adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE |
7137 IXGBE_FLAG2_RSC_ENABLED);
7138 return;
7139 }
7140
7141 /* Oh oh */
Emil Tantilov396e7992010-07-01 20:05:12 +00007142 e_err(probe, "Unable to allocate memory for VF Data Storage - "
7143 "SRIOV disabled\n");
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007144 pci_disable_sriov(adapter->pdev);
7145
7146err_novfs:
7147 adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED;
7148 adapter->num_vfs = 0;
7149#endif /* CONFIG_PCI_IOV */
7150}
7151
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007152/**
Auke Kok9a799d72007-09-15 14:07:45 -07007153 * ixgbe_probe - Device Initialization Routine
7154 * @pdev: PCI device information struct
7155 * @ent: entry in ixgbe_pci_tbl
7156 *
7157 * Returns 0 on success, negative on failure
7158 *
7159 * ixgbe_probe initializes an adapter identified by a pci_dev structure.
7160 * The OS initialization, configuring of the adapter private structure,
7161 * and a hardware reset occur.
7162 **/
7163static int __devinit ixgbe_probe(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007164 const struct pci_device_id *ent)
Auke Kok9a799d72007-09-15 14:07:45 -07007165{
7166 struct net_device *netdev;
7167 struct ixgbe_adapter *adapter = NULL;
7168 struct ixgbe_hw *hw;
7169 const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data];
Auke Kok9a799d72007-09-15 14:07:45 -07007170 static int cards_found;
7171 int i, err, pci_using_dac;
Don Skidmore289700db2010-12-03 03:32:58 +00007172 u8 part_str[IXGBE_PBANUM_LENGTH];
John Fastabendc85a2612010-02-25 23:15:21 +00007173 unsigned int indices = num_possible_cpus();
Yi Zoueacd73f2009-05-13 13:11:06 +00007174#ifdef IXGBE_FCOE
7175 u16 device_caps;
7176#endif
Don Skidmore289700db2010-12-03 03:32:58 +00007177 u32 eec;
Auke Kok9a799d72007-09-15 14:07:45 -07007178
Andy Gospodarekbded64a2010-07-21 06:40:31 +00007179 /* Catch broken hardware that put the wrong VF device ID in
7180 * the PCIe SR-IOV capability.
7181 */
7182 if (pdev->is_virtfn) {
7183 WARN(1, KERN_ERR "%s (%hx:%hx) should not be a VF!\n",
7184 pci_name(pdev), pdev->vendor, pdev->device);
7185 return -EINVAL;
7186 }
7187
gouji-new9ce77662009-05-06 10:44:45 +00007188 err = pci_enable_device_mem(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007189 if (err)
7190 return err;
7191
Nick Nunley1b507732010-04-27 13:10:27 +00007192 if (!dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)) &&
7193 !dma_set_coherent_mask(&pdev->dev, DMA_BIT_MASK(64))) {
Auke Kok9a799d72007-09-15 14:07:45 -07007194 pci_using_dac = 1;
7195 } else {
Nick Nunley1b507732010-04-27 13:10:27 +00007196 err = dma_set_mask(&pdev->dev, DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007197 if (err) {
Nick Nunley1b507732010-04-27 13:10:27 +00007198 err = dma_set_coherent_mask(&pdev->dev,
7199 DMA_BIT_MASK(32));
Auke Kok9a799d72007-09-15 14:07:45 -07007200 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007201 dev_err(&pdev->dev,
7202 "No usable DMA configuration, aborting\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007203 goto err_dma;
7204 }
7205 }
7206 pci_using_dac = 0;
7207 }
7208
gouji-new9ce77662009-05-06 10:44:45 +00007209 err = pci_request_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007210 IORESOURCE_MEM), ixgbe_driver_name);
Auke Kok9a799d72007-09-15 14:07:45 -07007211 if (err) {
Dan Carpenterb8bc0422010-07-27 00:05:56 +00007212 dev_err(&pdev->dev,
7213 "pci_request_selected_regions failed 0x%x\n", err);
Auke Kok9a799d72007-09-15 14:07:45 -07007214 goto err_pci_reg;
7215 }
7216
Frans Pop19d5afd2009-10-02 10:04:12 -07007217 pci_enable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007218
Auke Kok9a799d72007-09-15 14:07:45 -07007219 pci_set_master(pdev);
Wendy Xiongfb3b27b2008-04-23 11:09:24 -07007220 pci_save_state(pdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007221
John Fastabendc85a2612010-02-25 23:15:21 +00007222 if (ii->mac == ixgbe_mac_82598EB)
7223 indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES);
7224 else
7225 indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES);
7226
John Fastabende5b64632011-03-08 03:44:52 +00007227#if defined(CONFIG_DCB)
John Fastabendc85a2612010-02-25 23:15:21 +00007228 indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES);
John Fastabende5b64632011-03-08 03:44:52 +00007229#elif defined(IXGBE_FCOE)
John Fastabendc85a2612010-02-25 23:15:21 +00007230 indices += min_t(unsigned int, num_possible_cpus(),
7231 IXGBE_MAX_FCOE_INDICES);
7232#endif
John Fastabendc85a2612010-02-25 23:15:21 +00007233 netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices);
Auke Kok9a799d72007-09-15 14:07:45 -07007234 if (!netdev) {
7235 err = -ENOMEM;
7236 goto err_alloc_etherdev;
7237 }
7238
Auke Kok9a799d72007-09-15 14:07:45 -07007239 SET_NETDEV_DEV(netdev, &pdev->dev);
7240
Auke Kok9a799d72007-09-15 14:07:45 -07007241 adapter = netdev_priv(netdev);
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007242 pci_set_drvdata(pdev, adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007243
7244 adapter->netdev = netdev;
7245 adapter->pdev = pdev;
7246 hw = &adapter->hw;
7247 hw->back = adapter;
7248 adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1;
7249
Jeff Kirsher05857982008-09-11 19:57:00 -07007250 hw->hw_addr = ioremap(pci_resource_start(pdev, 0),
Joe Perchese8e9f692010-09-07 21:34:53 +00007251 pci_resource_len(pdev, 0));
Auke Kok9a799d72007-09-15 14:07:45 -07007252 if (!hw->hw_addr) {
7253 err = -EIO;
7254 goto err_ioremap;
7255 }
7256
7257 for (i = 1; i <= 5; i++) {
7258 if (pci_resource_len(pdev, i) == 0)
7259 continue;
7260 }
7261
Stephen Hemminger0edc3522008-11-19 22:24:29 -08007262 netdev->netdev_ops = &ixgbe_netdev_ops;
Auke Kok9a799d72007-09-15 14:07:45 -07007263 ixgbe_set_ethtool_ops(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007264 netdev->watchdog_timeo = 5 * HZ;
Don Skidmore9fe93af2010-12-03 09:33:54 +00007265 strncpy(netdev->name, pci_name(pdev), sizeof(netdev->name) - 1);
Auke Kok9a799d72007-09-15 14:07:45 -07007266
Auke Kok9a799d72007-09-15 14:07:45 -07007267 adapter->bd_number = cards_found;
7268
Auke Kok9a799d72007-09-15 14:07:45 -07007269 /* Setup hw api */
7270 memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops));
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007271 hw->mac.type = ii->mac;
Auke Kok9a799d72007-09-15 14:07:45 -07007272
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007273 /* EEPROM */
7274 memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops));
7275 eec = IXGBE_READ_REG(hw, IXGBE_EEC);
7276 /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */
7277 if (!(eec & (1 << 8)))
7278 hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic;
7279
7280 /* PHY */
7281 memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops));
Donald Skidmorec4900be2008-11-20 21:11:42 -08007282 hw->phy.sfp_type = ixgbe_sfp_type_unknown;
Ben Hutchings6b73e102009-04-29 08:08:58 +00007283 /* ixgbe_identify_phy_generic will set prtad and mmds properly */
7284 hw->phy.mdio.prtad = MDIO_PRTAD_NONE;
7285 hw->phy.mdio.mmds = 0;
7286 hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22;
7287 hw->phy.mdio.dev = netdev;
7288 hw->phy.mdio.mdio_read = ixgbe_mdio_read;
7289 hw->phy.mdio.mdio_write = ixgbe_mdio_write;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007290
7291 /* set up this timer and work struct before calling get_invariants
7292 * which might start the timer
7293 */
7294 init_timer(&adapter->sfp_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00007295 adapter->sfp_timer.function = ixgbe_sfp_timer;
Donald Skidmorec4900be2008-11-20 21:11:42 -08007296 adapter->sfp_timer.data = (unsigned long) adapter;
7297
7298 INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007299
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007300 /* multispeed fiber has its own tasklet, called from GPI SDP1 context */
7301 INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task);
7302
7303 /* a new SFP+ module arrival, called from GPI SDP2 context */
7304 INIT_WORK(&adapter->sfp_config_module_task,
Joe Perchese8e9f692010-09-07 21:34:53 +00007305 ixgbe_sfp_config_module_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007306
Don Skidmore8ca783a2009-05-26 20:40:47 -07007307 ii->get_invariants(hw);
Auke Kok9a799d72007-09-15 14:07:45 -07007308
7309 /* setup the private structure */
7310 err = ixgbe_sw_init(adapter);
7311 if (err)
7312 goto err_sw_init;
7313
Don Skidmoree86bff02010-02-11 04:14:08 +00007314 /* Make it possible the adapter to be woken up via WOL */
Don Skidmoreb93a2222010-11-16 19:27:17 -08007315 switch (adapter->hw.mac.type) {
7316 case ixgbe_mac_82599EB:
7317 case ixgbe_mac_X540:
Don Skidmoree86bff02010-02-11 04:14:08 +00007318 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Don Skidmoreb93a2222010-11-16 19:27:17 -08007319 break;
7320 default:
7321 break;
7322 }
Don Skidmoree86bff02010-02-11 04:14:08 +00007323
Don Skidmorebf069c92009-05-07 10:39:54 +00007324 /*
7325 * If there is a fan on this device and it has failed log the
7326 * failure.
7327 */
7328 if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) {
7329 u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP);
7330 if (esdp & IXGBE_ESDP_SDP1)
Emil Tantilov396e7992010-07-01 20:05:12 +00007331 e_crit(probe, "Fan has stopped, replace the adapter\n");
Don Skidmorebf069c92009-05-07 10:39:54 +00007332 }
7333
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007334 /* reset_hw fills in the perm_addr as well */
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007335 hw->phy.reset_if_overtemp = true;
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007336 err = hw->mac.ops.reset_hw(hw);
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007337 hw->phy.reset_if_overtemp = false;
Don Skidmore8ca783a2009-05-26 20:40:47 -07007338 if (err == IXGBE_ERR_SFP_NOT_PRESENT &&
7339 hw->mac.type == ixgbe_mac_82598EB) {
7340 /*
7341 * Start a kernel thread to watch for a module to arrive.
7342 * Only do this for 82598, since 82599 will generate
7343 * interrupts on module arrival.
7344 */
7345 set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
7346 mod_timer(&adapter->sfp_timer,
7347 round_jiffies(jiffies + (2 * HZ)));
7348 err = 0;
7349 } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007350 e_dev_err("failed to initialize because an unsupported SFP+ "
7351 "module type was detected.\n");
7352 e_dev_err("Reload the driver after installing a supported "
7353 "module.\n");
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007354 goto err_sw_init;
7355 } else if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007356 e_dev_err("HW Init failed: %d\n", err);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007357 goto err_sw_init;
7358 }
7359
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007360 ixgbe_probe_vf(adapter, ii);
7361
Emil Tantilov396e7992010-07-01 20:05:12 +00007362 netdev->features = NETIF_F_SG |
Joe Perchese8e9f692010-09-07 21:34:53 +00007363 NETIF_F_IP_CSUM |
7364 NETIF_F_HW_VLAN_TX |
7365 NETIF_F_HW_VLAN_RX |
7366 NETIF_F_HW_VLAN_FILTER;
Auke Kok9a799d72007-09-15 14:07:45 -07007367
Jesse Brandeburge9990a92008-08-26 04:27:24 -07007368 netdev->features |= NETIF_F_IPV6_CSUM;
Auke Kok9a799d72007-09-15 14:07:45 -07007369 netdev->features |= NETIF_F_TSO;
Auke Kok9a799d72007-09-15 14:07:45 -07007370 netdev->features |= NETIF_F_TSO6;
Herbert Xu78b6f4c2009-01-18 21:49:45 -08007371 netdev->features |= NETIF_F_GRO;
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007372 netdev->features |= NETIF_F_RXHASH;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007373
Don Skidmore58be7662011-04-12 09:42:11 +00007374 switch (adapter->hw.mac.type) {
7375 case ixgbe_mac_82599EB:
7376 case ixgbe_mac_X540:
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007377 netdev->features |= NETIF_F_SCTP_CSUM;
Don Skidmore58be7662011-04-12 09:42:11 +00007378 break;
7379 default:
7380 break;
7381 }
Jesse Brandeburg45a5ead2009-04-27 22:36:35 +00007382
Jeff Kirsherad31c402008-06-05 04:05:30 -07007383 netdev->vlan_features |= NETIF_F_TSO;
7384 netdev->vlan_features |= NETIF_F_TSO6;
Jesse Brandeburg22f32b7a52008-08-26 04:27:18 -07007385 netdev->vlan_features |= NETIF_F_IP_CSUM;
Alexander Duyckcd1da502009-08-25 04:47:50 +00007386 netdev->vlan_features |= NETIF_F_IPV6_CSUM;
Jeff Kirsherad31c402008-06-05 04:05:30 -07007387 netdev->vlan_features |= NETIF_F_SG;
7388
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007389 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7390 adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED |
7391 IXGBE_FLAG_DCB_ENABLED);
Alexander Duyck2f90b862008-11-20 20:52:10 -08007392
Jeff Kirsher7a6b6f52008-11-25 01:02:08 -08007393#ifdef CONFIG_IXGBE_DCB
Alexander Duyck2f90b862008-11-20 20:52:10 -08007394 netdev->dcbnl_ops = &dcbnl_ops;
7395#endif
7396
Yi Zoueacd73f2009-05-13 13:11:06 +00007397#ifdef IXGBE_FCOE
Yi Zou0d551582009-07-22 14:07:12 +00007398 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
Yi Zoueacd73f2009-05-13 13:11:06 +00007399 if (hw->mac.ops.get_device_caps) {
7400 hw->mac.ops.get_device_caps(hw, &device_caps);
Yi Zou0d551582009-07-22 14:07:12 +00007401 if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)
7402 adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE;
Yi Zoueacd73f2009-05-13 13:11:06 +00007403 }
7404 }
Yi Zou5e09d7f2010-07-19 13:59:52 +00007405 if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) {
7406 netdev->vlan_features |= NETIF_F_FCOE_CRC;
7407 netdev->vlan_features |= NETIF_F_FSO;
7408 netdev->vlan_features |= NETIF_F_FCOE_MTU;
7409 }
Yi Zoueacd73f2009-05-13 13:11:06 +00007410#endif /* IXGBE_FCOE */
Yi Zou7b872a52010-09-22 17:57:58 +00007411 if (pci_using_dac) {
Auke Kok9a799d72007-09-15 14:07:45 -07007412 netdev->features |= NETIF_F_HIGHDMA;
Yi Zou7b872a52010-09-22 17:57:58 +00007413 netdev->vlan_features |= NETIF_F_HIGHDMA;
7414 }
Auke Kok9a799d72007-09-15 14:07:45 -07007415
Peter P Waskiewicz Jr0c19d6a2009-07-30 12:25:28 +00007416 if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED)
Alexander Duyckf8212f92009-04-27 22:42:37 +00007417 netdev->features |= NETIF_F_LRO;
7418
Auke Kok9a799d72007-09-15 14:07:45 -07007419 /* make sure the EEPROM is good */
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007420 if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007421 e_dev_err("The EEPROM Checksum Is Not Valid\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007422 err = -EIO;
7423 goto err_eeprom;
7424 }
7425
7426 memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len);
7427 memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len);
7428
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007429 if (ixgbe_validate_mac_addr(netdev->perm_addr)) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007430 e_dev_err("invalid MAC address\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007431 err = -EIO;
7432 goto err_eeprom;
7433 }
7434
Don Skidmorec6ecf392010-12-03 03:31:51 +00007435 /* power down the optics for multispeed fiber and 82599 SFP+ fiber */
7436 if (hw->mac.ops.disable_tx_laser &&
7437 ((hw->phy.multispeed_fiber) ||
Don Skidmore9f911702010-12-03 13:24:05 +00007438 ((hw->mac.ops.get_media_type(hw) == ixgbe_media_type_fiber) &&
Don Skidmorec6ecf392010-12-03 03:31:51 +00007439 (hw->mac.type == ixgbe_mac_82599EB))))
Peter Waskiewicz61fac742010-04-27 00:38:15 +00007440 hw->mac.ops.disable_tx_laser(hw);
7441
Auke Kok9a799d72007-09-15 14:07:45 -07007442 init_timer(&adapter->watchdog_timer);
Joe Perchesc061b182010-08-23 18:20:03 +00007443 adapter->watchdog_timer.function = ixgbe_watchdog;
Auke Kok9a799d72007-09-15 14:07:45 -07007444 adapter->watchdog_timer.data = (unsigned long)adapter;
7445
7446 INIT_WORK(&adapter->reset_task, ixgbe_reset_task);
Jesse Brandeburgcf8280e2008-09-11 19:55:32 -07007447 INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007448
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007449 err = ixgbe_init_interrupt_scheme(adapter);
7450 if (err)
7451 goto err_sw_init;
Auke Kok9a799d72007-09-15 14:07:45 -07007452
Emil Tantilov67a74ee2011-04-23 04:50:40 +00007453 if (!(adapter->flags & IXGBE_FLAG_RSS_ENABLED))
7454 netdev->features &= ~NETIF_F_RXHASH;
7455
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007456 switch (pdev->device) {
Don Skidmore0b077fe2010-12-03 03:32:13 +00007457 case IXGBE_DEV_ID_82599_SFP:
7458 /* Only this subdevice supports WOL */
7459 if (pdev->subsystem_device == IXGBE_SUBDEV_ID_82599_SFP)
7460 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7461 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7462 break;
Alexander Duyck50d6c682010-11-16 19:27:05 -08007463 case IXGBE_DEV_ID_82599_COMBO_BACKPLANE:
7464 /* All except this subdevice support WOL */
Don Skidmore0b077fe2010-12-03 03:32:13 +00007465 if (pdev->subsystem_device != IXGBE_SUBDEV_ID_82599_KX4_KR_MEZZ)
7466 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
7467 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
7468 break;
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007469 case IXGBE_DEV_ID_82599_KX4:
Waskiewicz Jr, Peter P495dce12009-04-23 11:15:18 +00007470 adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX |
Joe Perchese8e9f692010-09-07 21:34:53 +00007471 IXGBE_WUFC_MC | IXGBE_WUFC_BC);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007472 break;
7473 default:
7474 adapter->wol = 0;
7475 break;
7476 }
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007477 device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol);
7478
PJ Waskiewicz04f165e2009-04-09 22:27:57 +00007479 /* pick up the PCI bus settings for reporting later */
7480 hw->mac.ops.get_bus_info(hw);
7481
Auke Kok9a799d72007-09-15 14:07:45 -07007482 /* print bus type/speed/width info */
Emil Tantilov849c4542010-06-03 16:53:41 +00007483 e_dev_info("(PCI Express:%s:%s) %pM\n",
Don Skidmore67163442011-04-26 08:00:00 +00007484 (hw->bus.speed == ixgbe_bus_speed_5000 ? "5.0GT/s" :
7485 hw->bus.speed == ixgbe_bus_speed_2500 ? "2.5GT/s" :
Joe Perchese8e9f692010-09-07 21:34:53 +00007486 "Unknown"),
7487 (hw->bus.width == ixgbe_bus_width_pcie_x8 ? "Width x8" :
7488 hw->bus.width == ixgbe_bus_width_pcie_x4 ? "Width x4" :
7489 hw->bus.width == ixgbe_bus_width_pcie_x1 ? "Width x1" :
7490 "Unknown"),
7491 netdev->dev_addr);
Don Skidmore289700db2010-12-03 03:32:58 +00007492
7493 err = ixgbe_read_pba_string_generic(hw, part_str, IXGBE_PBANUM_LENGTH);
7494 if (err)
Don Skidmore9fe93af2010-12-03 09:33:54 +00007495 strncpy(part_str, "Unknown", IXGBE_PBANUM_LENGTH);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007496 if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present)
Don Skidmore289700db2010-12-03 03:32:58 +00007497 e_dev_info("MAC: %d, PHY: %d, SFP+: %d, PBA No: %s\n",
Emil Tantilov849c4542010-06-03 16:53:41 +00007498 hw->mac.type, hw->phy.type, hw->phy.sfp_type,
Don Skidmore289700db2010-12-03 03:32:58 +00007499 part_str);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007500 else
Don Skidmore289700db2010-12-03 03:32:58 +00007501 e_dev_info("MAC: %d, PHY: %d, PBA No: %s\n",
7502 hw->mac.type, hw->phy.type, part_str);
Auke Kok9a799d72007-09-15 14:07:45 -07007503
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007504 if (hw->bus.width <= ixgbe_bus_width_pcie_x4) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007505 e_dev_warn("PCI-Express bandwidth available for this card is "
7506 "not sufficient for optimal performance.\n");
7507 e_dev_warn("For optimal performance a x8 PCI-Express slot "
7508 "is required.\n");
Auke Kok0c254d82008-02-11 09:25:56 -08007509 }
7510
Peter P Waskiewicz Jr34b03682009-02-05 23:54:42 -08007511 /* save off EEPROM version number */
7512 hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version);
7513
Auke Kok9a799d72007-09-15 14:07:45 -07007514 /* reset the hardware with the new settings */
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007515 err = hw->mac.ops.start_hw(hw);
Jesse Brandeburgc44ade92008-09-11 19:59:59 -07007516
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007517 if (err == IXGBE_ERR_EEPROM_VERSION) {
7518 /* We are running on a pre-production device, log a warning */
Emil Tantilov849c4542010-06-03 16:53:41 +00007519 e_dev_warn("This device is a pre-production adapter/LOM. "
7520 "Please be aware there may be issues associated "
7521 "with your hardware. If you are experiencing "
7522 "problems please contact your Intel or hardware "
7523 "representative who provided you with this "
7524 "hardware.\n");
Peter P Waskiewicz Jr794caeb2009-06-04 16:02:24 +00007525 }
Auke Kok9a799d72007-09-15 14:07:45 -07007526 strcpy(netdev->name, "eth%d");
7527 err = register_netdev(netdev);
7528 if (err)
7529 goto err_register;
7530
Jesse Brandeburg54386462009-04-17 20:44:27 +00007531 /* carrier off reporting is important to ethtool even BEFORE open */
7532 netif_carrier_off(netdev);
7533
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007534 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7535 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7536 INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task);
7537
Mallikarjuna R Chilakala119fc602010-05-20 23:07:06 -07007538 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
Joe Perchese8e9f692010-09-07 21:34:53 +00007539 INIT_WORK(&adapter->check_overtemp_task,
7540 ixgbe_check_overtemp_task);
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007541#ifdef CONFIG_IXGBE_DCA
Denis V. Lunev652f0932008-03-27 14:39:17 +03007542 if (dca_add_requester(&pdev->dev) == 0) {
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007543 adapter->flags |= IXGBE_FLAG_DCA_ENABLED;
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007544 ixgbe_setup_dca(adapter);
7545 }
7546#endif
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007547 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007548 e_info(probe, "IOV is enabled with %d VFs\n", adapter->num_vfs);
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007549 for (i = 0; i < adapter->num_vfs; i++)
7550 ixgbe_vf_configuration(pdev, (i | 0x10000000));
7551 }
7552
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007553 /* add san mac addr to netdev */
7554 ixgbe_add_sanmac_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007555
Emil Tantilov849c4542010-06-03 16:53:41 +00007556 e_dev_info("Intel(R) 10 Gigabit Network Connection\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007557 cards_found++;
7558 return 0;
7559
7560err_register:
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007561 ixgbe_release_hw_control(adapter);
Alexander Duyck7a921c92009-05-06 10:43:28 +00007562 ixgbe_clear_interrupt_scheme(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007563err_sw_init:
7564err_eeprom:
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007565 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7566 ixgbe_disable_sriov(adapter);
Donald Skidmorec4900be2008-11-20 21:11:42 -08007567 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
7568 del_timer_sync(&adapter->sfp_timer);
7569 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007570 cancel_work_sync(&adapter->multispeed_fiber_task);
7571 cancel_work_sync(&adapter->sfp_config_module_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007572 iounmap(hw->hw_addr);
7573err_ioremap:
7574 free_netdev(netdev);
7575err_alloc_etherdev:
Joe Perchese8e9f692010-09-07 21:34:53 +00007576 pci_release_selected_regions(pdev,
7577 pci_select_bars(pdev, IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007578err_pci_reg:
7579err_dma:
7580 pci_disable_device(pdev);
7581 return err;
7582}
7583
7584/**
7585 * ixgbe_remove - Device Removal Routine
7586 * @pdev: PCI device information struct
7587 *
7588 * ixgbe_remove is called by the PCI subsystem to alert the driver
7589 * that it should release a PCI device. The could be caused by a
7590 * Hot-Plug event, or because the driver is going to be removed from
7591 * memory.
7592 **/
7593static void __devexit ixgbe_remove(struct pci_dev *pdev)
7594{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007595 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7596 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007597
7598 set_bit(__IXGBE_DOWN, &adapter->state);
Tejun Heo760141a2010-12-12 16:45:14 +01007599
7600 /*
7601 * The timers may be rescheduled, so explicitly disable them
7602 * from being rescheduled.
Donald Skidmorec4900be2008-11-20 21:11:42 -08007603 */
7604 clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state);
Auke Kok9a799d72007-09-15 14:07:45 -07007605 del_timer_sync(&adapter->watchdog_timer);
Donald Skidmorec4900be2008-11-20 21:11:42 -08007606 del_timer_sync(&adapter->sfp_timer);
Tejun Heo760141a2010-12-12 16:45:14 +01007607
Donald Skidmorec4900be2008-11-20 21:11:42 -08007608 cancel_work_sync(&adapter->watchdog_task);
7609 cancel_work_sync(&adapter->sfp_task);
PJ Waskiewicze8e26352009-02-27 15:45:05 +00007610 cancel_work_sync(&adapter->multispeed_fiber_task);
7611 cancel_work_sync(&adapter->sfp_config_module_task);
Peter P Waskiewicz Jrc4cf55e2009-06-04 16:01:43 +00007612 if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE ||
7613 adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)
7614 cancel_work_sync(&adapter->fdir_reinit_task);
Tejun Heo760141a2010-12-12 16:45:14 +01007615 if (adapter->flags2 & IXGBE_FLAG2_TEMP_SENSOR_CAPABLE)
7616 cancel_work_sync(&adapter->check_overtemp_task);
Auke Kok9a799d72007-09-15 14:07:45 -07007617
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007618#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007619 if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) {
7620 adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED;
7621 dca_remove_requester(&pdev->dev);
7622 IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1);
7623 }
7624
7625#endif
Yi Zou332d4a72009-05-13 13:11:53 +00007626#ifdef IXGBE_FCOE
7627 if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED)
7628 ixgbe_cleanup_fcoe(adapter);
7629
7630#endif /* IXGBE_FCOE */
PJ Waskiewicz0365e6e2009-05-17 12:32:25 +00007631
7632 /* remove the added san mac */
7633 ixgbe_del_sanmac_netdev(netdev);
7634
Donald Skidmorec4900be2008-11-20 21:11:42 -08007635 if (netdev->reg_state == NETREG_REGISTERED)
7636 unregister_netdev(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007637
Greg Rose1cdd1ec2010-01-09 02:26:46 +00007638 if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED)
7639 ixgbe_disable_sriov(adapter);
7640
Alexander Duyck7a921c92009-05-06 10:43:28 +00007641 ixgbe_clear_interrupt_scheme(adapter);
Ayyappan Veeraiyan5eba3692008-02-01 15:59:04 -08007642
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007643 ixgbe_release_hw_control(adapter);
Auke Kok9a799d72007-09-15 14:07:45 -07007644
7645 iounmap(adapter->hw.hw_addr);
gouji-new9ce77662009-05-06 10:44:45 +00007646 pci_release_selected_regions(pdev, pci_select_bars(pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007647 IORESOURCE_MEM));
Auke Kok9a799d72007-09-15 14:07:45 -07007648
Emil Tantilov849c4542010-06-03 16:53:41 +00007649 e_dev_info("complete\n");
Ayyappan Veeraiyan021230d2008-03-03 15:03:45 -08007650
Auke Kok9a799d72007-09-15 14:07:45 -07007651 free_netdev(netdev);
7652
Frans Pop19d5afd2009-10-02 10:04:12 -07007653 pci_disable_pcie_error_reporting(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007654
Auke Kok9a799d72007-09-15 14:07:45 -07007655 pci_disable_device(pdev);
7656}
7657
7658/**
7659 * ixgbe_io_error_detected - called when PCI error is detected
7660 * @pdev: Pointer to PCI device
7661 * @state: The current pci connection state
7662 *
7663 * This function is called after a PCI bus error affecting
7664 * this device has been detected.
7665 */
7666static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev,
Joe Perchese8e9f692010-09-07 21:34:53 +00007667 pci_channel_state_t state)
Auke Kok9a799d72007-09-15 14:07:45 -07007668{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007669 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7670 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007671
7672 netif_device_detach(netdev);
7673
Breno Leitao3044b8d2009-05-06 10:44:26 +00007674 if (state == pci_channel_io_perm_failure)
7675 return PCI_ERS_RESULT_DISCONNECT;
7676
Auke Kok9a799d72007-09-15 14:07:45 -07007677 if (netif_running(netdev))
7678 ixgbe_down(adapter);
7679 pci_disable_device(pdev);
7680
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007681 /* Request a slot reset. */
Auke Kok9a799d72007-09-15 14:07:45 -07007682 return PCI_ERS_RESULT_NEED_RESET;
7683}
7684
7685/**
7686 * ixgbe_io_slot_reset - called after the pci bus has been reset.
7687 * @pdev: Pointer to PCI device
7688 *
7689 * Restart the card from scratch, as if from a cold-boot.
7690 */
7691static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev)
7692{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007693 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007694 pci_ers_result_t result;
7695 int err;
Auke Kok9a799d72007-09-15 14:07:45 -07007696
gouji-new9ce77662009-05-06 10:44:45 +00007697 if (pci_enable_device_mem(pdev)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007698 e_err(probe, "Cannot re-enable PCI device after reset.\n");
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007699 result = PCI_ERS_RESULT_DISCONNECT;
7700 } else {
7701 pci_set_master(pdev);
7702 pci_restore_state(pdev);
Breno Leitaoc0e1f682009-11-10 08:37:47 +00007703 pci_save_state(pdev);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007704
Don Skidmoredd4d8ca2009-04-29 00:22:31 -07007705 pci_wake_from_d3(pdev, false);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007706
7707 ixgbe_reset(adapter);
PJ Waskiewicz88512532009-03-13 22:15:10 +00007708 IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007709 result = PCI_ERS_RESULT_RECOVERED;
Auke Kok9a799d72007-09-15 14:07:45 -07007710 }
Auke Kok9a799d72007-09-15 14:07:45 -07007711
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007712 err = pci_cleanup_aer_uncorrect_error_status(pdev);
7713 if (err) {
Emil Tantilov849c4542010-06-03 16:53:41 +00007714 e_dev_err("pci_cleanup_aer_uncorrect_error_status "
7715 "failed 0x%0x\n", err);
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007716 /* non-fatal, continue */
7717 }
Auke Kok9a799d72007-09-15 14:07:45 -07007718
Peter P Waskiewicz Jr6fabd712008-12-10 01:13:08 -08007719 return result;
Auke Kok9a799d72007-09-15 14:07:45 -07007720}
7721
7722/**
7723 * ixgbe_io_resume - called when traffic can start flowing again.
7724 * @pdev: Pointer to PCI device
7725 *
7726 * This callback is called when the error recovery driver tells us that
7727 * its OK to resume normal operation.
7728 */
7729static void ixgbe_io_resume(struct pci_dev *pdev)
7730{
Alexander Duyckc60fbb02010-11-16 19:26:54 -08007731 struct ixgbe_adapter *adapter = pci_get_drvdata(pdev);
7732 struct net_device *netdev = adapter->netdev;
Auke Kok9a799d72007-09-15 14:07:45 -07007733
7734 if (netif_running(netdev)) {
7735 if (ixgbe_up(adapter)) {
Emil Tantilov396e7992010-07-01 20:05:12 +00007736 e_info(probe, "ixgbe_up failed after reset\n");
Auke Kok9a799d72007-09-15 14:07:45 -07007737 return;
7738 }
7739 }
7740
7741 netif_device_attach(netdev);
Auke Kok9a799d72007-09-15 14:07:45 -07007742}
7743
7744static struct pci_error_handlers ixgbe_err_handler = {
7745 .error_detected = ixgbe_io_error_detected,
7746 .slot_reset = ixgbe_io_slot_reset,
7747 .resume = ixgbe_io_resume,
7748};
7749
7750static struct pci_driver ixgbe_driver = {
7751 .name = ixgbe_driver_name,
7752 .id_table = ixgbe_pci_tbl,
7753 .probe = ixgbe_probe,
7754 .remove = __devexit_p(ixgbe_remove),
7755#ifdef CONFIG_PM
7756 .suspend = ixgbe_suspend,
7757 .resume = ixgbe_resume,
7758#endif
7759 .shutdown = ixgbe_shutdown,
7760 .err_handler = &ixgbe_err_handler
7761};
7762
7763/**
7764 * ixgbe_init_module - Driver Registration Routine
7765 *
7766 * ixgbe_init_module is the first routine called when the driver is
7767 * loaded. All it does is register with the PCI subsystem.
7768 **/
7769static int __init ixgbe_init_module(void)
7770{
7771 int ret;
Joe Perchesc7689572010-09-07 21:35:17 +00007772 pr_info("%s - version %s\n", ixgbe_driver_string, ixgbe_driver_version);
Emil Tantilov849c4542010-06-03 16:53:41 +00007773 pr_info("%s\n", ixgbe_copyright);
Auke Kok9a799d72007-09-15 14:07:45 -07007774
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007775#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007776 dca_register_notify(&dca_notifier);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007777#endif
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007778
Auke Kok9a799d72007-09-15 14:07:45 -07007779 ret = pci_register_driver(&ixgbe_driver);
7780 return ret;
7781}
Peter P Waskiewiczb4617242008-09-11 20:04:46 -07007782
Auke Kok9a799d72007-09-15 14:07:45 -07007783module_init(ixgbe_init_module);
7784
7785/**
7786 * ixgbe_exit_module - Driver Exit Cleanup Routine
7787 *
7788 * ixgbe_exit_module is called just before the driver is removed
7789 * from memory.
7790 **/
7791static void __exit ixgbe_exit_module(void)
7792{
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007793#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007794 dca_unregister_notify(&dca_notifier);
7795#endif
Auke Kok9a799d72007-09-15 14:07:45 -07007796 pci_unregister_driver(&ixgbe_driver);
Eric Dumazet1a515022010-11-16 19:26:42 -08007797 rcu_barrier(); /* Wait for completion of call_rcu()'s */
Auke Kok9a799d72007-09-15 14:07:45 -07007798}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007799
Jeff Garzik5dd2d332008-10-16 05:09:31 -04007800#ifdef CONFIG_IXGBE_DCA
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007801static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007802 void *p)
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007803{
7804 int ret_val;
7805
7806 ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event,
Joe Perchese8e9f692010-09-07 21:34:53 +00007807 __ixgbe_notify_dca);
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007808
7809 return ret_val ? NOTIFY_BAD : NOTIFY_DONE;
7810}
Jeb Cramerbd0362d2008-03-03 15:04:02 -08007811
Alexander Duyckb4533682009-03-31 21:32:42 +00007812#endif /* CONFIG_IXGBE_DCA */
Emil Tantilov849c4542010-06-03 16:53:41 +00007813
Auke Kok9a799d72007-09-15 14:07:45 -07007814module_exit(ixgbe_exit_module);
7815
7816/* ixgbe_main.c */